summaryrefslogtreecommitdiff
path: root/sys-boot/grub/files/grub-1.98-add-legacy-rootfs-detection.patch
blob: 1fadd46168298f2865ec66ee6381909d2b2ccf42 (plain)
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
diff -ur grub2-orig/util/grub-mkconfig.in grub2-new/util/grub-mkconfig.in
--- grub2-orig/util/grub-mkconfig.in	2010-01-28 15:01:46.746567396 +0100
+++ grub2-new/util/grub-mkconfig.in	2010-01-28 15:38:48.560587115 +0100
@@ -119,8 +119,8 @@
 fi
 
 # Device containing our userland.  Typically used for root= parameter.
-GRUB_DEVICE="`${grub_probe} --target=device /`"
-GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE="`${grub_probe} --target=device /`" || GRUB_DEVICE="`legacy_find_root_device`"
+GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || GRUB_DEVICE_UUID="`legacy_convert_to_uuid ${GRUB_DEVICE}`"
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
diff -ur grub2-orig/util/grub-mkconfig_lib.in grub2-new/util/grub-mkconfig_lib.in
--- grub2-orig/util/grub-mkconfig_lib.in	2010-01-28 15:01:46.740383831 +0100
+++ grub2-new/util/grub-mkconfig_lib.in	2010-01-28 15:38:10.474013430 +0100
@@ -188,3 +188,65 @@
   done
   echo "$a"
 }
+
+legacy_find_root_device ()
+{
+  mount_point=$1
+
+  # Autodetect current root device
+  device=
+  if [ -f /etc/fstab ] ; then
+    device="`awk '$1!~/^#/{
+      if ($2 ~ "^/+$") { $2 = "/"; } else { sub("/*$", "", $2); }
+      if ($2 == "'"$mount_point"'"){
+        print $1;
+      }
+    }' /etc/fstab | tail -n 1`"
+  fi
+
+  if [ -n "$device" ] ; then
+    case "$device" in
+      LABEL=* | UUID=*)
+        device="`findfs $device`"
+	device="`readlink -f "$device"`"
+      ;;
+      *)
+        device=`readlink -f "$device"`
+      ;;
+    esac
+  fi
+
+  echo $device
+}
+
+legacy_convert_to_uuid()
+{
+  echo "Cannot determine uuid of root device.  Trying legacy probe method" >&2
+  local dev; dev="$1"
+  
+  convert=false
+  case "$dev" in
+    /dev/disk/*)
+      ;;
+    /dev/mapper/*)
+      ;;
+    /dev/evms/[hs]d[a-z][0-9]*)
+      convert=:
+      ;;
+    /dev/evms/*)
+      ;;
+    /dev/md[0-9]*)
+      ;;
+    /dev/*)
+      convert=:
+      ;;
+  esac
+  if $convert; then
+    if [ -b "$dev" ]; then
+      uuid="`blkid -o value -s UUID "$dev" || true`"
+    fi
+  fi
+
+  echo "$uuid"
+}
+