From 3318fa47a3ba54b7b40c1b596d23aebfa2db184a Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 6 Aug 2022 16:22:32 +0200 Subject: [PATCH] New environment variable MKRESCUE_SED_UNPACK_EFI_TO_ISO --- frontend/grub-mkrescue-sed.sh | 100 +++++++++++++++++++++++++++--- frontend/grub-mkrescue-sed.sh.sig | Bin 0 -> 72 bytes 2 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 frontend/grub-mkrescue-sed.sh.sig diff --git a/frontend/grub-mkrescue-sed.sh b/frontend/grub-mkrescue-sed.sh index dcd9d696..1a485cd8 100755 --- a/frontend/grub-mkrescue-sed.sh +++ b/frontend/grub-mkrescue-sed.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (C) 2015 - 2019 +# Copyright (C) 2015 - 2022 # Thomas Schmitt , libburnia-project.org # Provided under BSD license: Use, modify, and distribute as you like. @@ -117,9 +117,9 @@ fi # command line.) # Each argument must be a single word. No whitespace. No quotation marks. -# "yes" overwrites the MBR partition table area in the EFI boot image by zeros. -# Some EFI implementations get stuck when seeing in the EFI partition a -# partition table entry which begins at LBA 0. +# "yes" in MKRESCUE_SED_IN_EFI_NO_PT overwrites the MBR partition table area +# in the EFI boot image by zeros. Some EFI implementations get stuck when +# seeing in the EFI partition a partition table entry which begins at LBA 0. # "extra" not only zeros the partition table but also the MBR signature. efi_zero_inner_pt=no if test -n "$MKRESCUE_SED_IN_EFI_NO_PT" @@ -127,6 +127,24 @@ then efi_zero_inner_pt="$MKRESCUE_SED_IN_EFI_NO_PT" fi +# "yes" in MKRESCUE_SED_UNPACK_EFI_TO_ISO causes the file tree from the FAT +# image efi.img to be unpacked by mcopy to a directory in /tmp which then +# gets mapped into the root directory of the emerging ISO 9660 filesystem. +# This enables a way of installing the result image onto a USB stick with +# FAT filesystem by simply copying its full file tree from ISO to FAT. +# Whether the payload files of the ISO will be able to work from FAT depends +# on their expectation towards file names and attributes. +# WARNING: Make sure that the files in efi.img do not collide with your +# payload files or with files added to the ISO by GRUB. Before using +# MKRESCUE_SED_UNPACK_EFI_TO_ISO, make a vanilla grub-mkrescue ISO +# with your payload, mount it and then its /efi.img file, then use +# program "find" on the mount point of efi.img to see all its files. +# Compare this with the output of "find" on the ISO mount point. +efi_unpack_to_iso=no +if test -n "$MKRESCUE_SED_UNPACK_EFI_TO_ISO" +then + efi_unpack_to_iso="$MKRESCUE_SED_UNPACK_EFI_TO_ISO" +fi # # Do the work @@ -190,10 +208,11 @@ done if test x"$debug" = xextra then # Show files on disk - find "$dir" + find "$dir" 2>&1 + echo 2>&1 fi -if test "$efi_zero_inner_pt" = yes -o "$efi_zero_inner_pt" = extra +if test x"$efi_zero_inner_pt" = xyes -o x"$efi_zero_inner_pt" = xextra then did_dd=0 if test -e "$dir"/efi.img @@ -222,6 +241,41 @@ then fi fi +efi_temp_tree= +if test x"$efi_unpack_to_iso" = xyes +then + if test -e "$dir"/efi.img + then + temp_tree=/tmp/grub-mkrescue-sed-et."$$" + # The mcopy command is the inverse of what grub-mkrescue does to pack it up + if mcopy -s -i "$dir"/efi.img ::/ "$temp_tree" + then + efi_temp_tree="$temp_tree" + if test x"$debug" = xyes -o x"$debug" = xextra + then + echo "Temporarily extracted $dir/efi.img to $temp_tree" >&2 + echo >&2 + if test x"$debug" = xextra + then + # Show extracted files + find "$temp_tree" >&2 + echo >&2 + fi + fi + elif test -e "$temp_tree" + then + rm -r "$temp_tree" + fi + if test -z "$efi_temp_tree" + then + echo >&2 + echo "$0 : NOTE : Could not extract efi.img to $temp_tree" >&2 + echo "$0 : NOTE : Thus cannot obey MKRESCUE_SED_UNPACK_EFI_TO_ISO." >&2 + echo >&2 + fi + fi +fi + efi_tmp_name= if test x"$mode" = xmjg \ -o x"$mode" = xmbr_only \ @@ -229,10 +283,15 @@ if test x"$mode" = xmjg \ -o x"$mode" = xmbr_hfs then # Move EFI partition image file out of the "$dir" tree, i.e. out of the ISO - efi_tmp_name=grub-mkrescue-sed-efi-img.$$ + efi_tmp_name=grub-mkrescue-sed-ei.$$ if test -e "$dir"/efi.img then mv "$dir"/efi.img /tmp/$efi_tmp_name + if test x"$debug" = xyes -o x"$debug" = xextra + then + echo "Temporarily moved $dir/efi.img to /tmp/$efi_tmp_name" >&2 + echo >&2 + fi elif test -e /tmp/$efi_tmp_name then rm /tmp/$efi_tmp_name @@ -322,6 +381,27 @@ else exit 1 fi +if echo "$efi_temp_tree" | grep '^/tmp/' >/dev/null +then + # Does the xorriso run end in native command mode ? + separator_seen=0 + for i in "$@" + do + if test x"$i" = x-- + then + separator_seen=1 + fi + done + if test "$separator_seen" = 1 + then + # Native mode possible: Enable it for sure and then use -map + x=" $x -- -map $efi_temp_tree /" + else + # Hopefully nobody finds a way to leave mkisofs emulation without "--" arg + x=" $x -graft-points /=$efi_temp_tree" + fi +fi + if test x"$debug" = xyes -o x"$debug" = xextra then echo "+ converted xorriso arguments:" >&2 @@ -349,5 +429,11 @@ then mv /tmp/$efi_tmp_name "$dir"/efi.img fi +# Remove possible extracted EFI partition tree +if echo "$efi_temp_tree" | grep '^/tmp/' >/dev/null +then + rm -r "$efi_temp_tree" +fi + exit $ret diff --git a/frontend/grub-mkrescue-sed.sh.sig b/frontend/grub-mkrescue-sed.sh.sig new file mode 100644 index 0000000000000000000000000000000000000000..5efa530e4e591694d8671d605cd373596c50dbcb GIT binary patch literal 72 zcmV-O0Jr~$Mg#y60ssaD0%GoW-~b8<5b4X`z^lNhR1Dw%pM5sJkWbJHBW|?~qyRD# e%Y^-+^8lceEp&{BEbZq-vQZUt%o+CPqvR3oxgT2q literal 0 HcmV?d00001