File: mkconfig-loopback.patch

package info (click to toggle)
grub2 2.12-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie, trixie-proposed-updates, trixie-updates
  • size: 70,780 kB
  • sloc: ansic: 424,740; asm: 16,228; sh: 9,525; cpp: 2,095; makefile: 1,590; python: 1,468; sed: 431; lex: 393; yacc: 268; awk: 85; lisp: 54; perl: 31
file content (95 lines) | stat: -rw-r--r-- 2,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From: Colin Watson <cjwatson@debian.org>
Date: Mon, 13 Jan 2014 12:13:00 +0000
Subject: Handle filesystems loop-mounted on file images

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
---
 util/grub-mkconfig_lib.in   | 24 ++++++++++++++++++++++++
 util/grub.d/10_linux.in     |  5 +++++
 util/grub.d/20_linux_xen.in |  5 +++++
 3 files changed, 34 insertions(+)

diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 33e1750..cc3c4f0 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -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 ()
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index e661e9d..cc6ae58 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -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
 
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
index 94dd8be..f496beb 100644
--- a/util/grub.d/20_linux_xen.in
+++ b/util/grub.d/20_linux_xen.in
@@ -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