Handle filesystems loop-mounted on file images
authorColin Watson <cjwatson@debian.org>
Mon, 13 Jan 2014 12:13:00 +0000 (12:13 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Mon, 15 Jul 2024 15:05:20 +0000 (17:05 +0200)
Improve prepare_grub_to_access_device to emit appropriate commands for
such filesystems, and ignore them in Linux grub.d scripts.

This is needed for Ubuntu's Wubi installation method.

This patch isn't inherently Debian/Ubuntu-specific.  losetup and
/proc/mounts are Linux-specific, though, so we might need to refine this
before sending it upstream.  The changes to the Linux grub.d scripts
might be better handled by integrating 10_lupin properly instead.

Patch-Name: mkconfig-loopback.patch

Gbp-Pq: Name mkconfig-loopback.patch

util/grub-mkconfig_lib.in
util/grub.d/10_linux.in
util/grub.d/20_linux_xen.in

index 33e1750aebb1298841f011d7926936822f0d89fb..cc3c4f0dbc135e57f14a2bf7efa55294fe4244ce 100644 (file)
@@ -133,6 +133,22 @@ prepare_grub_to_access_device ()
     esac
   done
 
+  loop_file=
+  case $1 in
+    /dev/loop/*|/dev/loop[0-9])
+      grub_loop_device="${1#/dev/}"
+      loop_file=`losetup "$1" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
+      case $loop_file in
+        /dev/*) ;;
+        *)
+          loop_device="$1"
+          shift
+          set -- `"${grub_probe}" --target=device "${loop_file}"` "$@"
+        ;;
+      esac
+    ;;
+  esac
+
   # Abstraction modules aren't auto-loaded.
   abstraction="`"${grub_probe}" --device $@ --target=abstraction`"
   for module in ${abstraction} ; do
@@ -169,6 +185,14 @@ prepare_grub_to_access_device ()
     fi
   fi
   IFS="$old_ifs"
+
+  if [ "x${loop_file}" != x ]; then
+    loop_mountpoint="$(awk '"'${loop_file}'" ~ "^"$2 && $2 != "/" { print $2 }' /proc/mounts | tail -n1)"
+    if [ "x${loop_mountpoint}" != x ]; then
+      echo "loopback ${grub_loop_device} ${loop_file#$loop_mountpoint}"
+      echo "set root=(${grub_loop_device})"
+    fi
+  fi
 }
 
 grub_get_device_id ()
index e661e9d13f8101e8d8badba5182c0b8efe4de5d1..cc6ae58e57fa4d01b993a076a57ff6d76a7d2889 100644 (file)
@@ -40,6 +40,11 @@ fi
 case ${GRUB_DEVICE} in
   /dev/loop/*|/dev/loop[0-9])
     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
+    # We can't cope with devices loop-mounted from files here.
+    case ${GRUB_DEVICE} in
+      /dev/*) ;;
+      *) exit 0 ;;
+    esac
   ;;
 esac
 
index 94dd8be1342aaa68fd35eeede20c79b7c5e9548c..f496bebfa6cec6512c937b218bea2defa7e0e13a 100644 (file)
@@ -40,6 +40,11 @@ fi
 case ${GRUB_DEVICE} in
   /dev/loop/*|/dev/loop[0-9])
     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
+    # We can't cope with devices loop-mounted from files here.
+    case ${GRUB_DEVICE} in
+      /dev/*) ;;
+      *) exit 0 ;;
+    esac
   ;;
 esac