From 85c4c129084115552e41c07facad9a987cfe2b7c Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Aug 02 2019 15:28:52 +0000 Subject: import os-prober-1.74-6.el8 --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16342ab --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/os-prober_1.74.tar.xz diff --git a/.os-prober.metadata b/.os-prober.metadata new file mode 100644 index 0000000..6448a8b --- /dev/null +++ b/.os-prober.metadata @@ -0,0 +1 @@ +f7008494924ee60468bb27df8d926d7e0234edab SOURCES/os-prober_1.74.tar.xz diff --git a/SOURCES/os-prober-bootpart-name-fix.patch b/SOURCES/os-prober-bootpart-name-fix.patch new file mode 100644 index 0000000..40a909d --- /dev/null +++ b/SOURCES/os-prober-bootpart-name-fix.patch @@ -0,0 +1,29 @@ +Index: os-prober/common.sh +=================================================================== +--- os-prober.orig/common.sh ++++ os-prober/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" diff --git a/SOURCES/os-prober-btrfsfix.patch b/SOURCES/os-prober-btrfsfix.patch new file mode 100644 index 0000000..1047d24 --- /dev/null +++ b/SOURCES/os-prober-btrfsfix.patch @@ -0,0 +1,472 @@ +diff --git a/common.sh b/common.sh +index c2c5f46..8fb3c5f 100644 +--- 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' +diff --git a/linux-boot-prober b/linux-boot-prober +index e32dc84..2a60fa2 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..db5cbfd 100755 +--- a/linux-boot-probes/mounted/common/40grub2 ++++ b/linux-boot-probes/mounted/common/40grub2 +@@ -2,17 +2,30 @@ + . /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 "$partition" = "$bootpart" ]; then ++ # trim off the leading subvol ++ kernelfile=$(echo "$kernel" | cut -d '/' -f 2- | cut -d '/' -f 2-) ++ if [ "x$rootsv" != "x$bootsv" ]; then ++ kernelfile="/boot/$kernelfile" ++ fi ++ 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 8852887..482c3c2 100755 +--- 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" +diff --git a/os-probes/common/50mounted-tests b/os-probes/common/50mounted-tests +index 2951ef9..e33eb82 100755 +--- a/os-probes/common/50mounted-tests ++++ b/os-probes/common/50mounted-tests +@@ -19,19 +19,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' +@@ -40,7 +52,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 +@@ -63,6 +75,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 +diff --git a/os-probes/mounted/common/90linux-distro b/os-probes/mounted/common/90linux-distro +index badfbb1..9bc5154 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 +@@ -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 diff --git a/SOURCES/os-prober-factor-out-logger.patch b/SOURCES/os-prober-factor-out-logger.patch new file mode 100644 index 0000000..52cb7ce --- /dev/null +++ b/SOURCES/os-prober-factor-out-logger.patch @@ -0,0 +1,107 @@ +Index: os-prober/common.sh +=================================================================== +--- os-prober.orig/common.sh ++++ os-prober/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 +Index: os-prober/linux-boot-prober +=================================================================== +--- os-prober.orig/linux-boot-prober ++++ os-prober/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 +@@ -19,6 +27,7 @@ bootuuid= + + grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true + ++( ( + if [ -z "$1" ]; then + ERR=y + elif [ "$1" = btrfs -a -z "$2" ]; then +@@ -186,3 +195,5 @@ else + fi + fi + fi ++) 9>&1 | logger 1>&- # fd_logger ++) 3>&1 # fd_result +Index: os-prober/os-prober +=================================================================== +--- os-prober.orig/os-prober ++++ os-prober/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 +@@ -136,6 +143,7 @@ fi + + : >"$OS_PROBER_TMP/btrfs-vols" + ++( ( + for partition in $(partitions); do + if ! mapped="$(mapdevfs "$partition")"; then + log "Device '$partition' does not exist; skipping" +@@ -200,3 +208,5 @@ for partition in $(partitions); do + fi + fi + done ++) 9>&1 | logger 1>&- # fd_logger ++) 3>&1 # fd_result diff --git a/SOURCES/os-prober-factored-logger-efi-fix.patch b/SOURCES/os-prober-factored-logger-efi-fix.patch new file mode 100644 index 0000000..5c66fa0 --- /dev/null +++ b/SOURCES/os-prober-factored-logger-efi-fix.patch @@ -0,0 +1,16 @@ +Index: os-prober/os-probes/mounted/x86/05efi +=================================================================== +--- os-prober.orig/os-probes/mounted/x86/05efi ++++ os-prober/os-probes/mounted/x86/05efi +@@ -59,7 +59,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 diff --git a/SOURCES/os-prober-gentoo-fix.patch b/SOURCES/os-prober-gentoo-fix.patch new file mode 100644 index 0000000..8545db2 --- /dev/null +++ b/SOURCES/os-prober-gentoo-fix.patch @@ -0,0 +1,13 @@ +Index: os-prober/linux-boot-probes/mounted/common/90fallback +=================================================================== +--- os-prober.orig/linux-boot-probes/mounted/common/90fallback ++++ os-prober/linux-boot-probes/mounted/common/90fallback +@@ -33,7 +33,7 @@ for kernpat in /vmlinuz /vmlinux /boot/v + # Dracut initramfses are named differently again. + initrdname3=$(echo "$kernfile" | sed "s/vmlinu[zx]/initramfs\*/" | sed 's/$/.img/') + # And Gentoo's also +- initrdname4=$(echo "$kernfile" | sed "s/kernel/initramfs\*/") ++ initrdname4=$(echo "$kernfile" | sed "s/kernel\|vmlinu[zx]/initramfs\*/") + foundinitrd=0 + for initrd in $(eval ls "$initrdname" "$initrdname1" "$initrdname2" "$initrdname3" "$initrdname4" 2>/dev/null); do + if [ "$initrd" != "$kernfile" ] && [ -f "$initrd" ] && [ ! -L "$initrd" ]; then diff --git a/SOURCES/os-prober-grepfix.patch b/SOURCES/os-prober-grepfix.patch new file mode 100644 index 0000000..4dadd4f --- /dev/null +++ b/SOURCES/os-prober-grepfix.patch @@ -0,0 +1,13 @@ +Index: os-prober/os-probes/mounted/x86/83haiku +=================================================================== +--- os-prober.orig/os-probes/mounted/x86/83haiku ++++ os-prober/os-probes/mounted/x86/83haiku +@@ -13,7 +13,7 @@ case "$type" in + *) debug "$partition is not a BeFS partition: exiting"; exit 1 ;; + esac + +-if head -c 512 "$partition" | grep -qs "system.haiku_loader"; then ++if head -c 512 "$partition" | grep -aqs "system.haiku_loader"; then + debug "Stage 1 bootloader found" + else + debug "Stage 1 bootloader not found: exiting" diff --git a/SOURCES/os-prober-grub2-parsefix.patch b/SOURCES/os-prober-grub2-parsefix.patch new file mode 100644 index 0000000..0ef8bda --- /dev/null +++ b/SOURCES/os-prober-grub2-parsefix.patch @@ -0,0 +1,22 @@ +Index: os-prober-1.58/linux-boot-probes/mounted/common/40grub2 +=================================================================== +--- os-prober-1.58.orig/linux-boot-probes/mounted/common/40grub2 ++++ os-prober-1.58/linux-boot-probes/mounted/common/40grub2 +@@ -77,7 +77,7 @@ parse_grub_menu () { + ignore_item=1 + fi + ;; +- linux) ++ linux*) + # Hack alert: sed off any (hdn,n) but + # assume the kernel is on the same + # partition. +@@ -90,7 +90,7 @@ parse_grub_menu () { + kernel="/boot$kernel" + fi + ;; +- initrd) ++ initrd*) + initrd="$(echo "$2" | sed 's/(.*)//')" + # Initrd same. + if [ "$partition" != "$bootpart" ]; then diff --git a/SOURCES/os-prober-mdraidfix.patch b/SOURCES/os-prober-mdraidfix.patch new file mode 100644 index 0000000..33a432d --- /dev/null +++ b/SOURCES/os-prober-mdraidfix.patch @@ -0,0 +1,25 @@ +Index: os-prober/os-prober +=================================================================== +--- os-prober.orig/os-prober ++++ os-prober/os-prober +@@ -64,6 +64,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 | +@@ -123,7 +128,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 diff --git a/SOURCES/os-prober-mounted-partitions-fix.patch b/SOURCES/os-prober-mounted-partitions-fix.patch new file mode 100644 index 0000000..aecfc9f --- /dev/null +++ b/SOURCES/os-prober-mounted-partitions-fix.patch @@ -0,0 +1,26 @@ +Index: os-prober/common.sh +=================================================================== +--- os-prober.orig/common.sh ++++ os-prober/common.sh +@@ -146,7 +146,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 + } + +Index: os-prober/linux-boot-prober +=================================================================== +--- os-prober.orig/linux-boot-prober ++++ os-prober/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 diff --git a/SOURCES/os-prober-no-dummy-mach-kernel.patch b/SOURCES/os-prober-no-dummy-mach-kernel.patch new file mode 100644 index 0000000..b9e1254 --- /dev/null +++ b/SOURCES/os-prober-no-dummy-mach-kernel.patch @@ -0,0 +1,22 @@ +From f71f7eb5c492720c24033901ef8c6c420e188ff2 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 May 2012 14:47:35 -0400 +Subject: [PATCH] Don't count our dummy mach_kernel as real MacOS X. + +--- + os-probes/mounted/powerpc/20macosx | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +Index: b/os-probes/mounted/powerpc/20macosx +=================================================================== +--- 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 -aq Dummy ; then + label="$(count_next_label MacOSX)" + result "$1:Mac OS X:$label:macosx" + exit 0 diff --git a/SOURCES/os-prober-umount-fix.patch b/SOURCES/os-prober-umount-fix.patch new file mode 100644 index 0000000..6e7937c --- /dev/null +++ b/SOURCES/os-prober-umount-fix.patch @@ -0,0 +1,18 @@ +Index: os-prober/common.sh +=================================================================== +--- os-prober.orig/common.sh ++++ os-prober/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 ++} ++ diff --git a/SPECS/os-prober.spec b/SPECS/os-prober.spec new file mode 100644 index 0000000..9013c50 --- /dev/null +++ b/SPECS/os-prober.spec @@ -0,0 +1,260 @@ +Name: os-prober +Version: 1.74 +Release: 6%{?dist} +Summary: Probes disks on the system for installed operating systems + +Group: System Environment/Base +# For more information about licensing, see copyright file. +License: GPLv2+ and GPL+ +URL: http://kitenet.net/~joey/code/os-prober/ +Source0: http://ftp.us.debian.org/debian/pool/main/o/os-prober/%{name}_%{version}.tar.xz +Patch0: os-prober-no-dummy-mach-kernel.patch +# Sent upstream +Patch1: os-prober-mdraidfix.patch +Patch2: os-prober-btrfsfix.patch +Patch3: os-prober-bootpart-name-fix.patch +Patch4: os-prober-mounted-partitions-fix.patch +Patch5: os-prober-factor-out-logger.patch +# To be sent upstream +Patch6: os-prober-factored-logger-efi-fix.patch +Patch7: os-prober-umount-fix.patch +Patch8: os-prober-grub2-parsefix.patch +Patch9: os-prober-grepfix.patch +Patch10: os-prober-gentoo-fix.patch + +Requires: udev coreutils util-linux +Requires: grep /bin/sed /sbin/modprobe +Requires: device-mapper + +BuildRequires: gcc git + +%description +This package detects other OSes available on a system and outputs the results +in a generic machine-readable format. Support for new OSes and Linux +distributions can be added easily. + +%prep +%autosetup -n %{name} -S git + +find -type f -exec sed -i -e 's|usr/lib|usr/libexec|g' {} \; +sed -i -e 's|grub-probe|grub2-probe|g' os-probes/common/50mounted-tests \ + linux-boot-probes/common/50mounted-tests + +%build +%make_build CFLAGS="%{optflags}" + +%install +install -m 0755 -d %{buildroot}%{_bindir} +install -m 0755 -d %{buildroot}%{_var}/lib/%{name} + +install -m 0755 -p os-prober linux-boot-prober %{buildroot}%{_bindir} +install -m 0755 -Dp newns %{buildroot}%{_libexecdir}/os-prober/newns +install -m 0644 -Dp common.sh %{buildroot}%{_datadir}/%{name}/common.sh + +%ifarch m68k +ARCH=m68k +%endif +%ifarch ppc ppc64 +ARCH=powerpc +%endif +%ifarch sparc sparc64 +ARCH=sparc +%endif +%ifarch %{ix86} x86_64 +ARCH=x86 +%endif + +for probes in os-probes os-probes/mounted os-probes/init \ + linux-boot-probes linux-boot-probes/mounted; do + install -m 755 -d %{buildroot}%{_libexecdir}/$probes + cp -a $probes/common/* %{buildroot}%{_libexecdir}/$probes + if [ -e "$probes/$ARCH" ]; then + cp -a $probes/$ARCH/* %{buildroot}%{_libexecdir}/$probes + fi +done +if [ "$ARCH" = x86 ]; then + install -m 755 -p os-probes/mounted/powerpc/20macosx \ + %{buildroot}%{_libexecdir}/os-probes/mounted +fi + +%files +%doc README TODO debian/changelog +%license debian/copyright +%{_bindir}/* +%{_libexecdir}/* +%{_datadir}/%{name} +%{_var}/lib/%{name} + +%changelog +* Sun Feb 18 2018 Hedayat Vatankhah - 1.74-6 +- Add gcc build dependency + +* Thu Feb 08 2018 Fedora Release Engineering - 1.74-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild + +* Fri Dec 29 2017 Hedayat Vatankhah - 1.74-4 +- Fix a path problem in btrfsfix.patch, fixes #1529616 + +* Thu Aug 03 2017 Fedora Release Engineering - 1.74-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild + +* Thu Jul 27 2017 Fedora Release Engineering - 1.74-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild + +* Mon Mar 27 2017 Neal Gompa - 1.74-1 +- Update to upstream version 1.74 +- Drop merged patches +- Rediff remaining patches +- Move newns to /usr/libexec/os-prober (debuginfo generation works) +- Mark copyright file as license file + +* Sat Feb 11 2017 Fedora Release Engineering - 1.71-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild + +* Fri Mar 04 2016 Hedayat Vatankhah - 1.71-1 +- Update to upstream version 1.71 +- Use git based autosetup for applying patches + +* Mon Feb 15 2016 Peter Jones - 1.70-3 +- Don't keep backups with 'patch -b'; they wind up in the ouput package. + +* Thu Feb 04 2016 Fedora Release Engineering - 1.70-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild + +* Fri Nov 13 2015 Hedayat Vatankhah - 1.70-1 +- Update to upstream version 1.70, fixes #1275641 +- Fix bug #1236358 - os-prober duplicates grub entries for read/write btrfs + subvolumes, thanks to Helmut Horvath +- Fix bug #1236649 - os-prober does not detect os on btrfs partition without + any subvolume + +* Tue Oct 20 2015 Hedayat Vatankhah - 1.68-1 +- Update to upstream version 1.68, bug #1267779 +- Support a case where a kernel named vmlinuz/x is used under Gentoo, bug #1223237 + +* Thu Jun 18 2015 Fedora Release Engineering - 1.65-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild + +* Tue Dec 23 2014 Hedayat Vatankhah - 1.65-2 +- Fix using grep for searching binary files, fixes #1172405. Thanks Paul Eggert + for initial patch fixing grep usage in 83haiku + +* Sun Dec 07 2014 Hedayat Vatankhah - 1.65-1 +- Using latest upstream version tarball to be consistent with upstream + versioning + +* Sat Oct 25 2014 Hedayat Vatankhah - 1.58-11 +- Fix parsing grub2's initrd/linux variations, rhbz #1108344 + +* Mon Sep 08 2014 Peter Jones - 1.58-10 +- Make os-prober output include partitions for UEFI chainloads. + Resolves: rhbz#873207 + +* Sun Aug 17 2014 Fedora Release Engineering - 1.58-9 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild + +* Sun Jul 06 2014 Hedayat Vatankhah - 1.58-8 +- Fix bug in counting LVM LVs which their name contains 'btrfs' as btrfs volumes + +* Sat Jun 07 2014 Fedora Release Engineering - 1.58-7 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild + +* Tue May 06 2014 Hedayat Vatankhah - 1.58-6 +- Fix separate /usr partitions for usrmove distros (bug #1044760) +- Fix umount error when directory is temporarily busy (bug #903906) + +* Thu Apr 24 2014 Hedayat Vatankhah - 1.58-5 +- Fixed bug #982009: fix btrfs support +- Suppress some more debug messages when debug messages are disabled + +* Sat Aug 03 2013 Fedora Release Engineering - 1.58-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild + +* Tue Jul 02 2013 Adam Williamson - 1.58-3 +- revert factored-logger-efi-fix.patch until grub2 is updated to match + +* Tue Jun 18 2013 Hedayat Vatankhah - 1.58-2 +- Fix a bug in EFI detection because of redirecting result output + +* Sun May 05 2013 Hedayat Vatankhah - 1.58-1 +- Update to upstream version 1.58, with UEFI support + +* Sat Feb 02 2013 Hedayat Vatankhah - 1.57-2 +- Fix a bug in recent btrfs patch when an extended partition is examined. + (H.J. Lu) (bug #906847) +- Fix naming of /boot partitions according to their fstab entry (bug #893472) +- Don't generate .btrfsfix files which will be included in final rpm +- Fix wrong boot partition set by linux-boot-prober when / and /boot are + mounted (bug #906886) +- Factor out 'logger', so that it is run once and logs are piped to it (John + Reiser) (bug #875356) + +* Tue Jan 22 2013 Hedayat Vatankhah - 1.57-1 +- Update to 1.57 (#890409) +- Use shell string processing rather than 'basename' (#875356) +- Make it possible to disable logging debug messages by assigning a value to + OS_PROBER_DISABLE_DEBUG environment variable (Gene Czarcinski) (#893997). +- Detect multi btrfs pools/volumes (Gene Czarcinski) (#888341) + +* Thu Oct 11 2012 Hedayat Vatankhah - 1.56-1 +- Update to 1.56 with a bug fix and applied one of my patches + +* Mon Aug 27 2012 Hedayat Vatankhah - 1.55-1 +- Update to new upstream version: 1.55 + +* Fri Jul 20 2012 Fedora Release Engineering - 1.53-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild + +* Sat Jun 02 2012 Hedayat Vatankhah - 1.53-3 +- Consider usrmoved distribtions in fallback linux detector (bug #826754) +- Remove patch backup files from final rpm package (by not creating a backup!) + +* Fri May 25 2012 Hedayat Vatankhah - 1.53-2 +- Add support for OSes installed on Linux mdraid partitions, bug #752402 +- Add Fedora's grub2 config path, fixes generating menu entries for other + installed Fedora's +- Fixed bug in parsing yaboot.conf: accept spaces around '=' for append, + bug #825041 + +* Fri May 11 2012 Hedayat Vatankhah - 1.53-1 +- Updated to 1.53 for a bugfix +- Fixed directory name in upstream tarbal + +* Thu May 10 2012 Peter Jones - 1.52-3 +- Don't detect our Mac boot blocks as OS X. + Resolves: rhbz#811412 + +* Sun Apr 29 2012 Hedayat Vatankhah - 1.52-2 +- use correct directory name for setup + +* Sun Apr 29 2012 Hedayat Vatankhah - 1.52-1 +- Updated to 1.52, supports win 8 + +* Wed Mar 28 2012 Hedayat Vatankhah - 1.51-1 +- Update to latest upstream version, 1.51 + +* Sat Jan 21 2012 Hedayat Vatankhah - 1.48-3 +- Remove dmraid and lvm2 dependency. bug #770393 + +* Fri Jan 13 2012 Fedora Release Engineering - 1.48-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild + +* Mon Jul 25 2011 Hedayat Vatankhah - 1.48-1 +- Updated to 1.48 release + +* Thu May 19 2011 Hedayat Vatankhah - 1.47-1 +- Updated to the new upstream version 1.47 + +* Wed May 04 2011 Hedayat Vatankhah - 1.46-2 +- Removed obsolete parts (build tag, defattr, etc) +- Added a patch to move newns outside of os-prober subdirectory +- Added required utilities as package requires + +* Sat Apr 30 2011 Hedayat Vatankhah - 1.46-1 +- Updated to 1.46 release + +* Tue Feb 22 2011 Hedayat Vatankhah - 1.42-2 +- Remove executable permission from common.sh + +* Thu Feb 17 2011 Hedayat Vatankhah - 1.42-1 +- Initial version