Gentoo Archives: gentoo-commits

From: Ben Kohler <bkohler@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-boot/os-prober/files/
Date: Wed, 22 Dec 2021 12:34:20
Message-Id: 1640176429.4e135dcb12f4cc3716becfd461786bfa370eb416.bkohler@gentoo
1 commit: 4e135dcb12f4cc3716becfd461786bfa370eb416
2 Author: Peter Levine <plevine457 <AT> gmail <DOT> com>
3 AuthorDate: Tue Dec 21 00:25:05 2021 +0000
4 Commit: Ben Kohler <bkohler <AT> gentoo <DOT> org>
5 CommitDate: Wed Dec 22 12:33:49 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4e135dcb
7
8 sys-boot/os-prober: switch btrfs patch from openSUSE to Fedora
9
10 Fixes issues related to undetected linux installations. This combines
11 Fedora's os-prober-btrfsfix.patch and openSUSE's
12 Improve-btrfs-handling-on-os-probing-for-grub2.patch, augmented to
13 correctly parse multiple initrd paths.
14
15 Tested-by: ernsteiswuerfel <erhard_f <AT> mailbox.org>
16 Bug: https://bugs.gentoo.org/817905
17 Package-Manager: Portage-3.0.30, Repoman-3.0.3
18 Signed-off-by: Peter Levine <plevine457 <AT> gmail.com>
19 Signed-off-by: Ben Kohler <bkohler <AT> gentoo.org>
20
21 .../os-prober-1.79-btrfs-subvolume-detection.patch | 238 +++++++++++----------
22 1 file changed, 122 insertions(+), 116 deletions(-)
23
24 diff --git a/sys-boot/os-prober/files/os-prober-1.79-btrfs-subvolume-detection.patch b/sys-boot/os-prober/files/os-prober-1.79-btrfs-subvolume-detection.patch
25 index 14cd794530ee..61337661401f 100644
26 --- a/sys-boot/os-prober/files/os-prober-1.79-btrfs-subvolume-detection.patch
27 +++ b/sys-boot/os-prober/files/os-prober-1.79-btrfs-subvolume-detection.patch
28 @@ -1,23 +1,22 @@
29 Fixes detection of multiple linux installations on different subvolumes of the
30 -same partition. Also contains changes from
31 -https://build.opensuse.org/package/view_file/openSUSE:Factory/os-prober/os-prober-btrfs-always-detect-default.patch
32 -to fix https://bugs.gentoo.org/790434.
33 +same partition. This patch is a combination of https://src.fedoraproject.org/rpms/os-prober/blob/a27e5121193e2222ada672db3521a7d9de70991b/f/os-prober-btrfsfix.patch and https://build.opensuse.org/package/view_file/openSUSE:Factory/os-prober/Improve-btrfs-handling-on-os-probing-for-grub2.patch?rev=56 .
34
35 Bug: https://bugs.gentoo.org/790434
36 + https://bugs.gentoo.org/817905
37 https://bugs.debian.org/688336
38 https://bugzilla.redhat.com/888341
39
40 --- a/common.sh
41 +++ b/common.sh
42 -@@ -155,6 +155,7 @@
43 +@@ -155,6 +155,7 @@ parse_proc_mounts () {
44 done
45 }
46 -
47 +
48 +# add forth parameter to pickup btrfs subvol info
49 parsefstab () {
50 while read -r line; do
51 case "$line" in
52 -@@ -165,12 +166,22 @@
53 +@@ -165,12 +166,22 @@ parsefstab () {
54 set -f
55 set -- $line
56 set +f
57 @@ -27,7 +26,7 @@ Bug: https://bugs.gentoo.org/790434
58 esac
59 done
60 }
61 -
62 +
63 +#check_btrfs_mounted $bootsv $bootuuid)
64 +check_btrfs_mounted () {
65 + bootsv="$1"
66 @@ -43,8 +42,8 @@ Bug: https://bugs.gentoo.org/790434
67 sed 's/\\011/ /g; s/\\012/\n/g; s/\\040/ /g; s/\\134/\\/g'
68 --- a/linux-boot-prober
69 +++ b/linux-boot-prober
70 -@@ -5,16 +5,148 @@
71 -
72 +@@ -5,16 +5,143 @@ set -e
73 +
74 newns "$@"
75 require_tmpdir
76 +ERR="n"
77 @@ -58,9 +57,9 @@ Bug: https://bugs.gentoo.org/790434
78 +bootmnt=
79 +bootsv=
80 +bootuuid=
81 -
82 +
83 grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true
84 -
85 +
86 -partition="$1"
87 +if [ -z "$1" ]; then
88 + ERR=y
89 @@ -80,14 +79,14 @@ Bug: https://bugs.gentoo.org/790434
90 + partition="$1"
91 + type=other
92 +fi
93 -
94 +
95 -if [ -z "$partition" ]; then
96 +if [ "x$ERR" != xn ]; then
97 echo "usage: linux-boot-prober partition" >&2
98 + echo " linux-boot-prober btrfs UUID=<> subvol=<>" >&2
99 exit 1
100 fi
101 -
102 +
103 +if [ "$type" = btrfs ]; then
104 + # handle all of the btrfs stuff here
105 + if [ ! -e "/proc/self/mountinfo" ]; then
106 @@ -111,12 +110,7 @@ Bug: https://bugs.gentoo.org/790434
107 + fi
108 + if [ -z "$mpoint" ]; then
109 + # mount the btrfs root
110 -+
111 -+ if [ -n "$subvol" ]; then
112 -+ opts="-o subvol=$subvol"
113 -+ fi
114 -+
115 -+ if ! mount $opts -t btrfs -U $UUID "$tmpmnt" 2>/dev/null; then
116 ++ if ! mount -o subvol=$subvol -t btrfs -U $UUID "$tmpmnt" 2>/dev/null; then
117 + warn "error mounting btrfs subvol=$subvol UUID=$UUID"
118 + umount "$tmpmnt/boot" 2>/dev/null
119 + umount "$tmpmnt" 2>/dev/null
120 @@ -194,8 +188,8 @@ Bug: https://bugs.gentoo.org/790434
121 if ! mapped="$(mapdevfs "$partition")"; then
122 log "Device '$partition' does not exist; skipping"
123 continue
124 -@@ -22,8 +154,8 @@
125 -
126 +@@ -22,8 +149,8 @@ fi
127 +
128 if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map"; then
129 for test in /usr/lib/linux-boot-probes/*; do
130 - debug "running $test"
131 @@ -206,10 +200,10 @@ Bug: https://bugs.gentoo.org/790434
132 break
133 --- a/linux-boot-probes/mounted/common/40grub2
134 +++ b/linux-boot-probes/mounted/common/40grub2
135 -@@ -2,17 +2,30 @@
136 +@@ -2,17 +2,42 @@
137 . /usr/share/os-prober/common.sh
138 set -e
139 -
140 +
141 +# add support for btrfs with no separate /boot
142 +# that is, rootsv = bootsv
143 partition="$1"
144 @@ -218,16 +212,28 @@ Bug: https://bugs.gentoo.org/790434
145 type="$4"
146 +rootsv="$5"
147 +bootsv="$6"
148 -
149 +
150 found_item=0
151 -
152 +
153 entry_result () {
154 -+ if [ "x$type" = "xbtrfs" -a "$partition" = "$bootpart" ]; then
155 -+ # trim off the leading subvol
156 -+ kernelfile=$(echo "$kernel" | cut -d '/' -f 2- | cut -d '/' -f 2-)
157 -+ if [ "x$rootsv" != "x$bootsv" ]; then
158 -+ kernelfile="/boot/$kernelfile"
159 ++ if [ "x$type" = "xbtrfs" ]; then
160 ++ bsv=${bootsv:+/}${bootsv}
161 ++ # if path is not relative to subvolume make it relative
162 ++ kernel=${kernel#${bsv}}
163 ++ kernelfile=$kernel
164 ++ initrd=${initrd#${bsv}}
165 ++ if [ "x$GRUB_FS" != "xbtrfs" ]; then
166 ++ # absolute path needed: prepend subvolume if $kernel isn't empty
167 ++ kernel=${kernel:+${bsv}}${kernel}
168 ++ # handle multiple initrd paths
169 ++ local initrd_path=
170 ++ for path in ${initrd}; do
171 ++ initrd_path+="${bsv}${path} "
172 ++ done
173 ++ initrd="${initrd_path% }"
174 + fi
175 ++ # assumed: rootsv != bootsv if rootsv isn't ancestor of bootsv
176 ++ [ "$partition" != "$bootpart" -o "$rootsv" != "$bootsv" ] && kernelfile="/boot${kernelfile}"
177 + else
178 + kernelfile=$kernel
179 + fi
180 @@ -238,22 +244,41 @@ Bug: https://bugs.gentoo.org/790434
181 result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
182 found_item=1
183 fi
184 -@@ -108,9 +121,9 @@
185 - [ "$mpoint/boot/grub/grub.cfg" -nt "$mpoint/boot/grub/menu.lst" ]); then
186 - debug "parsing grub.cfg"
187 - parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub/grub.cfg"
188 --elif [ -e "$mpoint/boot/grub2/grub.cfg" ]; then
189 -+elif [ -e "$mpoint/boot/grub/grub.cfg" ]; then
190 - debug "parsing grub.cfg"
191 -- parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub2/grub.cfg"
192 -+ parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub/grub.cfg"
193 - fi
194 -
195 - if [ "$found_item" = 0 ]; then
196 +@@ -64,7 +88,7 @@ parse_grub_menu () {
197 + ignore_item=1
198 + fi
199 + ;;
200 +- linux)
201 ++ linux|linuxefi|linux16)
202 + # Hack alert: sed off any (hdn,n) but
203 + # assume the kernel is on the same
204 + # partition.
205 +@@ -73,18 +98,18 @@ parse_grub_menu () {
206 + parameters="$@"
207 + # Systems with a separate /boot will not have
208 + # the path to the kernel in grub.cfg.
209 +- if [ "$partition" != "$bootpart" ]; then
210 ++ if [ "$partition" != "$bootpart" -a "$type" != "btrfs" ]; then
211 + kernel="/boot$kernel"
212 + fi
213 + ;;
214 +- initrd)
215 ++ initrd|initrdefi|initrd16)
216 + shift
217 + initrd=""
218 + for initrd_path in "$@"; do
219 + # sed hack, as above
220 + initrd_path="$(echo "$initrd_path" | sed 's/(.*)//')"
221 + # Initrd same.
222 +- if [ "$partition" != "$bootpart" ]; then
223 ++ if [ "$partition" != "$bootpart" -a "$type" != "btrfs" ]; then
224 + initrd_path="/boot$initrd_path"
225 + fi
226 + if [ -z "$initrd" ]; then
227 --- a/os-prober
228 +++ b/os-prober
229 -@@ -76,9 +76,12 @@
230 -
231 +@@ -76,9 +76,12 @@ partitions () {
232 +
233 # Also detect OSes on LVM volumes (assumes LVM is active)
234 if type lvs >/dev/null 2>&1; then
235 - echo "$(LVM_SUPPRESS_FD_WARNINGS=1 log_output lvs --noheadings --separator : -o vg_name,lv_name |
236 @@ -264,21 +289,21 @@ Bug: https://bugs.gentoo.org/790434
237 + # now lets make sure we got all of the btrfs partitions and disks
238 + blkid | grep 'TYPE="btrfs"' | cut -d ':' -f 1
239 }
240 -
241 +
242 parse_proc_swaps () {
243 -@@ -136,6 +139,8 @@
244 +@@ -136,6 +139,8 @@ if [ -f /proc/mdstat ] ; then
245 grep "^md" /proc/mdstat | cut -d: -f2- | parse_proc_mdstat >"$OS_PROBER_TMP/raided-map" || true
246 fi
247 -
248 +
249 +: >"$OS_PROBER_TMP/btrfs-vols"
250 +
251 for partition in $(partitions); do
252 if ! mapped="$(mapdevfs "$partition")"; then
253 log "Device '$partition' does not exist; skipping"
254 -@@ -154,7 +159,26 @@
255 +@@ -154,7 +159,26 @@ for partition in $(partitions); do
256 continue
257 fi
258 -
259 +
260 - if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map" ; then
261 + # do btrfs processing here; both mounted and unmounted will
262 + # be handled by 50mounted-tests so we can do a subvol only once.
263 @@ -305,10 +330,10 @@ Bug: https://bugs.gentoo.org/790434
264 debug "running $test on $partition"
265 --- a/os-probes/common/50mounted-tests
266 +++ b/os-probes/common/50mounted-tests
267 -@@ -14,19 +14,31 @@
268 +@@ -14,19 +14,31 @@ do_unmount() {
269 rmdir "$tmpmnt" || true
270 }
271 -
272 +
273 -types="$(fs_type "$partition")"
274 +if [ "x$1" = xbtrfs ]; then
275 + types=btrfs
276 @@ -342,7 +367,7 @@ Bug: https://bugs.gentoo.org/790434
277 elif [ "$types" = ntfs ]; then
278 if type ntfs-3g >/dev/null 2>&1; then
279 types='ntfs-3g ntfs'
280 -@@ -35,7 +47,7 @@
281 +@@ -35,7 +47,7 @@ elif [ -z "$types" ]; then
282 if type cryptsetup >/dev/null 2>&1 && \
283 cryptsetup luksDump "$partition" >/dev/null 2>&1; then
284 debug "$1 is a LUKS partition; skipping"
285 @@ -351,52 +376,11 @@ Bug: https://bugs.gentoo.org/790434
286 fi
287 for type in $(grep -v nodev /proc/filesystems); do
288 # hfsplus filesystems are mountable as hfs. Try hfs last so
289 -@@ -58,6 +70,127 @@
290 +@@ -58,6 +70,108 @@ if [ ! -d "$tmpmnt" ]; then
291 fi
292 -
293 +
294 mounted=
295 +
296 -+probe_subvol ()
297 -+{
298 -+ local subvol=$1
299 -+ local partition=$2
300 -+ local UUID=$3
301 -+ local tmpmnt=$4
302 -+
303 -+ mounted=
304 -+ mpoint="$(grep btrfs /proc/self/mountinfo | grep "$partition " | grep "/$subvol " | cut -d ' ' -f 5)"
305 -+ ret=1
306 -+
307 -+ if [ -n "$subvol" ]; then
308 -+ opts="-o subvol=$subvol"
309 -+ fi
310 -+
311 -+ if [ -n "$mpoint" ]; then
312 -+ if [ "x$mpoint" = "x/" ]; then
313 -+ continue # this is the root for the running system
314 -+ fi
315 -+ mounted=1
316 -+ else
317 -+ # again, do not mount btrfs ro
318 -+ mount -t btrfs $opts -U "$UUID" "$tmpmnt"
319 -+ mpoint="$tmpmnt"
320 -+ fi
321 -+ test="/usr/lib/os-probes/mounted/90linux-distro"
322 -+ if [ -f "$test" ] && [ -x "$test" ]; then
323 -+ debug "running subtest $test"
324 -+ if "$test" "$partition" "$mpoint" btrfs "UUID=$UUID" "subvol=$subvol"; then
325 -+ debug "os found by subtest $test on subvol $subvol"
326 -+ ret=0
327 -+ fi
328 -+ fi
329 -+ if [ -z "$mounted" ]; then
330 -+ if ! umount "$tmpmnt"; then
331 -+ warn "failed to umount $tmpmnt"
332 -+ fi
333 -+ fi
334 -+ return $ret
335 -+}
336 -+
337 +# all btrfs processing here. Handle both unmounted and
338 +# mounted subvolumes.
339 +if [ "$types" = btrfs ]; then
340 @@ -436,7 +420,7 @@ Bug: https://bugs.gentoo.org/790434
341 + mpoint="$tmpmnt"
342 + fi
343 +
344 -+ test="/usr/libexec/os-probes/mounted/90linux-distro"
345 ++ test="/usr/lib/os-probes/mounted/90linux-distro"
346 + if [ -f "$test" ] && [ -x "$test" ]; then
347 + debug "running subtest $test"
348 + if "$test" "$partition" "$mpoint" btrfs "UUID=$UUID"; then
349 @@ -450,24 +434,46 @@ Bug: https://bugs.gentoo.org/790434
350 + fi
351 + fi
352 + fi
353 -+ found=
354 -+ # Always probe subvol or root set as default
355 -+ if probe_subvol "$defaultvol" "$partition" "$UUID" "$tmpmnt"; then
356 -+ found=1
357 -+ fi
358 +
359 -+ # Probe any other OS on subvol
360 -+ for subvol in $subvols; do
361 -+ if echo "$rosubvols" | grep -q -x "$subvol" ||
362 -+ echo "$sssubvols" | grep -q -x "$subvol" ||
363 -+ echo "$defaultvol" | grep -q -x "$subvol"; then
364 -+ continue
365 -+ fi
366 -+ debug "begin btrfs processing for $UUID subvol=$subvol"
367 -+ if probe_subvol "$subvol" "$partition" "$UUID" "$tmpmnt"; then
368 -+ found=1
369 -+ fi
370 -+ done
371 ++ if [ -z "$subvols" ]; then
372 ++ debug "no subvols found on btrfs volume $UUID"
373 ++ else
374 ++ found=
375 ++ for subvol in $subvols; do
376 ++ debug "begin btrfs processing for $UUID subvol=$subvol"
377 ++ if echo "$rosubvols" | grep -q -x "$subvol"; then
378 ++ continue
379 ++ fi
380 ++ if echo "$sssubvols" | grep -q -x "$subvol"; then
381 ++ continue
382 ++ fi
383 ++ mounted=
384 ++ mpoint="$(grep btrfs /proc/self/mountinfo | grep "$partition " | grep "/$subvol " | cut -d ' ' -f 5)"
385 ++ if [ -n "$mpoint" ]; then
386 ++ if [ "x$mpoint" = "x/" ]; then
387 ++ continue # this is the root for the running system
388 ++ fi
389 ++ mounted=1
390 ++ else
391 ++ # again, do not mount btrfs ro
392 ++ mount -t btrfs -o subvol="$subvol" -U "$UUID" "$tmpmnt"
393 ++ mpoint="$tmpmnt"
394 ++ fi
395 ++ test="/usr/lib/os-probes/mounted/90linux-distro"
396 ++ if [ -f "$test" ] && [ -x "$test" ]; then
397 ++ debug "running subtest $test"
398 ++ if "$test" "$partition" "$mpoint" btrfs "UUID=$UUID" "subvol=$subvol"; then
399 ++ debug "os found by subtest $test on subvol $subvol"
400 ++ found=1
401 ++ fi
402 ++ fi
403 ++ if [ -z "$mounted" ]; then
404 ++ if ! umount "$tmpmnt"; then
405 ++ warn "failed to umount $tmpmnt"
406 ++ fi
407 ++ fi
408 ++ done
409 ++ fi
410 + rmdir "$tmpmnt" || true
411 + if [ "$found" ]; then
412 + exit 0
413 @@ -481,16 +487,16 @@ Bug: https://bugs.gentoo.org/790434
414 grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
415 --- a/os-probes/mounted/common/90linux-distro
416 +++ b/os-probes/mounted/common/90linux-distro
417 -@@ -7,6 +7,8 @@
418 +@@ -7,6 +7,8 @@ set -e
419 partition="$1"
420 dir="$2"
421 type="$3"
422 +uuid="$4"
423 +subvol="$5"
424 -
425 +
426 # This test is inaccurate, but given separate / and /boot partitions and the
427 # fact that only some architectures have ld-linux.so, I can't see anything
428 -@@ -143,7 +145,11 @@
429 +@@ -143,7 +145,11 @@ if (ls "$dir"/lib*/ld*.so* && [ -d "$dir/boot" ] || ls "$dir"/usr/lib*/ld*.so*)
430 fi
431
432 label="$(count_next_label "$short")"