Re: linux-boot-prober (os-prober)
Ok, here's the patch. I haven't done this before, so tell me if i've
done something wrong(or even right, for that matter).
Thanks a lot
On 12/18/06, Joey Hess <joeyh@debian.org> wrote:
The Abattoir wrote:
> I'm working on something where it'd be useful to detect existing
> (linux) operating systems using os-prober/linux-boot-prober. It looks
> like linux-boot-prober unmounts a partition( when --mounted is used)
> and remounts them. Is there a reason why it needs to remount a
> partition under '/var/lib/os-prober/mount' instead of detecting where
> the partition is mounted currently and run the tests from there?(hence
> avoiding the unmounting)
I'd be very happy to see a patch that did it that way for --mounted. The
Frugalware guys who contributed --mounted didn't do it that way, since
remounting worked for them and was easier.
--
see shy jo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFFht1ad8HHehbQuO8RAtr0AKDe3yPDpIKJ2YcHgInSlV1RFnH5CwCfTpa3
R13qKfyZpGz2CA0yB4agukM=
=Ik2X
-----END PGP SIGNATURE-----
--
The Abattoir
--- 50mounted-tests.orig 2006-12-19 19:05:56.000000000 +0530
+++ 50mounted-tests 2006-12-19 19:03:37.000000000 +0530
@@ -24,98 +24,98 @@
mkdir $tmpmnt
fi
-# If DO_MOUNTED is set, also process already mounted partitions by temporarily
-# unmounting them.
+# If DO_MOUNTED is set, set tmpmnt to oldmnt to avoid unnecessary unmounting.
oldmnt=$(mount |grep "$partition "|cut -d' ' -f 3)
if [ -n "$DO_MOUNTED" ] && [ -n "$oldmnt" ]; then
- oldopts=$(mount |grep "$partition "|sed 's/.*(\(.*\)).*/\1/')
- umount $partition
+ tmpmnt=$oldmnt
fi
for type in $(grep -v nodev /proc/filesystems); do
- if mount -o ro -t $type $partition $tmpmnt 2>/dev/null; then
- bootpart=""
- if [ -e "$tmpmnt/etc/fstab" ]; then
- # Try to mount any /boot partition.
- bootmnt=$(parsefstab < $tmpmnt/etc/fstab | grep " /boot ") || true
- if [ -n "$bootmnt" ]; then
- set -- $bootmnt
- boottomnt=""
- mounted=""
- if [ -e "$1" ]; then
- bootpart="$1"
- boottomnt="$1"
- elif [ -e "$tmpmnt/$1" ]; then
- bootpart="$1"
- boottomnt="$tmpmnt/$1"
- elif [ -e "/target/$1" ]; then
- bootpart="$1"
- boottomnt="/target/$1"
- elif echo "$1" | grep -q "LABEL="; then
- debug "mounting boot partition by label for linux system on $partition: $1"
- label=$(echo "$1" | cut -d = -f 2)
- if /target/bin/mount -L "$label" -o ro $tmpmnt/boot -t "$3"; then
- mounted=1
- bootpart=$(mount | grep $tmpmnt/boot | cut -d " " -f 1)
- else
- error "failed to mount by label"
- fi
- elif echo "$1" | grep -q "UUID="; then
- debug "mounting boot partition by UUID for linux system on $partition: $1"
- uuid=$(echo "$1" | cut -d = -f 2)
- if /target/bin/mount -U "$uuid" -o ro $tmpmnt/boot -t "$3"; then
- mounted=1
- bootpart=$(mount | grep $tmpmnt/boot | cut -d " " -f 1)
- else
- error "failed to mount by UUID"
- fi
+ if [ ! -n "$DO_MOUNTED" ]; then
+ mount -o ro -t $type $partition $tmpmnt 2>/dev/null
+ fi
+ bootpart=""
+ if [ -e "$tmpmnt/etc/fstab" ]; then
+ # Try to mount any /boot partition.
+ bootmnt=$(parsefstab < $tmpmnt/etc/fstab | grep " /boot ") || true
+ if [ -n "$bootmnt" ]; then
+ set -- $bootmnt
+ boottomnt=""
+ mounted=""
+ if [ -e "$1" ]; then
+ bootpart="$1"
+ boottomnt="$1"
+ elif [ -e "$tmpmnt/$1" ]; then
+ bootpart="$1"
+ boottomnt="$tmpmnt/$1"
+ elif [ -e "/target/$1" ]; then
+ bootpart="$1"
+ boottomnt="/target/$1"
+ elif echo "$1" | grep -q "LABEL="; then
+ debug "mounting boot partition by label for linux system on $partition: $1"
+ label=$(echo "$1" | cut -d = -f 2)
+ if /target/bin/mount -L "$label" -o ro $tmpmnt/boot -t "$3"; then
+ mounted=1
+ bootpart=$(mount | grep $tmpmnt/boot | cut -d " " -f 1)
+ else
+ error "failed to mount by label"
+ fi
+ elif echo "$1" | grep -q "UUID="; then
+ debug "mounting boot partition by UUID for linux system on $partition: $1"
+ uuid=$(echo "$1" | cut -d = -f 2)
+ if /target/bin/mount -U "$uuid" -o ro $tmpmnt/boot -t "$3"; then
+ mounted=1
+ bootpart=$(mount | grep $tmpmnt/boot | cut -d " " -f 1)
else
- bootpart=""
+ error "failed to mount by UUID"
fi
+ else
+ bootpart=""
+ fi
- if [ ! "$mounted" ]; then
- if [ -z "$bootpart" ]; then
- debug "found boot partition $1 for linux system on $partition, but cannot map to existing device"
- else
- debug "found boot partition $bootpart for linux system on $partition"
- if ! mount -o ro "$boottomnt" $tmpmnt/boot -t "$3"; then
- error "failed to mount $boottomnt on $tmpmnt/boot"
- fi
+ if [ ! "$mounted" ]; then
+ if [ -z "$bootpart" ]; then
+ debug "found boot partition $1 for linux system on $partition, but cannot map to existing device"
+ else
+ debug "found boot partition $bootpart for linux system on $partition"
+ if ! mount -o ro "$boottomnt" $tmpmnt/boot -t "$3"; then
+ error "failed to mount $boottomnt on $tmpmnt/boot"
fi
fi
fi
fi
- if [ -z "$bootpart" ]; then
- bootpart="$partition"
- fi
-
- for test in /usr/lib/linux-boot-probes/mounted/*; do
- if [ -f $test ] && [ -x $test ]; then
- debug "running $test $partition $bootpart $tmpmnt $type"
- if $test $partition $bootpart $tmpmnt $type; then
- debug "$test succeeded"
- umount $tmpmnt/boot 2>/dev/null || true
+ fi
+ if [ -z "$bootpart" ]; then
+ bootpart="$partition"
+ fi
+
+ for test in /usr/lib/linux-boot-probes/mounted/*; do
+ if [ -f $test ] && [ -x $test ]; then
+ debug "running $test $partition $bootpart $tmpmnt $type"
+ if $test $partition $bootpart $tmpmnt $type; then
+ debug "$test succeeded"
+ umount $tmpmnt/boot 2>/dev/null || true
+
+ if [ ! -n "$DO_MOUNTED" ] ; then
umount $tmpmnt
- if [ -n "$DO_MOUNTED" ] && [ -n "$oldmnt" ]; then
- mount $partition $oldmnt -o $oldopts
- fi
- rmdir $tmpmnt || true
- exit 0
+ rmdir $tmpmnt || true
fi
+ exit 0
fi
- done
+ fi
+ done
- umount $tmpmnt/boot 2>/dev/null || true
+ umount $tmpmnt/boot 2>/dev/null || true
+
+ if [ ! -n "$DO_MOUNTED" ]; then
umount $tmpmnt
- if [ -n "$DO_MOUNTED" ] && [ -n "$oldmnt" ]; then
- mount $partition $oldmnt -o $oldopts
- fi
-
- break
+ rmdir $tmpmnt || true
fi
+
+ break
done
-rmdir $tmpmnt || true
+
# No tests found anything.
exit 1
Reply to: