On 21-01-13 15:35:15, Michał Górny wrote:
> Support dracut's uefi=yes configuration option that creates a combined
> UEFI stub, kernel and initramfs in a single UEFI executable.  If such
> an output is detected, install it in place of the actual kernel image
> and stub out the duplicate initrd to save space.
> 
> Signed-off-by: Michał Górny <[email protected]>
> ---
>  eclass/dist-kernel-utils.eclass | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
> index d65dc0924b40..50ad15f8b1fd 100644
> --- a/eclass/dist-kernel-utils.eclass
> +++ b/eclass/dist-kernel-utils.eclass
> @@ -41,8 +41,20 @@ dist-kernel_build_initramfs() {
>       local output=${1}
>       local version=${2}
>  
> +     local rel_image_path=$(dist-kernel_get_image_path)
> +     local image=${output%/*}/${rel_image_path##*/}
> +
> +     local args=(
> +             --force
> +             # if uefi=yes is used, dracut needs to locate the kernel image
> +             --kernel-image "${image}"
> +
> +             # positional arguments
> +             "${output}" "${version}"
> +     )
> +
>       ebegin "Building initramfs via dracut"
> -     dracut --force "${output}" "${version}"
> +     dracut "${args[@]}"
>       eend ${?} || die -n "Building initramfs failed"
>  }
>  
> @@ -85,6 +97,23 @@ dist-kernel_install_kernel() {
>       local image=${2}
>       local map=${3}
>  
> +     # if dracut is used in eufi=yes mode, initrd will actually
> +     # be a combined kernel+initramfs UEFI executable.  we can easily
> +     # recognize it by PE magic (vs cpio for a regular initramfs)
> +     local initrd=${image%/*}/initrd
> +     local magic
> +     [[ -s ${initrd} ]] && read -n 2 magic < "${initrd}"
> +     if [[ ${magic} == MZ ]]; then

This magic header is matched by both the kernel and the new uefi
executible.  I think a better check would be...

if file "${image_path}" | grep -q 'EFI application'; then

> +             einfo "Combined UEFI kernel+initramfs executable found"
> +             # install the combined executable in place of kernel
> +             image=${initrd}.uefi
> +             mv "${initrd}" "${image}" || die
> +             # put an empty file in place of initrd.  installing a duplicate
> +             # file would waste disk space, and removing it entirely provokes
> +             # kernel-install to regenerate it via dracut.
> +             > "${initrd}"
> +     fi
> +
>       ebegin "Installing the kernel via installkernel"
>       # note: .config is taken relatively to System.map;
>       # initrd relatively to bzImage
> -- 
> 2.30.0

I want to make sure you are not overwriting the original kernel image,
if you do then subsiquent --config runs will include the kernel image,
making the final image grow.

In order to avoid that I did some file juggling, but it looks like it's
cleaner here.

https://gist.github.com/prometheanfire/aeffa1c3f92d3d2af312b3b6915051fb
'worked' but was kinda unclean.


-- 
Matthew Thode (prometheanfire)

Attachment: signature.asc
Description: PGP signature

Reply via email to