New environment variable MKRESCUE_SED_UNPACK_EFI_TO_ISO

This commit is contained in:
Thomas Schmitt 2022-08-06 16:22:32 +02:00
parent 9e79f64cae
commit 3318fa47a3
2 changed files with 93 additions and 7 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
# Copyright (C) 2015 - 2019
# Copyright (C) 2015 - 2022
# Thomas Schmitt <scdbackup@gmx.net>, 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

Binary file not shown.