1 From 67aeec648cc3b3439d65f331adc5f757de3b1c78 Mon Sep 17 00:00:00 2001
2 From: Colin Watson <cjwatson@debian.org>
3 Date: Mon, 13 Jan 2014 12:13:00 +0000
4 Subject: Handle filesystems loop-mounted on file images
6 Improve prepare_grub_to_access_device to emit appropriate commands for
7 such filesystems, and ignore them in Linux grub.d scripts.
9 This is needed for Ubuntu's Wubi installation method.
11 This patch isn't inherently Debian/Ubuntu-specific. losetup and
12 /proc/mounts are Linux-specific, though, so we might need to refine this
13 before sending it upstream. The changes to the Linux grub.d scripts
14 might be better handled by integrating 10_lupin properly instead.
16 Patch-Name: mkconfig_loopback.patch
18 util/grub-mkconfig_lib.in | 24 ++++++++++++++++++++++++
19 util/grub.d/10_linux.in | 5 +++++
20 util/grub.d/20_linux_xen.in | 5 +++++
21 3 files changed, 34 insertions(+)
23 diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
24 index 3a4684e78..9ee60d5fa 100644
25 --- a/util/grub-mkconfig_lib.in
26 +++ b/util/grub-mkconfig_lib.in
27 @@ -133,6 +133,22 @@ prepare_grub_to_access_device ()
33 + /dev/loop/*|/dev/loop[0-9])
34 + grub_loop_device="${1#/dev/}"
35 + loop_file=`losetup "$1" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
41 + set -- `"${grub_probe}" --target=device "${loop_file}"` "$@"
47 # Abstraction modules aren't auto-loaded.
48 abstraction="`"${grub_probe}" --device $@ --target=abstraction`"
49 for module in ${abstraction} ; do
50 @@ -165,6 +181,14 @@ prepare_grub_to_access_device ()
55 + if [ "x${loop_file}" != x ]; then
56 + loop_mountpoint="$(awk '"'${loop_file}'" ~ "^"$2 && $2 != "/" { print $2 }' /proc/mounts | tail -n1)"
57 + if [ "x${loop_mountpoint}" != x ]; then
58 + echo "loopback ${grub_loop_device} ${loop_file#$loop_mountpoint}"
59 + echo "set root=(${grub_loop_device})"
65 diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
66 index c34d470c9..5ff76f59a 100644
67 --- a/util/grub.d/10_linux.in
68 +++ b/util/grub.d/10_linux.in
70 case ${GRUB_DEVICE} in
71 /dev/loop/*|/dev/loop[0-9])
72 GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
73 + # We can't cope with devices loop-mounted from files here.
74 + case ${GRUB_DEVICE} in
81 diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
82 index c48af948d..af05bd276 100644
83 --- a/util/grub.d/20_linux_xen.in
84 +++ b/util/grub.d/20_linux_xen.in
86 case ${GRUB_DEVICE} in
87 /dev/loop/*|/dev/loop[0-9])
88 GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
89 + # We can't cope with devices loop-mounted from files here.
90 + case ${GRUB_DEVICE} in