From e8c52d9c024523c8180764ec1e5d386fa9e12cbc Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Nov 03 2016 05:46:49 +0000 Subject: import os-prober-1.58-9.el7 --- diff --git a/SOURCES/0001-Change-filepath-to-newns.patch b/SOURCES/0001-Change-filepath-to-newns.patch new file mode 100644 index 0000000..28d52f8 --- /dev/null +++ b/SOURCES/0001-Change-filepath-to-newns.patch @@ -0,0 +1,24 @@ +From b8706e5dee8bada1390363cf9c43af61b2288425 Mon Sep 17 00:00:00 2001 +From: Hedayat Vatankhah +Date: Thu, 5 May 2011 23:33:30 +0430 +Subject: [PATCH 01/18] Change filepath to newns + +Move newns to a location outside the os-prober directory. +--- + common.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/common.sh b/common.sh +index 30e245e..f83eb0d 100644 +--- a/common.sh ++++ b/common.sh +@@ -1,5 +1,5 @@ + newns () { +- [ "$OS_PROBER_NEWNS" ] || exec /usr/lib/os-prober/newns "$0" "$@" ++ [ "$OS_PROBER_NEWNS" ] || exec /usr/lib/newns "$0" "$@" + } + + cleanup_tmpdir=false +-- +2.5.5 + diff --git a/SOURCES/0002-Don-t-count-dummy-mach_kernel-as-MacOS-X-811412.patch b/SOURCES/0002-Don-t-count-dummy-mach_kernel-as-MacOS-X-811412.patch new file mode 100644 index 0000000..10fc99c --- /dev/null +++ b/SOURCES/0002-Don-t-count-dummy-mach_kernel-as-MacOS-X-811412.patch @@ -0,0 +1,26 @@ +From a523db148d1af573614f92f3284068ef08b2c5b6 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 May 2012 14:47:35 -0400 +Subject: [PATCH 02/18] Don't count dummy mach_kernel as MacOS X (#811412) + +Resolves: rhbz#811412 +--- + os-probes/mounted/powerpc/20macosx | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/os-probes/mounted/powerpc/20macosx b/os-probes/mounted/powerpc/20macosx +index dd4207f..16d9da6 100755 +--- a/os-probes/mounted/powerpc/20macosx ++++ b/os-probes/mounted/powerpc/20macosx +@@ -21,7 +21,7 @@ esac + # but I don't think it exists on Mac OS <= 9, and it's XML so parsing in + # shell will be nasty. + +-if [ -e "$2/mach_kernel" ]; then ++if [ -e "$2/mach_kernel" ] && ! dd if="$2/mach_kernel" count=1 bs=5 2>/dev/null | grep -q Dummy ; then + label="$(count_next_label MacOSX)" + result "$1:Mac OS X:$label:macosx" + exit 0 +-- +2.5.5 + diff --git a/SOURCES/0003-Detect-OS-installed-to-mdraid-partition-752402.patch b/SOURCES/0003-Detect-OS-installed-to-mdraid-partition-752402.patch new file mode 100644 index 0000000..aebfda3 --- /dev/null +++ b/SOURCES/0003-Detect-OS-installed-to-mdraid-partition-752402.patch @@ -0,0 +1,40 @@ +From e448a5baca1bb9bcb36cdc2a73de8d7edb3e96f3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Pavel=20Lis=C3=BD?= +Date: Sat, 5 May 2012 14:00:01 +0430 +Subject: [PATCH 03/18] Detect OS installed to mdraid partition (#752402) + +Add ability to find operating systems installed on mdraid partitions. + +Resolves: rhbz#752402 +--- + os-prober | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/os-prober b/os-prober +index 2a08736..99ede8e 100755 +--- a/os-prober ++++ b/os-prober +@@ -57,6 +57,11 @@ partitions () { + exit 0 + fi + ++ # Add MD RAID devices ++ if [ -f /proc/mdstat ] ; then ++ awk '/^md/ {printf "/dev/"$1"\n"}' /proc/mdstat ++ fi ++ + # 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 | +@@ -116,7 +121,7 @@ if [ -f /proc/swaps ]; then + fi + : >"$OS_PROBER_TMP/raided-map" + if [ -f /proc/mdstat ] ; then +- grep "^md" /proc/mdstat | parse_proc_mdstat >"$OS_PROBER_TMP/raided-map" || true ++ grep "^md" /proc/mdstat | cut -d: -f2- | parse_proc_mdstat >"$OS_PROBER_TMP/raided-map" || true + fi + + for partition in $(partitions); do +-- +2.5.5 + diff --git a/SOURCES/0004-Yaboot-allows-spaces-in-append-825041.patch b/SOURCES/0004-Yaboot-allows-spaces-in-append-825041.patch new file mode 100644 index 0000000..894c08f --- /dev/null +++ b/SOURCES/0004-Yaboot-allows-spaces-in-append-825041.patch @@ -0,0 +1,32 @@ +From 23fdf30de70d22ce737e66fbf63cc2365339dc1a Mon Sep 17 00:00:00 2001 +From: IBM Bug Proxy +Date: Fri, 25 May 2012 16:24:42 +0430 +Subject: [PATCH 04/18] Yaboot allows spaces in append (#825041) + +Yaboot configuration files may contain append statements with a space +before and after the assignment operator. Update os-prober to be able to +parse these files successfully. + +Resolves: rhbz#825041 +--- + linux-boot-probes/mounted/powerpc/40yaboot | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/linux-boot-probes/mounted/powerpc/40yaboot b/linux-boot-probes/mounted/powerpc/40yaboot +index 26d8a16..cbb87da 100755 +--- a/linux-boot-probes/mounted/powerpc/40yaboot ++++ b/linux-boot-probes/mounted/powerpc/40yaboot +@@ -74,8 +74,8 @@ parse_yaboot_conf () { + kernel="$(dequote "$2")" + ;; + append) +- shift 1 +- parameters="$(dequote "${line#append=}")" ++ cleanappend=`printf %s "$line" | sed -E 's/append(\s)*=(\s)*//'` ++ parameters="$(dequote "$cleanappend")" + ;; + initrd) + initrd="$(dequote "$2")" +-- +2.5.5 + diff --git a/SOURCES/0005-Detect-ld.so-after-usr-move-826754.patch b/SOURCES/0005-Detect-ld.so-after-usr-move-826754.patch new file mode 100644 index 0000000..8e6e4c5 --- /dev/null +++ b/SOURCES/0005-Detect-ld.so-after-usr-move-826754.patch @@ -0,0 +1,30 @@ +From f9e0053eab8ed2d270c080f2d346fe5c84748f23 Mon Sep 17 00:00:00 2001 +From: Hedayat Vatankhah +Date: Sat, 2 Jun 2012 20:24:31 +0430 +Subject: [PATCH 05/18] Detect ld.so after usr move (#826754) + +Handle ld.so path changing from /lib to /usr/lib. + +REBASE CONFLICT + +Resolves: rhbz#826754 +--- + os-probes/mounted/common/90linux-distro | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/os-probes/mounted/common/90linux-distro b/os-probes/mounted/common/90linux-distro +index 6678f22..583a9ec 100755 +--- a/os-probes/mounted/common/90linux-distro ++++ b/os-probes/mounted/common/90linux-distro +@@ -17,7 +17,7 @@ type="$3" + # symlinks we need to also check in $dir/usr/lib* for distributions that + # moved /lib* to /usr and only left symlinks behind. + # TODO: look for ld-linux.so on arches that have it +-if (ls "$dir"/lib*/ld*.so* || ls "$dir"/usr/lib*/ld*.so*) >/dev/null 2>/dev/null; then ++if (ls "$dir"/lib*/ld*.so* && [ -d "$dir/boot" ] || ls "$dir"/usr/lib*/ld*.so*) >/dev/null 2>/dev/null; then + if [ -e "$dir/etc/debian_version" ]; then + short="Debian" + long="$(printf "Debian GNU/Linux (%s)\n" "$(cat "$dir/etc/debian_version")")" +-- +2.5.5 + diff --git a/SOURCES/0006-Use-shell-processing-instead-of-basename-875356.patch b/SOURCES/0006-Use-shell-processing-instead-of-basename-875356.patch new file mode 100644 index 0000000..d00c7f9 --- /dev/null +++ b/SOURCES/0006-Use-shell-processing-instead-of-basename-875356.patch @@ -0,0 +1,43 @@ +From f17c272d769a43490eec780424f5971f87acdc06 Mon Sep 17 00:00:00 2001 +From: John Reiser +Date: Thu, 31 Jan 2013 23:58:53 +0330 +Subject: [PATCH 06/18] Use shell processing instead of basename (#875356) + +Systems with many partitions bog down os-prober. Remove the call to +basename and use shell substitution instead. + +Resolves: rhbz#875356 +--- + common.sh | 2 +- + linux-boot-probes/mounted/powerpc/40yaboot | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/common.sh b/common.sh +index f83eb0d..b9b3951 100644 +--- a/common.sh ++++ b/common.sh +@@ -57,7 +57,7 @@ progname= + cache_progname() { + case $progname in + '') +- progname="$(basename "$0")" ++ progname="${0##*/}" + ;; + esac + } +diff --git a/linux-boot-probes/mounted/powerpc/40yaboot b/linux-boot-probes/mounted/powerpc/40yaboot +index cbb87da..b060b18 100755 +--- a/linux-boot-probes/mounted/powerpc/40yaboot ++++ b/linux-boot-probes/mounted/powerpc/40yaboot +@@ -27,7 +27,7 @@ recordstanza () { + fi + + if [ -z "$title" ]; then +- title="$(basename "$kernel")" ++ title="${kernel##*/}" + fi + if [ "$read_only" ]; then + parameters="ro $parameters" +-- +2.5.5 + diff --git a/SOURCES/0007-Add-option-for-less-logging-893997.patch b/SOURCES/0007-Add-option-for-less-logging-893997.patch new file mode 100644 index 0000000..cb52c4e --- /dev/null +++ b/SOURCES/0007-Add-option-for-less-logging-893997.patch @@ -0,0 +1,31 @@ +From e4b8dd8350ae928cad07ac31fd4844ef794db543 Mon Sep 17 00:00:00 2001 +From: Gene Czarcinski +Date: Thu, 31 Jan 2013 23:58:53 +0330 +Subject: [PATCH 07/18] Add option for less logging (#893997) + +Syslog receives many debug messages from os-prober. Added environment +variable OS_PROBER_DISABLE_DEBUG allowing them to be turned off. + +Resolves: rhbz#893997 +--- + common.sh | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/common.sh b/common.sh +index b9b3951..19ef90a 100644 +--- a/common.sh ++++ b/common.sh +@@ -76,7 +76,9 @@ warn() { + } + + debug() { +- log "debug: $@" ++ if [ -z "$OS_PROBER_DISABLE_DEBUG" ]; then ++ log "debug: $@" ++ fi + } + + result () { +-- +2.5.5 + diff --git a/SOURCES/0008-Improve-btrfs-detection-support-888341.patch b/SOURCES/0008-Improve-btrfs-detection-support-888341.patch new file mode 100644 index 0000000..7bad4c8 --- /dev/null +++ b/SOURCES/0008-Improve-btrfs-detection-support-888341.patch @@ -0,0 +1,486 @@ +From 916d8338b56b514b8f0ef72530a627fa28463140 Mon Sep 17 00:00:00 2001 +From: Gene Czarcinski +Date: Thu, 31 Jan 2013 23:58:53 +0330 +Subject: [PATCH 08/18] Improve btrfs detection support (#888341) + +Enables os-prober to detect multiple installations that live in separate +btrfs storage pools. + +Resolves: rhbz#888341 +--- + README.btrfs | 15 ++++ + common.sh | 13 ++- + linux-boot-prober | 133 ++++++++++++++++++++++++++++++- + linux-boot-probes/mounted/common/40grub2 | 12 ++- + os-prober | 28 ++++++- + os-probes/common/50mounted-tests | 98 +++++++++++++++++++++-- + os-probes/mounted/common/90linux-distro | 8 +- + 7 files changed, 293 insertions(+), 14 deletions(-) + create mode 100644 README.btrfs + +diff --git a/README.btrfs b/README.btrfs +new file mode 100644 +index 0000000..f9b4d45 +--- /dev/null ++++ b/README.btrfs +@@ -0,0 +1,15 @@ ++BTRFS is a new filesystem which combines the filesystem with logical volume ++management (subvolumes). For further information, see: ++ https://btrfs.wiki.kernel.org/index.php/Main_Page ++ https://btrfs.wiki.kernel.org/index.php/FAQ ++ ++In order to support BTRFS, a number of changes were necessary to os-prober, ++os-probes/common/50mounted-tests, os-probes/mounted/common/90linux-distro, ++linux-boot-prober, and linux-boot-probes/common/50mounted-tests. ++ ++The biggest impact will be to grub2 where there is additional information ++output by os-prober and where, if a BTRFS subvolume is being used for root, ++the parameters for linux-boot-prober have changed. ++ ++Sun 30 Dec 2012 11:49:52 AM EST Gene Czarcinski ++ +diff --git a/common.sh b/common.sh +index 19ef90a..85d13f0 100644 +--- a/common.sh ++++ b/common.sh +@@ -127,6 +127,7 @@ parse_proc_mounts () { + done + } + ++# add forth parameter to pickup btrfs subvol info + parsefstab () { + while read -r line; do + case "$line" in +@@ -137,12 +138,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' +diff --git a/linux-boot-prober b/linux-boot-prober +index e32dc84..505c2fd 100755 +--- 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 +diff --git a/linux-boot-probes/mounted/common/40grub2 b/linux-boot-probes/mounted/common/40grub2 +index 885614e..11ffa1b 100755 +--- a/linux-boot-probes/mounted/common/40grub2 ++++ b/linux-boot-probes/mounted/common/40grub2 +@@ -2,17 +2,27 @@ + . /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" -a "$rootsv" = "$bootsv" ]; then ++ # trim off the leading subvol ++ kernelfile=$(echo "$kernel" | cut -d '/' -f 2- | cut -d '/' -f 2-) ++ 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 +diff --git a/os-prober b/os-prober +index 99ede8e..ca8f5ab 100755 +--- a/os-prober ++++ b/os-prober +@@ -64,9 +64,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 btrfs | cut -d ':' -f 1 + } + + parse_proc_swaps () { +@@ -124,6 +127,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" +@@ -142,7 +147,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) ++ 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" +diff --git a/os-probes/common/50mounted-tests b/os-probes/common/50mounted-tests +index 561163b..751999a 100755 +--- a/os-probes/common/50mounted-tests ++++ b/os-probes/common/50mounted-tests +@@ -1,20 +1,36 @@ + #!/bin/sh + # Sub-tests that require a mounted partition. + set -e +-partition="$1" + + . /usr/share/os-prober/common.sh + +-types="$(fs_type "$partition")" || types=NOT-DETECTED ++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 [ "x$types" = "x" ]; then ++ exit 1 ++elif [ "$types" = LVM2_member ]; then ++ debug "skipping LVM2 Volume Group on $partition" ++ 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" = ntfs ]; then + if type ntfs-3g >/dev/null 2>&1; then + types='ntfs-3g ntfs' +@@ -23,7 +39,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 +@@ -46,6 +62,76 @@ 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 9) ++ if ! umount "$tmpmnt"; then ++ warn "failed to umount btrfs volume on $tmpmnt" ++ rmdir "$tmpmnt" || true ++ exit 1 ++ fi ++ if [ -z "$subvols" ]; then ++ debug "no subvols found on btrfs volume $UUID" ++ exit 1 ++ fi ++ 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 ++ 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 +diff --git a/os-probes/mounted/common/90linux-distro b/os-probes/mounted/common/90linux-distro +index 583a9ec..6b03c7a 100755 +--- 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 +@@ -131,7 +133,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 +-- +2.5.5 + diff --git a/SOURCES/0009-Support-detection-on-btrfs-software-raid-906847.patch b/SOURCES/0009-Support-detection-on-btrfs-software-raid-906847.patch new file mode 100644 index 0000000..573cf94 --- /dev/null +++ b/SOURCES/0009-Support-detection-on-btrfs-software-raid-906847.patch @@ -0,0 +1,29 @@ +From aadaae9305a96da301e1466dbe93b85d7e89b2f9 Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Tue, 5 Feb 2013 21:47:40 +0330 +Subject: [PATCH 09/18] Support detection on btrfs software raid (#906847) + +Update btrfs support to include detecting systems where the btrfs +filesystem sits on top of software raid. + +Resolves: rhbz#906847 +--- + os-prober | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/os-prober b/os-prober +index ca8f5ab..f5052af 100755 +--- a/os-prober ++++ b/os-prober +@@ -149,7 +149,7 @@ for partition in $(partitions); do + + # 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) ++ 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 +-- +2.5.5 + diff --git a/SOURCES/0010-Name-lvm-boot-partitions-by-fstab-entry-893472.patch b/SOURCES/0010-Name-lvm-boot-partitions-by-fstab-entry-893472.patch new file mode 100644 index 0000000..4b67c98 --- /dev/null +++ b/SOURCES/0010-Name-lvm-boot-partitions-by-fstab-entry-893472.patch @@ -0,0 +1,45 @@ +From 163af6741ad259dc1a92ffcca2f563d0ea86bb44 Mon Sep 17 00:00:00 2001 +From: Gene Czarcinski +Date: Tue, 5 Feb 2013 21:47:40 +0330 +Subject: [PATCH 10/18] Name lvm boot partitions by fstab entry(#893472) + +Recognize boot partitions on separate logical volumes and name them +using their fstab entries. + +Resolves: rhbz#893472 +--- + common.sh | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/common.sh b/common.sh +index 85d13f0..52b0d2b 100644 +--- a/common.sh ++++ b/common.sh +@@ -246,7 +246,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 +@@ -254,6 +254,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" +-- +2.5.5 + diff --git a/SOURCES/0011-Set-correct-boot-partition-906886.patch b/SOURCES/0011-Set-correct-boot-partition-906886.patch new file mode 100644 index 0000000..a48b238 --- /dev/null +++ b/SOURCES/0011-Set-correct-boot-partition-906886.patch @@ -0,0 +1,43 @@ +From f21658a98e0e0456c0dfb6852cb4bbdda9298647 Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Tue, 5 Feb 2013 21:47:40 +0330 +Subject: [PATCH 11/18] Set correct boot partition (#906886) + +If the boot and root are mounted then os-prober was selecting +the wrong boot partition. + +Resolves: rhbz#906886 +--- + common.sh | 2 +- + linux-boot-prober | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/common.sh b/common.sh +index 52b0d2b..1dbf7a3 100644 +--- a/common.sh ++++ b/common.sh +@@ -123,7 +123,7 @@ parse_proc_mounts () { + set -f + set -- $line + set +f +- printf '%s %s %s\n' "$(mapdevfs "$1")" "$2" "$3" ++ printf '%s %s %s %s\n' "$(mapdevfs "$1")" "$2" "$3" "$1" + done + } + +diff --git a/linux-boot-prober b/linux-boot-prober +index 505c2fd..57bf245 100755 +--- 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 +-- +2.5.5 + diff --git a/SOURCES/0012-Factor-out-unnecessary-logger-calls-875356.patch b/SOURCES/0012-Factor-out-unnecessary-logger-calls-875356.patch new file mode 100644 index 0000000..3a4b2e4 --- /dev/null +++ b/SOURCES/0012-Factor-out-unnecessary-logger-calls-875356.patch @@ -0,0 +1,126 @@ +From e314c1fc4cbdf8d7172fb6f8b87b127b21dd26c0 Mon Sep 17 00:00:00 2001 +From: John Reiser +Date: Tue, 5 Feb 2013 21:47:40 +0330 +Subject: [PATCH 12/18] Factor out unnecessary logger calls (#875356) + +Numerous invocations of logger bogged down os-prober on system with +large numbers of partitions. Refactored to reduce the total number of +unique invocations to increase speed. + +Resolves: rhbz#875356 +--- + common.sh | 24 ++++++++++++++++-------- + linux-boot-prober | 11 +++++++++++ + os-prober | 12 +++++++++++- + 3 files changed, 38 insertions(+), 9 deletions(-) + +diff --git a/common.sh b/common.sh +index 1dbf7a3..7fcae5a 100644 +--- a/common.sh ++++ b/common.sh +@@ -62,10 +62,14 @@ cache_progname() { + esac + } + +-log() { +- cache_progname +- logger -t "$progname" "$@" +-} ++# fd_logger: bind value now, possibly after assigning default. ++eval ' ++ log() { ++ cache_progname ++ echo "$progname: $@" 1>&'${fd_logger:=9}' ++ } ++' ++export fd_logger # so subshells inherit current value by default + + error() { + log "error: $@" +@@ -81,10 +85,14 @@ debug() { + fi + } + +-result () { +- log "result:" "$@" +- echo "$@" +-} ++# fd_result: bind value now, possibly after assigning default. ++eval ' ++ result() { ++ log "result:" "$@" ++ echo "$@" 1>&'${fd_result:=1}' ++ } ++' ++export fd_result # so subshells inherit current value by default + + # shim to make it easier to use os-prober outside d-i + if ! type mapdevfs >/dev/null 2>&1; then +diff --git a/linux-boot-prober b/linux-boot-prober +index 57bf245..3b89750 100755 +--- a/linux-boot-prober ++++ b/linux-boot-prober +@@ -1,4 +1,12 @@ + #!/bin/sh ++ ++# dash shell does not have "{varname}>&1" feature that bash shell has ++# for auto-assignment of new filedescriptors. ++# It is cumbersome to write the 'eval' to use our own variables in redirections. ++# Therefore use fixed numbers. ++export fd_result=3 # file descriptor for external results ++export fd_logger=9 # file descriptor for input to logger ++ + . /usr/share/os-prober/common.sh + + set -e +@@ -147,6 +155,7 @@ if ! mapped="$(mapdevfs "$partition")"; then + continue + fi + ++( ( + if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map"; then + for test in /usr/lib/linux-boot-probes/*; do + if [ -x $test ] && [ -f $test ]; then +@@ -186,3 +195,5 @@ else + fi + fi + fi ++) 9>&1 | logger 1>&- # fd_logger ++) 3>&1 # fd_result +diff --git a/os-prober b/os-prober +index f5052af..4b371d6 100755 +--- a/os-prober ++++ b/os-prober +@@ -1,7 +1,14 @@ + #!/bin/sh + set -e + +-. /usr/share/os-prober/common.sh ++# dash shell does not have "{varname}>&1" feature that bash shell has ++# for auto-assignment of new filedescriptors. ++# It is cumbersome to write the 'eval' to use our own variables in redirections. ++# Therefore use fixed numbers. ++export fd_result=3 # file descriptor for external results ++export fd_logger=9 # file descriptor for input to logger ++ ++ . /usr/share/os-prober/common.sh + + newns "$@" + require_tmpdir +@@ -129,6 +136,7 @@ fi + + : >"$OS_PROBER_TMP/btrfs-vols" + ++( ( + for partition in $(partitions); do + if ! mapped="$(mapdevfs "$partition")"; then + log "Device '$partition' does not exist; skipping" +@@ -193,3 +201,5 @@ for partition in $(partitions); do + fi + fi + done ++) 9>&1 | logger 1>&- # fd_logger ++) 3>&1 # fd_result +-- +2.5.5 + diff --git a/SOURCES/0013-Issue-with-EFI-detection-in-logger-873207.patch b/SOURCES/0013-Issue-with-EFI-detection-in-logger-873207.patch new file mode 100644 index 0000000..5914226 --- /dev/null +++ b/SOURCES/0013-Issue-with-EFI-detection-in-logger-873207.patch @@ -0,0 +1,32 @@ +From 2ee8f66a5d1b25f9d037b44456e006a9972bb190 Mon Sep 17 00:00:00 2001 +From: Hedayat Vatankhah +Date: Wed, 19 Jun 2013 01:44:55 +0430 +Subject: [PATCH 13/18] Issue with EFI detection in logger (#873207) + +Fixed a bug introduced with the logger refactoring that caused EFI +detection to fail. + +Resolves: rhbz#873207 +--- + os-probes/mounted/x86/05efi | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/os-probes/mounted/x86/05efi b/os-probes/mounted/x86/05efi +index 1e506fc..8a6288b 100755 +--- a/os-probes/mounted/x86/05efi ++++ b/os-probes/mounted/x86/05efi +@@ -58,7 +58,11 @@ ret=1 + for test in /usr/lib/os-probes/mounted/efi/*; do + debug "running subtest $test" + if [ -f "$test" ] && [ -x "$test" ]; then ++ # we need results of subtest in stdout ++ orig_fd_res=$fd_result ++ export fd_result=1 + entry=$("$test" "$mpoint/$efi") ++ export fd_result=$orig_fd_res + if [ -n "$entry" ]; then + debug "bootloader $entry found by subtest $test" + ret=0 +-- +2.5.5 + diff --git a/SOURCES/0014-Man-pages-missing-948848.patch b/SOURCES/0014-Man-pages-missing-948848.patch new file mode 100644 index 0000000..5e07998 --- /dev/null +++ b/SOURCES/0014-Man-pages-missing-948848.patch @@ -0,0 +1,81 @@ +From 5ba6fa3dd7d3065c12a26e217760ae52a67a277e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jan 2014 16:01:05 -0500 +Subject: [PATCH 14/18] Man pages missing (#948848) + +Added man pages for os-prober and linux-boot-prober. + +Resolves: rhbz#948848 +--- + linux-boot-prober.1 | 27 +++++++++++++++++++++++++++ + os-prober.1 | 24 ++++++++++++++++++++++++ + 2 files changed, 51 insertions(+) + create mode 100644 linux-boot-prober.1 + create mode 100644 os-prober.1 + +diff --git a/linux-boot-prober.1 b/linux-boot-prober.1 +new file mode 100644 +index 0000000..4818c85 +--- /dev/null ++++ b/linux-boot-prober.1 +@@ -0,0 +1,27 @@ ++.TH linux-boot-prober 1 "20 Jan 2014" "linux-boot-prober" ++.SH "NAME" ++linux-boot-prober \(em Determine boot characteristics of a specified device. ++.SH "SYNOPSIS" ++.B linux-boot-prober ++.I ++.SH "DESCRIPTION" ++.PP ++The \fBlinux-boot-prober\fR utility will try to work out how to boot the ++linux root partition specified by \fI\fR. If successful, it ++will outoput one or more lines of the form: ++ ++::