1
0
forked from ports/contrib

os-prober: 1.79 -> 1.80

This commit is contained in:
Tim Biermann 2022-05-28 13:42:24 +02:00
parent 2a726c72f5
commit 0d3207fdda
Signed by: tb
GPG Key ID: 42F8B4E30B673606
9 changed files with 651 additions and 21 deletions

View File

@ -1,6 +1,11 @@
untrusted comment: verify with /etc/ports/contrib.pub
RWSagIOpLGJF391d/+M2zgcjjsP3jA1RYxk1wRGz0perQ/MN82hKsunJkvBTnQsk0qg3Tohnosc9eaQL4EJ59CdK5JCWSw0kaAA=
SHA256 (Pkgfile) = edc57a2615a452245b6b52a2a0f9855924ae62a2c7178565cb9c2aa9ee7cc3d6
RWSagIOpLGJF3/ZoLwd6XMTTf9TzcAkkES65JTlOGT8z4IQaChgzF0T2sIu+DEKyNpgqkjdQI6d4AbQY2oh4dxFBWjBgkZgSzwc=
SHA256 (Pkgfile) = a20a96d8c0dfe0cabc361e63d5ee41d689bb9ea58ea7fe3e20f96404aa0d7c9a
SHA256 (.footprint) = 304a8bff621cd9e72899712ff96855b3a777f9f233dcb4820f32fba094becae7
SHA256 (os-prober_1.79.tar.xz) = abe6317d078c4e51e322e62036b6df4a698bfe80c5be110a08894841179810ee
SHA256 (Fix-CRUX-grub-menu-entry-detection.patch) = cc77faf6fa1eaf281db0c04798dd8c3f81d12722d29527c021e9dfae896ded36
SHA256 (os-prober_1.80.tar.xz) = 8063c38b9d006b94869e4127057d1189cb1adb561c2085c400b297ffa0cee38f
SHA256 (os-prober-1.79-btrfs-subvolume-detection.patch) = 15bb651eec5a0ae9bd08fc70f1cc23246cf31e7054838d162020d4806dc67810
SHA256 (os-prober-1.79-use-fstab-name.patch) = efb22d59db0c60fa1545ae8e18ac5585fda44a8a95ef8c46bca8499f79c7ad27
SHA256 (os-prober-1.79-mounted-boot-partition-fix.patch) = fc46f47cb10d25387244888780733abfc4c45a7be44e8a49935d054aa5b82749
SHA256 (os-prober-1.79-fix-busy-umount-message.patch) = 14164906bb62415769efa76f874cf236cd1c73e8e9c87e0fc8f3f5674bc85424
SHA256 (os-prober-1.79-efi-chroot-blkid-fallback.patch) = 3b6f28d91dcc0389039a14992aa197eba18c083cb9762157e32414a5e5f026ef
SHA256 (add-CRUX-detection.patch) = 7da0c45bbde226b92cf2ea7116bf084806a066ca29ff1d52bb4a7ab90f03a5f5

View File

