summarylogtreecommitdiffstats
path: root/Improve-btrfs-handling-on-os-probing-for-grub2.patch
blob: 4e79674f9662b824171ab03967d4b598dda86506 (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
84
85
86
87
88
89
90
91
92
93
94
From: Egbert Eich <eich@suse.de>
Date: Fri May 29 08:55:21 2015 +0200
Subject: Improve btrfs handling on os-probing for grub2
Patch-mainline: never

References: bsc#892364
Signed-off-by: Egbert Eich <eich@suse.com>

Currently probing of a grub2 config file is broken if
the root/boot fs is btrfs. This is due to a patch picked
from Fedora which attempts to determine the location of
the kernel and probe for it.
This code has meanwhile changed on Fedora, however the
new version works no better than the old one.
It is possible that this code works under very special
circumstances of the Fedora system, however it is by no
means valid.
Our goal is to
a. determine the location of the kernel in the mounted fs
   regardless whether the grub2 config specifies an absolute
   or relative path to the kernel file.
b. Prepend the correct prefix if grub2_btrfs expects an
   absolute path (either because the current grub2 fs isn't
   btrfs or absolute path addressing is explicitely requested).
c. Attempt to handle the location of the kernel file correctly
   if this lives on a separate btrfs subvolume.
   (Currently this only works if the path to this subvolume is
   identical to the fs path).

Signed-off-by: Egbert Eich <eich@suse.de>

v2:
a. Fix missing linux16/initrd16 parsing in entry result
b. Fix kernelfile path if separate boot partition on btrfs

Signed-off-by: Michael Chang <mchang@suse.com>
---
 linux-boot-probes/mounted/common/40grub2 | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Index: os-prober-1.61/linux-boot-probes/mounted/common/40grub2
===================================================================
--- os-prober-1.61.orig/linux-boot-probes/mounted/common/40grub2
+++ os-prober-1.61/linux-boot-probes/mounted/common/40grub2
@@ -14,9 +14,19 @@ bootsv="$6"
 found_item=0

 entry_result () {
-	if [ "x$type" = "xbtrfs" -a "$rootsv" = "$bootsv" ]; then
-		# trim off the leading subvol
-		kernelfile=$(echo "$kernel" | cut -d '/' -f 2- | cut -d '/' -f 2-)
+	if [ "x$type" = "xbtrfs" ]; then
+		bsv=${bootsv:+/}${bootsv}
+		# if path is not relative to subvolume make it relative
+		kernel=${kernel#${bsv}}
+		kernelfile=$kernel
+		initrd=${initrd#${bsv}}
+		if [ "x$GRUB_FS" != "xbtrfs" -o "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" != "xtrue" ]; then
+		    # absolute path needed: prepend subvolume if $kernel isn't empty
+		    kernel=${kernel:+${bsv}}${kernel}
+		    initrd=${initrd:+${bsv}}${initrd}
+		fi
+		# assumed: rootsv != bootsv if rootsv isn't ancestor of bootsv
+		[ "$partition" != "$bootpart" -o "$rootsv" != "$bootsv" ] && kernelfile="/boot${kernelfile}"
 	else
 		kernelfile=$kernel
 	fi
@@ -81,7 +91,7 @@ parse_grub_menu () {
 					ignore_item=1
 				fi
 			;;
-			linux|linuxefi)
+			linux|linuxefi|linux16)
 				# Hack alert: sed off any (hdn,n) but
 				# assume the kernel is on the same
 				# partition.
@@ -90,14 +100,14 @@ parse_grub_menu () {
 				parameters="$@"
 				# Systems with a separate /boot will not have
 				# the path to the kernel in grub.cfg.
-				if [ "$partition" != "$bootpart" ]; then
+				if [ "$partition" != "$bootpart" -a "$type" != "btrfs" ]; then
 					kernel="/boot$kernel"
 				fi
 			;;
-			initrd|initrdefi)
+			initrd|initrdefi|initrd16)
 				initrd="$(echo "$2" | sed 's/(.*)//')"
 				# Initrd same.
-				if [ "$partition" != "$bootpart" ]; then
+				if [ "$partition" != "$bootpart" -a "$type" != "btrfs" ]; then
 					initrd="/boot$initrd"
 				fi
 			;;