Ensure GRUB finds the running ISO
authorMichael Prokop <mika@grml.org>
Thu, 22 Nov 2018 22:54:10 +0000 (23:54 +0100)
committerMichael Prokop <mika@grml.org>
Thu, 22 Nov 2018 23:05:20 +0000 (00:05 +0100)
Instead of relying on the presence of the /conf/bootid.txt file, which
might be present on several Grml ISOs, let's generate a unique filename
which GRUB then can search for.

JFTR: The redirection within the layers (scripts/GRMLBASE/45-grub-images
vs main grml-live script) is necessary, because the GRUB image is
generated from within the rootfs (grml_chroot), but the rootfs is
compressed within a squashfs file, while we can only access files
available directly inside the ISO (corresponding to the files inside
grml_cd, and not the files inside grml_chroot which
scripts/GRMLBASE/45-grub-images has access to).

etc/grml/fai/config/scripts/GRMLBASE/45-grub-images
grml-live

index 84bc178..16c0e9a 100755 (executable)
@@ -11,12 +11,17 @@ set -u
 
 TMP_CONFIG="/tmp/grub_config_efi"
 
+# this allows us to find this specific Grml ISO,
+# even if there are multiple Grml ISOs present
+bootfile="${GRML_NAME}_$(TZ=UTC date +%s)"
+echo "$bootfile" > "${target}/"boot/grub/bootfile.txt
+
 cat > "${target}/${TMP_CONFIG}" <<EOF
-search.file /conf/bootid.txt root
+search.file /conf/bootfile_$bootfile root
 set prefix=(\$root)/boot/grub
 insmod normal
 normal
-echo "E: Could not find root device!"
+echo "E: Could not find root device (for /conf/bootfile_$bootfile)!"
 EOF
 
 ARCHS=(i386-pc)
index f561355..6043764 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -1011,6 +1011,26 @@ if [ "$ARCH" = i386 ] || [ "$ARCH" = amd64 ] ; then
       eend $?
     fi
 
+    # every recent Grml ISO ships a /conf/bootid.txt, though GRUB might find
+    # the /conf/bootid.txt of a different (Grml) ISO than the one that's
+    # supposed to be running, so within scripts/GRMLBASE/45-grub-images
+    # we generate a random filename, stored inside /boot/grub/bootfile.txt,
+    # which we place on the resulting ISO here
+    if [ -r "${CHROOT_OUTPUT}"/boot/grub/bootfile.txt ] ; then
+      mkdir -p "${BUILD_OUTPUT}"/conf
+      rm -f "${BUILD_OUTPUT}"/conf/bootfile*  # ensure we don't leave any old(er) files behind
+
+      einfo "Generating "${BUILD_OUTPUT}"/conf/bootfile* files"
+      log   "Generating "${BUILD_OUTPUT}"/conf/bootfile* files"
+
+      # save information about the random filename inside /conf/bootfile.txt
+      echo "/conf/bootfile_$(cat "${CHROOT_OUTPUT}"/boot/grub/bootfile.txt)" > \
+        "${BUILD_OUTPUT}"/conf/bootfile.txt
+      echo "# This file is relevant for GRUB boot with the Grml ISO." > \
+        "${BUILD_OUTPUT}"/conf/bootfile_"$(cat "${CHROOT_OUTPUT}"/boot/grub/bootfile.txt)"
+      eend $?
+    fi
+
     grub_setup
 
     # EFI boot files