@ -1,12 +0,0 @@
--- a/os-probes/mounted/common/90linux-distro 2017-05-04 14:57:23.197520770 +0800
+++ b/os-probes/mounted/common/90linux-distro 2017-05-04 15:09:13.848541790 +0800
@@ -137,6 +137,9 @@ if (ls "$dir"/lib*/ld*.so* && [ -d "$dir
elif [ -e "$dir/etc/devuan_version" ]; then
short="Devuan"
long="$(printf "Devuan GNU/Linux (%s)\n" "$(cat "$dir/etc/devuan_version")")"
+ elif [ -e "$dir/usr/bin/crux" ]; then
+ short="CRUX"
+ long="$(printf "CRUX GNU/Linux" "$(cat "$dir/usr/bin/crux" | grep echo | cut -b 20-22)")"
else
short="Linux"
long="unknown Linux distribution"

View File

@ -1,22 +1,37 @@
# Description: Tool to detect other OSes.
# URL: http://joey.kitenet.net/code/os-prober
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on:
# Depends on: grub2
name=os-prober
version=1.79
version=1.80
release=1
source=(http://ftp.de.debian.org/debian/pool/main/o/$name/${name}_$version.tar.xz
Fix-CRUX-grub-menu-entry-detection.patch)
# grabbed from gentoo
os-prober-1.79-btrfs-subvolume-detection.patch
os-prober-1.79-use-fstab-name.patch
os-prober-1.79-mounted-boot-partition-fix.patch
os-prober-1.79-fix-busy-umount-message.patch
os-prober-1.79-efi-chroot-blkid-fallback.patch
add-CRUX-detection.patch)
build() {
cd $name
patch -Np1 -i $SRC/Fix-CRUX-grub-menu-entry-detection.patch
cd $name-$version
patch -Np1 -i $SRC/add-CRUX-detection.patch
patch -Np1 -i $SRC/os-prober-1.79-btrfs-subvolume-detection.patch
patch -Np1 -i $SRC/os-prober-1.79-use-fstab-name.patch
patch -Np1 -i $SRC/os-prober-1.79-mounted-boot-partition-fix.patch
patch -Np1 -i $SRC/os-prober-1.79-fix-busy-umount-message.patch
patch -Np1 -i $SRC/os-prober-1.79-efi-chroot-blkid-fallback.patch
# Adjust lib dir to allow detection of 64-bit distros
sed -i -e "s:/lib/ld\*\.so\*:/lib*/ld*.so*:g" os-probes/mounted/common/90linux-distro
rm -f Makefile
make newns
find . -iname "*.orig" -delete
install -Dm755 linux-boot-prober $PKG/usr/bin/linux-boot-prober
install -Dm755 $name $PKG/usr/bin/$name
install -Dm755 newns $PKG/usr/lib/$name/newns

View File

@ -0,0 +1,15 @@
diff -Naur os-prober-1.80.orig/os-probes/mounted/common/90linux-distro os-prober-1.80/os-probes/mounted/common/90linux-distro
--- os-prober-1.80.orig/os-probes/mounted/common/90linux-distro 2022-05-28 11:49:43.439329688 +0200
+++ os-prober-1.80/os-probes/mounted/common/90linux-distro 2022-05-28 12:05:30.890279156 +0200
@@ -27,6 +27,11 @@
elif [ -e "$dir/etc/debian_version" ]; then
short="Debian"
long="$(printf "Debian GNU/Linux (%s)\n" "$(cat "$dir/etc/debian_version")")"
+ # CRUX traditionally only supplies /usr/bin/crux with only newer versions
+ # supporting /etc/os-release, we only need name and version anyway
+ elif [ -e "$dir/usr/bin/crux" ]; then
+ short="$(awk '/echo / {gsub(/"|,/, "", $2); print $2}' $dir/usr/bin/crux)"
+ long="$(awk '/echo / {gsub(/"|,/, "", $2);gsub(/"|,/, "", $4); print $2 " " $4}' $dir/usr/bin/crux)"
# RPM derived distributions may also have a redhat-release or
# mandrake-release, so check their files first.
elif [ -e "$dir/etc/altlinux-release" ]; then

View File

@ -0,0 +1,511 @@
Fixes detection of multiple linux installations on different subvolumes of the
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 .
Bug: https://bugs.gentoo.org/790434
https://bugs.gentoo.org/817905
https://bugs.debian.org/688336
https://bugzilla.redhat.com/888341
--- a/common.sh
+++ b/common.sh
@@ -155,6 +155,7 @@ parse_proc_mounts () {
done
}
+# add forth parameter to pickup btrfs subvol info
parsefstab () {
while read -r line; do
case "$line" in
@@ -165,12 +166,22 @@ parsefstab () {
set -f
set -- $line
set +f
- printf '%s %s %s\n' "$1" "$2" "$3"
+ printf '%s %s %s %s\n' "$1" "$2" "$3" "$4"
;;
esac
done
}
+#check_btrfs_mounted $bootsv $bootuuid)
+check_btrfs_mounted () {
+ bootsv="$1"
+ bootuuid="$2"
+ bootdev=$(blkid | grep "$bootuuid" | cut -d ':' -f 1)
+ bindfrom=$(grep " btrfs " /proc/self/mountinfo |
+ grep " $bootdev " | grep " /$bootsv " | cut -d ' ' -f 5)
+ printf "%s" "$bindfrom"
+}
+
unescape_mount () {
printf %s "$1" | \
sed 's/\\011/ /g; s/\\012/\n/g; s/\\040/ /g; s/\\134/\\/g'
--- a/linux-boot-prober
+++ b/linux-boot-prober
@@ -5,16 +5,143 @@ set -e
newns "$@"
require_tmpdir
+ERR="n"
+
+tmpmnt=/var/lib/os-prober/mount
+if [ ! -d "$tmpmnt" ]; then
+ mkdir "$tmpmnt"
+fi
+
+mounted=
+bootmnt=
+bootsv=
+bootuuid=
grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true
-partition="$1"
+if [ -z "$1" ]; then
+ ERR=y
+elif [ "$1" = btrfs -a -z "$2" ]; then
+ ERR=y
+elif [ "$1" = btrfs -a -z "$3" ]; then
+ ERR=y
+elif [ "$1" = btrfs ]; then
+ type=btrfs
+ echo "$2" | grep -q "^UUID=" || ERR=y
+ echo "$3" | grep -q "^subvol=" || ERR=y
+ export "$2"
+ export "$3"
+ partition=$(blkid | grep "$UUID" | cut -d ':' -f 1 | tr '\n' ' ' | cut -d ' ' -f 1)
+ debug "btrfs: partition=$partition, UUID=$UUID, subvol=$subvol"
+else
+ partition="$1"
+ type=other
+fi
-if [ -z "$partition" ]; then
+if [ "x$ERR" != xn ]; then
echo "usage: linux-boot-prober partition" >&2
+ echo " linux-boot-prober btrfs UUID=<> subvol=<>" >&2
exit 1
fi
+if [ "$type" = btrfs ]; then
+ # handle all of the btrfs stuff here
+ if [ ! -e "/proc/self/mountinfo" ]; then
+ warn "/proc/self/mountinfo does not exist, exiting"
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ mpoint=$(grep "btrfs" /proc/self/mountinfo | grep " /$subvol " | grep " $partition " | cut -d ' ' -f 5)
+ if [ "$mpoint" = "/" ]; then
+ warn "specifying active root not valid, exiting"
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ if [ "$mpoint" = "$tmpmnt" ]; then
+ warn "btrfs subvol=$subvool, UUID=$UUID, already mounted on $tmpmnt **ERROR**"
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ if [ -z "$mpoint" ]; then
+ # mount the btrfs root
+ if ! mount -o subvol=$subvol -t btrfs -U $UUID "$tmpmnt" 2>/dev/null; then
+ warn "error mounting btrfs subvol=$subvol UUID=$UUID"
+ umount "$tmpmnt/boot" 2>/dev/null
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ else
+ # bind-mount
+ if ! mount -o bind "$mpoint" "$tmpmnt" 2>/dev/null; then
+ warn "error mounting btrfs bindfrom=$mpoint subvol=$subvol UUID=$UUID"
+ umount "$tmpmnt/boot" 2>/dev/null
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ fi
+ debug "mounted btrfs $partition, subvol=$subvol on $tmpmnt"
+ if [ ! -e "$tmpmnt/etc/fstab" ]; then
+ warn "btrfs subvol=$subvol not root"
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ bootmnt=$(parsefstab < "$tmpmnt/etc/fstab" | grep " /boot ") || true
+ if [ -z "$bootmnt" ]; then
+ # /boot is part of the root
+ bootpart="$partition"
+ bootsv="$subvol"
+ elif echo "$bootmnt" | cut -d ' ' -f 3 | grep -q "btrfs"; then
+ # separate btrfs /boot subvolume
+ bootsv=$(echo "$bootmnt" | cut -d ' ' -f 4 | grep "^subvol=" | sed "s/subvol=//" )
+ bootuuid=$(echo "$bootmnt" | cut -d ' ' -f 1 | grep "^UUID=" | sed "s/UUID=//" )
+ debug "mounting btrfs $tmpmnt/boot UUID=$bootuuid subvol=$bootsv"
+ bindfrom=$(check_btrfs_mounted $bootsv $bootuuid)
+ if [ -n "$bindfrom" ]; then
+ # already mounted some place
+ if ! mount -o bind $bindfrom "$tmpmnt/boot" 2>/dev/null; then
+ warn "error bind mounting btrfs boot subvol=$bootsv, from=$bindfrom"
+ umount "$tmpmnt/boot" 2>/dev/null
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ elif ! mount -o subvol=$bootsv -t btrfs -U $bootuuid "$tmpmnt/boot" 2>/dev/null; then
+ warn "error mounting btrfs boot partition subvol=$bootsv, UUID=$bootuuid"
+ umount "$tmpmnt/boot" 2>/dev/null
+ umount "$tmpmnt" 2>/dev/null
+ rmdir "$tmpmnt" 2>/dev/null
+ exit 1
+ fi
+ bootpart=$(grep " btrfs " /proc/self/mountinfo | grep " /$bootsv " | cut -d ' ' -f 10)
+ else
+ # non-btrfs partition or logical volume
+ linux_mount_boot $partition $tmpmnt
+ bootpart="${mountboot%% *}"
+ bootsv=
+ fi
+
+ test="/usr/lib/linux-boot-probes/mounted/40grub2"
+ if [ -f $test ] && [ -x $test ]; then
+ debug "running $test $partition $bootpart $tmpmnt $type $subvol $bootsv"
+ if $test "$partition" "$bootpart" "$tmpmnt" "$type" "$subvol" "$bootsv"; then
+ debug "$test succeeded"
+ fi
+ fi
+ umount "$tmpmnt/boot" 2>/dev/null || true
+ if ! umount "$tmpmnt" 2>/dev/null; then
+ warn "problem umount $tmpmnt"
+ fi
+ rmdir "$tmpmnt" 2>/dev/null || true
+
+ exit 0
+fi
+
if ! mapped="$(mapdevfs "$partition")"; then
log "Device '$partition' does not exist; skipping"
continue
@@ -22,8 +149,8 @@ fi
if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map"; then
for test in /usr/lib/linux-boot-probes/*; do
- debug "running $test"
if [ -x $test ] && [ -f $test ]; then
+ debug "running $test"
if $test "$partition"; then
debug "linux detected by $test"
break
--- a/linux-boot-probes/mounted/common/40grub2
+++ b/linux-boot-probes/mounted/common/40grub2
@@ -2,17 +2,42 @@
. /usr/share/os-prober/common.sh
set -e
+# add support for btrfs with no separate /boot
+# that is, rootsv = bootsv
partition="$1"
bootpart="$2"
mpoint="$3"
type="$4"
+rootsv="$5"
+bootsv="$6"
found_item=0
entry_result () {
+ 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" ]; then
+ # absolute path needed: prepend subvolume if $kernel isn't empty
+ kernel=${kernel:+${bsv}}${kernel}
+ # handle multiple initrd paths
+ local initrd_path=
+ for path in ${initrd}; do
+ initrd_path+="${bsv}${path} "
+ done
+ initrd="${initrd_path% }"
+ fi
+ # assumed: rootsv != bootsv if rootsv isn't ancestor of bootsv
+ [ "$partition" != "$bootpart" -o "$rootsv" != "$bootsv" ] && kernelfile="/boot${kernelfile}"
+ else
+ kernelfile=$kernel
+ fi
if [ "$ignore_item" = 0 ] && \
[ -n "$kernel" ] && \
- [ -e "$mpoint/$kernel" ]; then
+ [ -e "$mpoint/$kernelfile" ]; then
result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
found_item=1
fi
@@ -64,7 +88,7 @@ parse_grub_menu () {
ignore_item=1
fi
;;
- linux)
+ linux|linuxefi|linux16)
# Hack alert: sed off any (hdn,n) but
# assume the kernel is on the same
# partition.
@@ -73,18 +98,18 @@ 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)
+ initrd|initrdefi|initrd16)
shift
initrd=""
for initrd_path in "$@"; do
# sed hack, as above
initrd_path="$(echo "$initrd_path" | sed 's/(.*)//')"
# Initrd same.
- if [ "$partition" != "$bootpart" ]; then
+ if [ "$partition" != "$bootpart" -a "$type" != "btrfs" ]; then
initrd_path="/boot$initrd_path"
fi
if [ -z "$initrd" ]; then
--- a/os-prober
+++ b/os-prober
@@ -76,9 +76,12 @@ partitions () {
# Also detect OSes on LVM volumes (assumes LVM is active)
if type lvs >/dev/null 2>&1; then
- echo "$(LVM_SUPPRESS_FD_WARNINGS=1 log_output lvs --noheadings --separator : -o vg_name,lv_name |
+ echo "$(LVM_SUPPRESS_FD_WARNINGS=1 log_output lvs --noheadings --separator : -o vg_name,lv_name 2>/dev/null |
sed "s|-|--|g;s|^[[:space:]]*\(.*\):\(.*\)$|/dev/mapper/\1-\2|")"
fi
+
+ # now lets make sure we got all of the btrfs partitions and disks
+ blkid | grep 'TYPE="btrfs"' | cut -d ':' -f 1
}
parse_proc_swaps () {
@@ -136,6 +139,8 @@ if [ -f /proc/mdstat ] ; then
grep "^md" /proc/mdstat | cut -d: -f2- | parse_proc_mdstat >"$OS_PROBER_TMP/raided-map" || true
fi
+: >"$OS_PROBER_TMP/btrfs-vols"
+
for partition in $(partitions); do
if ! mapped="$(mapdevfs "$partition")"; then
log "Device '$partition' does not exist; skipping"
@@ -154,7 +159,26 @@ for partition in $(partitions); do
continue
fi
- if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map" ; then
+ # do btrfs processing here; both mounted and unmounted will
+ # be handled by 50mounted-tests so we can do a subvol only once.
+ type=$(blkid -o value -s TYPE $mapped || true)
+ if [ "$type" = btrfs ]; then
+ uuid=$(blkid -o value -s UUID $mapped)
+ if grep -q "^$uuid" "$OS_PROBER_TMP/btrfs-vols" ; then
+ continue
+ fi
+ debug "btrfs volume uuid=$uuid partition=$partition"
+ echo "$uuid" >>"$OS_PROBER_TMP/btrfs-vols"
+ test="/usr/lib/os-probes/50mounted-tests"
+ if [ -f "$test" ] && [ -x "$test" ]; then
+ debug "running $test on btrfs $partition"
+ if "$test" btrfs "$uuid" "$partition"; then
+ debug "os detected by $test"
+ continue
+ fi
+ fi
+
+ elif ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map" ; then
for test in /usr/lib/os-probes/*; do
if [ -f "$test" ] && [ -x "$test" ]; then
debug "running $test on $partition"
--- a/os-probes/common/50mounted-tests
+++ b/os-probes/common/50mounted-tests
@@ -14,19 +14,31 @@ do_unmount() {
rmdir "$tmpmnt" || true
}
-types="$(fs_type "$partition")"
+if [ "x$1" = xbtrfs ]; then
+ types=btrfs
+ if [ -z "$2" -o -z "$3" ]; then
+ debug "missing btrfs parameters, exiting"
+ exit 1
+ fi
+ UUID="$2"
+ BTRFSDEV="$3"
+else
+ partition="$1"
+ types="$(fs_type "$partition")" || types=NOT-DETECTED
+fi
+
if [ "$types" = NOT-DETECTED ]; then
debug "$1 type not recognised; skipping"
- exit 0
+ exit 1
elif [ "$types" = swap ]; then
debug "$1 is a swap partition; skipping"
- exit 0
+ exit 1
elif [ "$types" = crypto_LUKS ]; then
debug "$1 is a LUKS partition; skipping"
- exit 0
+ exit 1
elif [ "$types" = LVM2_member ]; then
debug "$1 is an LVM member; skipping"
- exit 0
+ exit 1
elif [ "$types" = ntfs ]; then
if type ntfs-3g >/dev/null 2>&1; then
types='ntfs-3g ntfs'
@@ -35,7 +47,7 @@ elif [ -z "$types" ]; then
if type cryptsetup >/dev/null 2>&1 && \
cryptsetup luksDump "$partition" >/dev/null 2>&1; then
debug "$1 is a LUKS partition; skipping"
- exit 0
+ exit 1
fi
for type in $(grep -v nodev /proc/filesystems); do
# hfsplus filesystems are mountable as hfs. Try hfs last so
@@ -58,6 +70,108 @@ if [ ! -d "$tmpmnt" ]; then
fi
mounted=
+
+# all btrfs processing here. Handle both unmounted and
+# mounted subvolumes.
+if [ "$types" = btrfs ]; then
+ partition="$BTRFSDEV"
+ debug "begin btrfs processing for $UUID"
+ # note that the btrfs volume must not be mounted ro
+ if mount -t btrfs -U "$UUID" "$tmpmnt" 2>/dev/null; then
+ debug "btrfs volume $UUID mounted"
+ else
+ warn "cannot mount btrfs volume $UUID, exiting"
+ rmdir "$tmpmnt" || true
+ exit 1
+ fi
+ # besides regular subvols, get ro and snapshot so thet can be excluded
+ subvols=$(btrfs subvolume list "$tmpmnt" | cut -d ' ' -f 9)
+ rosubvols=$(btrfs subvolume list -r "$tmpmnt" | cut -d ' ' -f 9)
+ sssubvols=$(btrfs subvolume list -s "$tmpmnt" | cut -d ' ' -f 14)
+ if ! umount "$tmpmnt"; then
+ warn "failed to umount btrfs volume on $tmpmnt"
+ rmdir "$tmpmnt" || true
+ exit 1
+ fi
+
+ found=
+ mounted=
+
+ mpoint="$(grep btrfs /proc/self/mountinfo | grep "$partition " | cut -d ' ' -f 5)"
+ if [ -n "$mpoint" -a "x$mpoint" = "x/" ]; then
+ debug "This is the root for the running system" #running system must be done elsewhere
+ else
+ #partition was not root of running system, so lets look for bootable subvols
+ if [ -n "$mpoint" ] ; then
+ mounted=1 #partition was already mounted,so lets not unmount it when done
+ else
+ # again, do not mount btrfs ro
+ mount -t btrfs -U "$UUID" "$tmpmnt"
+ mpoint="$tmpmnt"
+ fi
+
+ test="/usr/lib/os-probes/mounted/90linux-distro"
+ if [ -f "$test" ] && [ -x "$test" ]; then
+ debug "running subtest $test"
+ if "$test" "$partition" "$mpoint" btrfs "UUID=$UUID"; then
+ debug "os found by subtest $test on $partition"
+ found=1
+ fi
+ fi
+ if [ -z "$mounted" ]; then
+ if ! umount "$tmpmnt"; then
+ warn "failed to umount $tmpmnt"
+ fi
+ fi
+ fi
+
+ if [ -z "$subvols" ]; then
+ debug "no subvols found on btrfs volume $UUID"
+ else
+ found=
+ for subvol in $subvols; do
+ debug "begin btrfs processing for $UUID subvol=$subvol"
+ if echo "$rosubvols" | grep -q -x "$subvol"; then
+ continue
+ fi
+ if echo "$sssubvols" | grep -q -x "$subvol"; then
+ continue
+ fi
+ mounted=
+ mpoint="$(grep btrfs /proc/self/mountinfo | grep "$partition " | grep "/$subvol " | cut -d ' ' -f 5)"
+ if [ -n "$mpoint" ]; then
+ if [ "x$mpoint" = "x/" ]; then
+ continue # this is the root for the running system
+ fi
+ mounted=1
+ else
+ # again, do not mount btrfs ro
+ mount -t btrfs -o subvol="$subvol" -U "$UUID" "$tmpmnt"
+ mpoint="$tmpmnt"
+ fi
+ test="/usr/lib/os-probes/mounted/90linux-distro"
+ if [ -f "$test" ] && [ -x "$test" ]; then
+ debug "running subtest $test"
+ if "$test" "$partition" "$mpoint" btrfs "UUID=$UUID" "subvol=$subvol"; then
+ debug "os found by subtest $test on subvol $subvol"
+ found=1
+ fi
+ fi
+ if [ -z "$mounted" ]; then
+ if ! umount "$tmpmnt"; then
+ warn "failed to umount $tmpmnt"
+ fi
+ fi
+ done
+ fi
+ rmdir "$tmpmnt" || true
+ if [ "$found" ]; then
+ exit 0
+ else
+ exit 1
+ fi
+fi
+
if type grub-mount >/dev/null 2>&1 && \
type grub-probe >/dev/null 2>&1 && \
grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
--- a/os-probes/mounted/common/90linux-distro
+++ b/os-probes/mounted/common/90linux-distro
@@ -7,6 +7,8 @@ set -e
partition="$1"
dir="$2"
type="$3"
+uuid="$4"
+subvol="$5"
# This test is inaccurate, but given separate / and /boot partitions and the
# fact that only some architectures have ld-linux.so, I can't see anything
@@ -143,7 +145,11 @@ if (ls "$dir"/lib*/ld*.so* && [ -d "$dir/boot" ] || ls "$dir"/usr/lib*/ld*.so*)
fi
label="$(count_next_label "$short")"
- result "$partition:$long:$label:linux"
+ if [ "x$type" = "xbtrfs" -a "x$uuid" != "x" -a "x$subvol" != "x" ]; then
+ result "$partition:$long:$label:linux:$type:$uuid:$subvol"
+ else
+ result "$partition:$long:$label:linux"
+ fi
exit 0
else
exit 1

View File

@ -0,0 +1,24 @@
Fixes missing entries when os-prober is run in a chroot environment by falling back
to blkid if udev isn't available or if /run/udev isn't bind mounted. Modified from
https://build.opensuse.org/package/view_file/Base:System/os-prober/os-prober-05efi-blkid.patch?rev=103
Bug: https://bugs.gentoo.org/761475
https://bugzilla.opensuse.org/1076779
--- a/os-probes/mounted/x86/05efi
+++ b/os-probes/mounted/x86/05efi
@@ -46,6 +46,14 @@ if type udevinfo > /dev/null 2>&1; then
fi
eval "$(udevinfo -q property -n "$partition" | grep -E '^ID_PART_ENTRY_(TYPE|SCHEME)=')"
+
+ # udev may not work in chroot as its db may not be there, bailout that by blkid (bsc#1076779)
+ if [ -z "$ID_PART_ENTRY_TYPE" -a -z "$ID_PART_ENTRY_SCHEME" ] &&
+ type blkid > /dev/null 2>&1; then
+ debug "fallback to blkid"
+ eval "$(blkid -p -o udev "$partition" | grep -E '^(ID_PART_ENTRY_(TYPE|SCHEME))=')"
+ fi
+
debug "$partition partition scheme is $ID_PART_ENTRY_SCHEME"
debug "$partition partition type is $ID_PART_ENTRY_TYPE"

View File

@ -0,0 +1,21 @@
Fixes errors like "umount: /var/lib/os-prober/mount: target is busy."
which can appear in some corner-cases.
Bug: https://bugzilla.redhat.com/903906
--- a/common.sh
+++ b/common.sh
@@ -336,3 +336,13 @@ linux_mount_boot () {
mountboot="$bootpart $mounted"
}
+
+umount_exec=$(which umount)
+umount() {
+ if ! $umount_exec $@ 2> /dev/null; then
+ error "umount error, retrying after 1 sec"
+ sleep 1
+ $umount_exec $@
+ fi
+}
+

View File

@ -0,0 +1,17 @@
Fixes the problem of the root partition being returned instead of the boot
partition when both are already mounted somewhere.
Bug: https://bugs.debian.org/699840
https://bugzilla.redhat.com/906886
--- a/linux-boot-prober
+++ b/linux-boot-prober
@@ -167,7 +167,7 @@ else
bootpart="${mountboot%% *}"
bootmounted="${mountboot#* }"
else
- bootpart="$partition"
+ bootpart="$(grep " $mpoint/boot " "$OS_PROBER_TMP/mounted-map" | head -n1 | cut -d " " -f 4)"
bootmounted=0
fi
for test in /usr/lib/linux-boot-probes/mounted/*; do

View File

@ -0,0 +1,34 @@
For symlinks to partions in fstab, returns the partition name from fstab instead
of the name of its resolved destination, eg., for /dev/mapper/mylvmvol in fstab,
linked to /dev/dm-2, return "mylvmvol" instead of "dm-2".
Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=699839
https://bugzilla.redhat.com/show_bug.cgi?id=893472
--- a/common.sh
+++ b/common.sh
@@ -269,7 +269,7 @@ linux_mount_boot () {
if [ "$bindfrom" != "$tmpmnt/boot" ]; then
if mount --bind "$bindfrom" "$tmpmnt/boot"; then
mounted=1
- bootpart="$1"
+ bootpart="$tmppart"
else
debug "failed to bind-mount $bindfrom onto $tmpmnt/boot"
fi
@@ -277,6 +277,15 @@ linux_mount_boot () {
fi
if [ "$mounted" ]; then
:
+ elif [ -e "$tmppart" ]; then
+ bootpart="$tmppart"
+ boottomnt="$tmppart"
+ elif [ -e "$tmpmnt/$tmppart" ]; then
+ bootpart="$tmppart"
+ boottomnt="$tmpmnt/$tmppart"
+ elif [ -e "/target/$tmppart" ]; then
+ bootpart="$tmppart"
+ boottomnt="/target/$tmppart"
elif [ -e "$1" ]; then
bootpart="$1"
boottomnt="$1"