From 7ef3249e1cc6cb5a711de55a32d8ac5ffed686b4 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 29 Nov 2024 14:22:32 +0100 Subject: [PATCH 1/8] interactive mode: ignore failures when identifying file system fails When booting Grml from a YUMI device (see https://yumiusb.com/) which was built with Ventoy, then executing `blkid -s TYPE -o value /dev/dm-0p1` might fail, if ventoy is behind the /dev/dm-0p1: | root@grml:~# dmsetup ls | ventoy (253:0) Fixes: ++ for i in $AVAILABLE_PARTITIONS +++ blkid -s TYPE -o value /dev/dm-0p1 ++++ error_handler ++++ last_exit_code=2 ++++ last_bash_command='blkid -s TYPE -o value "$i" 2> /dev/null' ++++ echo 'Unexpected non-zero exit code 2 in /usr/sbin/grml-debootstrap /usr/sbin/grml-debootstrap /usr/sbin/grml-debootstrap /usr/sbin/grml-debootstrap at line 744 1151 1166 0 detected! last bash command: blkid -s TYPE -o value "$i" 2> /dev/null' ++++ '[' -r /mnt/debootstrap.5465/debootstrap/debootstrap.log ']' Thanks to klatls for the bug report --- grml-debootstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grml-debootstrap b/grml-debootstrap index 8137067c..08797791 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -728,7 +728,7 @@ prompt_for_target() fi PARTITION_LIST=$(for i in $AVAILABLE_PARTITIONS ; do - fs="$(blkid -s TYPE -o value "$i" 2>/dev/null)" + fs="$(blkid -s TYPE -o value "$i" 2>/dev/null || true)" [ -n "$fs" ] || fs='[no_filesystem_yet]' echo "$i" "$fs" unset fs From 12cce02e746d2567bab0d3dbc032358c04d65a19 Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Sat, 7 Dec 2024 16:09:23 +0100 Subject: [PATCH 2/8] Update changelog for 0.111 release --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 713d229a..19ad2d8e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +grml-debootstrap (0.111) unstable; urgency=medium + + [ Michael Prokop ] + * [7ef3249] interactive mode: ignore failures when identifying file system fails + + -- Chris Hofstaedtler Sat, 07 Dec 2024 16:09:19 +0100 + grml-debootstrap (0.110) unstable; urgency=medium [ Chris Hofstaedtler ] From afa6392ee8c327157eafdfe43864a4f6fde89693 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Fri, 10 Jan 2025 00:00:52 -0600 Subject: [PATCH 3/8] Make bootloader updates on UEFI-based systems work --- grml-debootstrap | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index 08797791..a5a3b6bf 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -300,7 +300,7 @@ cleanup() { # ugly, but make sure we really don't leave anything (/proc /proc and # /dev /dev are intended, trying to work around timing issues, see #657023) for ARG in /run/udev /sys /proc /proc /dev/pts /dev/pts /dev /dev ; do - [ -x "$MNTPOINT"/bin/umount ] && { clean_chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true; } + [ -x "$MNTPOINT"/bin/umount ] && { clean_chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true; } umount "$MNTPOINT"/$ARG >/dev/null 2>&1 || true done @@ -1597,16 +1597,32 @@ grub_install() { if [ -n "$ARM_EFI_TARGET" ]; then einfo "Installing Grub as bootloader into EFI." - clean_chroot "${MNTPOINT}" grub-install --target=arm64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-nvram --removable + clean_chroot "${MNTPOINT}" grub-install --target=arm64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-nvram --force-extra-removable # Has chroot-script installed GRUB to MBR using grub-install (successfully), already? # chroot-script skips installation for unset ${GRUB} elif [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | grep -Fq GRUB; then einfo "Installing Grub as bootloader." - if ! clean_chroot "${MNTPOINT}" dpkg --list grub-pc 2>/dev/null | grep -q '^ii' ; then - echo "Notice: grub-pc package not present yet, installing it therefore." - # shellcheck disable=SC2086 - clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-pc + if [ -z "$VMEFI" ]; then + if ! clean_chroot "${MNTPOINT}" dpkg --list grub-pc 2>/dev/null | grep -q '^ii' ; then + echo "Notice: grub-pc package not present yet, installing it therefore." + # shellcheck disable=SC2086 + clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-pc + fi + else + # We install grub-pc-bin instead of grub-pc when EFI is enabled, because + # otherwise the EFI bootloader won't be automatically updated when GRUB + # packages are uploaded. Doing this means that the BIOS bootloader won't + # be automatically updated, which stinks, however the BIOS bootloader + # doesn't have the same security concerns as the EFI bootloader (there's + # no Secure Boot to grapple with when using legacy BIOS boot) so it's + # better to let the BIOS bootloader lag behind and update the EFI one + # than to let the EFI bootloader lag behind and update the BIOS one. + if ! clean_chroot "${MNTPOINT}" dpkg --list grub-pc-bin 2>/dev/null | grep -q '^ii' ; then + echo "Notice: grub-pc-bin package not present yet, installing it therefore." + # shellcheck disable=SC2086 + clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-pc-bin + fi fi mkdir -p "${MNTPOINT}/boot/grub" @@ -1617,7 +1633,6 @@ grub_install() { cp -a "${MNTPOINT}"/usr/lib/grub/i386-pc "${MNTPOINT}/boot/grub/" if [ -n "$VMEFI" ]; then - mkdir -p "${MNTPOINT}"/boot/efi mount -t vfat "${EFI_TARGET}" "${MNTPOINT}"/boot/efi @@ -1631,24 +1646,24 @@ grub_install() { if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-arm64-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-arm64-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 - clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-arm64-bin grub-efi-arm64-signed + clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-arm64-bin grub-efi-arm64-signed grub-efi-arm64 fi - clean_chroot "$MNTPOINT" grub-install --target=arm64-efi --efi-directory=/boot/efi --uefi-secure-boot --removable "/dev/$LOOP_DISK" + clean_chroot "$MNTPOINT" grub-install --target=arm64-efi --efi-directory=/boot/efi --uefi-secure-boot --bootloader-id=debian --force-extra-removable "/dev/$LOOP_DISK" elif [ "$(dpkg --print-architecture)" = "i386" ]; then if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-ia32-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-ia32-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 - clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-ia32-bin grub-efi-ia32-signed + clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-ia32-bin grub-efi-ia32-signed grub-efi-ia32 fi - clean_chroot "$MNTPOINT" grub-install --target=i386-efi --efi-directory=/boot/efi --uefi-secure-boot --removable "/dev/$LOOP_DISK" + clean_chroot "$MNTPOINT" grub-install --target=i386-efi --efi-directory=/boot/efi --uefi-secure-boot --bootloader-id=debian --force-extra-removable "/dev/$LOOP_DISK" clean_chroot "$MNTPOINT" grub-install --target=i386-pc "/dev/$LOOP_DISK" else if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-amd64-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-amd64-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 - clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-amd64-bin grub-efi-amd64-signed + clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-amd64-bin grub-efi-amd64-signed grub-efi-amd64 fi - clean_chroot "$MNTPOINT" grub-install --target=x86_64-efi --efi-directory=/boot/efi --uefi-secure-boot --removable "/dev/$LOOP_DISK" + clean_chroot "$MNTPOINT" grub-install --target=x86_64-efi --efi-directory=/boot/efi --uefi-secure-boot --bootloader-id=debian --force-extra-removable "/dev/$LOOP_DISK" clean_chroot "$MNTPOINT" grub-install --target=i386-pc "/dev/$LOOP_DISK" fi else @@ -1671,6 +1686,9 @@ grub_install() { fi fi + # Make sure bootloader updates affect the removable media partition too + clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-amd64 grub2/force_efi_extra_removable boolean true' + # workaround for Debian bug #918590 with lvm + udev: # WARNING: Device /dev/... not initialized in udev database even after waiting 10000000 microseconds if [ -d /run/udev ] ; then From 16132260fb3750442b968c29c7ad6ccc0924ec20 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Sat, 11 Jan 2025 23:45:55 -0600 Subject: [PATCH 4/8] Allow customizing EFI bootloader ID, streamline GRUB EFI installation --- grml-debootstrap | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index a5a3b6bf..debe727e 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -122,6 +122,8 @@ Options for Virtual Machine deployment: --vmsize Use specified size for size of VM file (default: 2G). Syntax as supported by qemu-img, like: --vmsize 3G --vmefi Create an EFI boot partition for the VM. + --efi-id Sets the efi bootloader ID for the VM. Only relevant when + used with --vmefi. Configuration options: @@ -376,7 +378,7 @@ fi # }}} # cmdline handling {{{ -CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,defaultinterfaces,interactive,nodebootstrap,nointerfaces,nokernel,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,post-scripts:,pre-scripts:,debconf:,vm,vmfile,vmsize:,vmefi,keep_src_list,hostname:,password:,nopassword,grmlrepos,backportrepos,bootappend:,grub:,efi:,arch:,insecure,verbose,help,version,force,debug,contrib,non-free,remove-configs,sshcopyid,sshcopyauth +CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,defaultinterfaces,interactive,nodebootstrap,nointerfaces,nokernel,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,post-scripts:,pre-scripts:,debconf:,vm,vmfile,vmsize:,vmefi,efi-id:,keep_src_list,hostname:,password:,nopassword,grmlrepos,backportrepos,bootappend:,grub:,efi:,arch:,insecure,verbose,help,version,force,debug,contrib,non-free,remove-configs,sshcopyid,sshcopyauth if ! _opt_temp=$(getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \ $CMDLINE_OPTS -- "$@"); then @@ -413,6 +415,9 @@ while :; do --vmefi) # Create an EFI boot partition for the VM _opt_vmefi="T" ;; + --efi-id) + shift; _opt_efi_id="$1" + ;; --mntpoint|-p) # Mountpoint used for mounting the target system shift; _opt_mntpoint="$1" ;; @@ -579,6 +584,7 @@ done [ "$_opt_vmfile" ] && VMFILE=1 && VIRTUAL=1 [ "$_opt_vmsize" ] && VMSIZE=$_opt_vmsize [ "$_opt_vmefi" ] && VMEFI=1 +[ "$_opt_efi_id" ] && EFI_ID=$_opt_efi_id [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt [ "$_opt_interactive" ] && INTERACTIVE=1 @@ -1636,34 +1642,54 @@ grub_install() { mkdir -p "${MNTPOINT}"/boot/efi mount -t vfat "${EFI_TARGET}" "${MNTPOINT}"/boot/efi + if [ -z "${EFI_ID}" ]; then + EFI_ID="$( + source "${MNTPOINT}"/etc/default/grub + for file in "${MNTPOINT}"/etc/default/grub.d/*.cfg; do + if [ -f "${file}" ]; then + source "${file}" + fi + done + echo "${GRUB_DISTRIBUTOR}" + )" + else + # This is prefixed with a `z` so that it takes precedence over any other GRUB config. + echo "GRUB_DISTRIBUTOR='${EFI_ID}'" > "${MNTPOINT}"/etc/default/grub.d/z-grml-debootstrap-efi-id.cfg + fi + + mkdir -p "${MNTPOINT}"/boot/efi/EFI/BOOT + mkdir -p "${MNTPOINT}"/boot/efi/EFI/"${EFI_ID}" + if ! clean_chroot "${MNTPOINT}" dpkg --list shim-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: shim-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS shim-signed fi + # The EFI bootloader will automatically be installed to the proper location when the + # corresponding grub-efi-ARCH package is installed. if [ "$(dpkg --print-architecture)" = "arm64" ]; then + clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-arm64-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-arm64-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-arm64-bin grub-efi-arm64-signed grub-efi-arm64 fi - clean_chroot "$MNTPOINT" grub-install --target=arm64-efi --efi-directory=/boot/efi --uefi-secure-boot --bootloader-id=debian --force-extra-removable "/dev/$LOOP_DISK" elif [ "$(dpkg --print-architecture)" = "i386" ]; then + clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-ia32 grub2/force_efi_extra_removable boolean true' if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-ia32-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-ia32-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-ia32-bin grub-efi-ia32-signed grub-efi-ia32 fi - clean_chroot "$MNTPOINT" grub-install --target=i386-efi --efi-directory=/boot/efi --uefi-secure-boot --bootloader-id=debian --force-extra-removable "/dev/$LOOP_DISK" clean_chroot "$MNTPOINT" grub-install --target=i386-pc "/dev/$LOOP_DISK" else + clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-amd64 grub2/force_efi_extra_removable boolean true' if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-amd64-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-amd64-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-amd64-bin grub-efi-amd64-signed grub-efi-amd64 fi - clean_chroot "$MNTPOINT" grub-install --target=x86_64-efi --efi-directory=/boot/efi --uefi-secure-boot --bootloader-id=debian --force-extra-removable "/dev/$LOOP_DISK" clean_chroot "$MNTPOINT" grub-install --target=i386-pc "/dev/$LOOP_DISK" fi else @@ -1686,9 +1712,6 @@ grub_install() { fi fi - # Make sure bootloader updates affect the removable media partition too - clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-amd64 grub2/force_efi_extra_removable boolean true' - # workaround for Debian bug #918590 with lvm + udev: # WARNING: Device /dev/... not initialized in udev database even after waiting 10000000 microseconds if [ -d /run/udev ] ; then From 9f8b42353ad6a6a51c76c8409f8ba85c152ac591 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Sun, 12 Jan 2025 13:39:21 -0600 Subject: [PATCH 5/8] Get rid of ARM_EFI_TARGET codepaths, merge with VMEFI --- grml-debootstrap | 99 +++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 60 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index debe727e..c99811fd 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -1329,13 +1329,6 @@ mkfs() { fi if [ -n "$MKFS" ] ; then - - if [ -n "${ARM_EFI_TARGET}" ] ; then - einfo "Running mkfs.fat $MKFS_OPTS on $ARM_EFI_TARGET" - mkfs.fat -n "EFI" "$ARM_EFI_TARGET" - MKFS_OPTS="$MKFS_OPTS -L LINUX" - fi - einfo "Running $MKFS $MKFS_OPTS on $TARGET" # shellcheck disable=SC2086 "$MKFS" $MKFS_OPTS "$TARGET" @@ -1507,6 +1500,16 @@ prepare_vm() { ORIG_TARGET="$TARGET" # store for later reuse + case "$ARCH" in + i386|amd64) true;; + arm64) VMEFI=1;; + esac + + if [ "$ARCH" = 'arm64' ]; then + # arm64 support largely only exists for GPT + VMEFI=1 + fi + if [ -n "$VMFILE" ]; then qemu-img create -f raw "${TARGET}" "${VMSIZE}" fi @@ -1514,53 +1517,43 @@ prepare_vm() { parted -s "${TARGET}" 'mklabel gpt' parted -s "${TARGET}" 'mkpart ESP fat32 1MiB 101MiB' parted -s "${TARGET}" 'set 1 boot on' - parted -s "${TARGET}" 'mkpart bios_grub 101MiB 102MiB' - parted -s "${TARGET}" 'set 2 bios_grub on' - parted -s "${TARGET}" 'mkpart primary ext4 102MiB 100%' - - else - # arm64 support largely only exists for GPT if [ "$ARCH" = 'arm64' ]; then - einfo "Setting up GPT partitions for arm64" - parted -s "${TARGET}" 'mklabel gpt' - parted -s "${TARGET}" 'mkpart ESP fat32 1MiB 10MiB' - parted -s "${TARGET}" 'set 1 boot on' - parted -s "${TARGET}" 'mkpart LINUX ext4 10MiB 100%' + # No need for a bios_grub parttion on ARM64 + parted -s "${TARGET}" 'mkpart primary ext4 101MiB 100%' else - parted -s "${TARGET}" 'mklabel msdos' - if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then - einfo "Adjusting disk signature to a fixed (non-random) value" - MBRTMPFILE=$(mktemp) - dd if="${TARGET}" of="${MBRTMPFILE}" bs=512 count=1 - echo -en "\\x41\\x41\\x41\\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1 - dd if="${MBRTMPFILE}" of="${TARGET}" conv=notrunc - fi - parted -s "${TARGET}" 'mkpart primary ext4 4MiB 100%' - parted -s "${TARGET}" 'set 1 boot on' + parted -s "${TARGET}" 'mkpart bios_grub 101MiB 102MiB' + parted -s "${TARGET}" 'set 2 bios_grub on' + parted -s "${TARGET}" 'mkpart primary ext4 102MiB 100%' + fi + else + parted -s "${TARGET}" 'mklabel msdos' + if [ "$FIXED_DISK_IDENTIFIERS" = "yes" ] ; then + einfo "Adjusting disk signature to a fixed (non-random) value" + MBRTMPFILE=$(mktemp) + dd if="${TARGET}" of="${MBRTMPFILE}" bs=512 count=1 + echo -en "\\x41\\x41\\x41\\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1 + dd if="${MBRTMPFILE}" of="${TARGET}" conv=notrunc fi + parted -s "${TARGET}" 'mkpart primary ext4 4MiB 100%' + parted -s "${TARGET}" 'set 1 boot on' fi - DEVINFO=$(kpartx -asv "$TARGET") # e.g. 'add map loop0p1 (254:5): 0 20477 linear 7:0 3' - will be multi-line for arm64 + DEVINFO=$(kpartx -asv "$TARGET") # e.g. 'add map loop0p1 (254:5): 0 20477 linear 7:0 3' - will be multi-line for EFI VMs if [ -z "${DEVINFO}" ] ; then eerror "Error setting up loopback device." bailout 1 fi - # if we're building for arm64, we operate on the first line of $DEVINFO which is the EFI partition - if [ "$ARCH" = 'arm64' ]; then - LOOP_PART="${DEVINFO##add map }" # 'loop0p1 (254:5): 0 20477 linear 7:0 3' - LOOP_PART="${LOOP_PART// */}" # 'loop0p1' - LOOP_DISK="${LOOP_PART%p*}" # 'loop0' - export ARM_EFI_TARGET="/dev/mapper/$LOOP_PART" - DEVINFO=${DEVINFO##*$'\n'} # now set $DEVINFO to the last line which is the OS partition - fi - # hopefully this always works as expected LOOP_PART="${DEVINFO##add map }" # 'loop0p1 (254:5): 0 20477 linear 7:0 3' LOOP_PART="${LOOP_PART// */}" # 'loop0p1' if [ -n "$VMEFI" ]; then export EFI_TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop0p1' - LOOP_PART="${LOOP_PART%p1}p3" + if [ "$ARCH" = 'arm64' ]; then + LOOP_PART="${LOOP_PART%p1}p2" + else + LOOP_PART="${LOOP_PART%p1}p3" + fi fi LOOP_DISK="${LOOP_PART%p*}" # 'loop0' export TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop0p1' @@ -1587,26 +1580,14 @@ grub_install() { bailout 1 fi - if [ -n "${ARM_EFI_TARGET}" ]; then - mkdir -p "${MNTPOINT}"/boot/efi - if ! mount "${ARM_EFI_TARGET}" "${MNTPOINT}"/boot/efi ; then - eerror "Error: Mounting ${ARM_EFI_TARGET} failed, can not continue." - bailout 1 - fi - fi - mount -t proc none "${MNTPOINT}"/proc mount -t sysfs none "${MNTPOINT}"/sys mount -t devtmpfs udev "${MNTPOINT}"/dev mount -t devpts devpts "${MNTPOINT}"/dev/pts - if [ -n "$ARM_EFI_TARGET" ]; then - einfo "Installing Grub as bootloader into EFI." - - clean_chroot "${MNTPOINT}" grub-install --target=arm64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-nvram --force-extra-removable # Has chroot-script installed GRUB to MBR using grub-install (successfully), already? # chroot-script skips installation for unset ${GRUB} - elif [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | grep -Fq GRUB; then + if [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | grep -Fq GRUB; then einfo "Installing Grub as bootloader." if [ -z "$VMEFI" ]; then @@ -1615,7 +1596,7 @@ grub_install() { # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-pc fi - else + elif [ "$ARCH" != 'arm64' ]; then # We install grub-pc-bin instead of grub-pc when EFI is enabled, because # otherwise the EFI bootloader won't be automatically updated when GRUB # packages are uploaded. Doing this means that the BIOS bootloader won't @@ -1632,11 +1613,12 @@ grub_install() { fi mkdir -p "${MNTPOINT}/boot/grub" - if ! [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ] ; then - eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." - bailout 1 + if [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ]; then + cp -a "${MNTPOINT}"/usr/lib/grub/i386-pc "${MNTPOINT}/boot/grub/" + elif [ "$ARCH" != 'arm64' ]; then + eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." + bailout 1 fi - cp -a "${MNTPOINT}"/usr/lib/grub/i386-pc "${MNTPOINT}/boot/grub/" if [ -n "$VMEFI" ]; then mkdir -p "${MNTPOINT}"/boot/efi @@ -1740,9 +1722,6 @@ grub_install() { if grep -q '^GRUB_DISABLE_LINUX_UUID=.*true' "${MNTPOINT}"/etc/default/grub 2>/dev/null ; then ewarn "GRUB_DISABLE_LINUX_UUID is set to true in /etc/default/grub, not adjusting root= in grub.cfg." ewarn "Please note that your system might NOT be able to properly boot." - elif [ -z "$ARM_EFI_TARGET" ]; then - einfo "Adjusting grub.cfg for successful boot sequence." - sed -i "s;root=[^ ]\\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg fi # workaround for Debian bug #918590 with lvm + udev: From 18009502873a77bdf9577dc93311de746105cb42 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Sun, 12 Jan 2025 15:21:02 -0600 Subject: [PATCH 6/8] Use chroot's architecture when determining which EFI bootloader to install --- grml-debootstrap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index c99811fd..f115b449 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -1645,19 +1645,19 @@ grub_install() { if ! clean_chroot "${MNTPOINT}" dpkg --list shim-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: shim-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 - clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS shim-signed + clean_chroot "${MNTPOINT}" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS shim-signed fi # The EFI bootloader will automatically be installed to the proper location when the # corresponding grub-efi-ARCH package is installed. - if [ "$(dpkg --print-architecture)" = "arm64" ]; then + if [ "${ARCH}" = "arm64" ]; then clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-arm64-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-arm64-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-arm64-bin grub-efi-arm64-signed grub-efi-arm64 fi - elif [ "$(dpkg --print-architecture)" = "i386" ]; then + elif [ "${ARCH}" = "i386" ]; then clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-ia32 grub2/force_efi_extra_removable boolean true' if ! clean_chroot "${MNTPOINT}" dpkg --list grub-efi-ia32-signed 2>/dev/null | grep -q '^ii' ; then echo "Notice: grub-efi-ia32-signed package not present yet, installing it therefore." From c30381d07ff713058f2ccb8aedf49a4577bf6395 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Sun, 12 Jan 2025 17:24:55 -0600 Subject: [PATCH 7/8] Explicitly reconfigure the EFI bootloader metapackage to ensure the bootloader actually gets installed --- grml-debootstrap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grml-debootstrap b/grml-debootstrap index f115b449..0edb25a5 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -1656,6 +1656,7 @@ grub_install() { echo "Notice: grub-efi-arm64-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-arm64-bin grub-efi-arm64-signed grub-efi-arm64 + clean_chroot "$MNTPOINT" dpkg-reconfigure --priority=critical grub-efi-arm64 fi elif [ "${ARCH}" = "i386" ]; then clean_chroot "$MNTPOINT" debconf-set-selections <<< 'grub-efi-ia32 grub2/force_efi_extra_removable boolean true' @@ -1663,6 +1664,7 @@ grub_install() { echo "Notice: grub-efi-ia32-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-ia32-bin grub-efi-ia32-signed grub-efi-ia32 + clean_chroot "$MNTPOINT" dpkg-reconfigure --priority=critical grub-efi-ia32 fi clean_chroot "$MNTPOINT" grub-install --target=i386-pc "/dev/$LOOP_DISK" else @@ -1671,6 +1673,7 @@ grub_install() { echo "Notice: grub-efi-amd64-signed package not present yet, installing it therefore." # shellcheck disable=SC2086 clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-efi-amd64-bin grub-efi-amd64-signed grub-efi-amd64 + clean_chroot "$MNTPOINT" dpkg-reconfigure --priority=critical grub-efi-amd64 fi clean_chroot "$MNTPOINT" grub-install --target=i386-pc "/dev/$LOOP_DISK" fi From e2c47d81ac41fa5e0b843a25d4e7695f09823267 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Sun, 12 Jan 2025 17:22:13 -0600 Subject: [PATCH 8/8] Simplify grub-pc bootloader installation code --- grml-debootstrap | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index 0edb25a5..6b064ed0 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -1590,12 +1590,10 @@ grub_install() { if [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | grep -Fq GRUB; then einfo "Installing Grub as bootloader." + local grub_pc_package_name='' + if [ -z "$VMEFI" ]; then - if ! clean_chroot "${MNTPOINT}" dpkg --list grub-pc 2>/dev/null | grep -q '^ii' ; then - echo "Notice: grub-pc package not present yet, installing it therefore." - # shellcheck disable=SC2086 - clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-pc - fi + grub_pc_package_name='grub-pc' elif [ "$ARCH" != 'arm64' ]; then # We install grub-pc-bin instead of grub-pc when EFI is enabled, because # otherwise the EFI bootloader won't be automatically updated when GRUB @@ -1605,10 +1603,13 @@ grub_install() { # no Secure Boot to grapple with when using legacy BIOS boot) so it's # better to let the BIOS bootloader lag behind and update the EFI one # than to let the EFI bootloader lag behind and update the BIOS one. - if ! clean_chroot "${MNTPOINT}" dpkg --list grub-pc-bin 2>/dev/null | grep -q '^ii' ; then - echo "Notice: grub-pc-bin package not present yet, installing it therefore." - # shellcheck disable=SC2086 - clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS grub-pc-bin + grub_pc_package_name='grub-pc-bin' + fi + + if [ -n "${grub_pc_package_name}" ]; then + if ! clean_chroot "${MNTPOINT}" dpkg --list "${grub_pc_package_name}" 2>/dev/null | grep -q '^ii' ; then + echo "Notice: ${grub_pc_package_name} package not present yet, installing it therefore." + clean_chroot "$MNTPOINT" DEBIAN_FRONTEND=$DEBIAN_FRONTEND apt-get -y --no-install-recommends install $DPKG_OPTIONS "${grub_pc_package_name}" fi fi