Commit a73b45e6 authored by Joey Hess's avatar Joey Hess

* Joey Hess

     - Initialise variables in lilo and grub probes, to avoid inheriting
       settings for things like $initrd from the kernel command line.
       This fixes processing of things like lilo.conf stanzas that do not set
       an initrd. Thanks to Frans Pop.
     - Add some extra debug logging.

r14042
parent 16d8b82e
......@@ -22,3 +22,20 @@ count_next_label() {
echo "${_labelprefix}${_cfor}"
}
log() {
logger -t "$(basename $0)" "$@"
}
error() {
log "error: $@"
}
debug() {
log "debug: $@"
}
result () {
log "result:" "$@"
echo "$@"
}
#!/bin/sh
. /usr/share/os-prober/common.sh
set -e
partition="$1"
for test in /usr/lib/linux-boot-probes/*; do
if [ -x $test ] && [ -f $test ] && \
$test $partition; then
break
debug "running $test"
if [ -x $test ] && [ -f $test ]; then
if $test $partition; then
debug "linux detected by $test"
break
fi
fi
done
#!/bin/sh
# Sub-tests that require a mounted partition.
. /usr/share/os-prober/common.sh
set -e
partition=$1
log() {
logger -t linux-boot-prober "$@"
}
error() {
log "error: $@"
}
info() {
log "info: $@"
}
parsefstab () {
while read line; do
case "$line" in
......@@ -57,11 +46,11 @@ for type in $(grep -v nodev /proc/filesystems); do
fi
if [ -z "$bootpart" ]; then
info "found boot partition $1 for linux system on $partition, but cannot map to existing device"
debg "found boot partition $1 for linux system on $partition, but cannot map to existing device"
else
info "found boot partition $bootpart for linux system on $partition"
debug "found boot partition $bootpart for linux system on $partition"
if ! mount -o ro "$boottomnt" $tmpmnt/boot -t "$3"; then
info "failed to mount $boottomnt on $tmpmnt/boot"
error "failed to mount $boottomnt on $tmpmnt/boot"
fi
fi
fi
......@@ -71,15 +60,18 @@ for type in $(grep -v nodev /proc/filesystems); do
fi
for test in /usr/lib/linux-boot-probes/mounted/*; do
if [ -f $test ] && [ -x $test ] && \
$test $partition $bootpart $tmpmnt $type; then
umount $tmpmnt/boot 2>/dev/null || true
umount $tmpmnt
rmdir $tmpmnt || true
exit 0
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
umount $tmpmnt
rmdir $tmpmnt || true
exit 0
fi
fi
done
umount $tmpmnt/boot 2>/dev/null || true
umount $tmpmnt
......
#!/bin/sh
# Fallback in case nothing else works. Look for vmlinu[xz] file in root and
# /boot, see if there is a matching initrd, and wing it.
. /usr/share/os-prober/common.sh
set -e
partition="$1"
bootpart="$2"
mpoint="$3"
......@@ -23,13 +25,13 @@ for kernfile in /vmlinuz /vmlinux /boot/vmlinuz /boot/vmlinux /boot/vmlinuz* \
for initrd in $(eval ls $mpoint$initrdname 2>/dev/null); do
if [ -f "$initrd" ]; then
initrd=$(echo "$initrd" | sed "s!^$mpoint!!")
echo "$partition:$kernbootpart::$kernfile:$initrd:root=$mappedpartition"
result "$partition:$kernbootpart::$kernfile:$initrd:root=$mappedpartition"
exitcode=0
foundinitrd=1
fi
done
if [ "$foundinitrd" = 0 ]; then
echo "$partition:$kernbootpart::$kernfile::root=$mappedpartition"
result "$partition:$kernbootpart::$kernfile::root=$mappedpartition"
exitcode=0
fi
fi
......
#!/bin/sh
. /usr/share/os-prober/common.sh
set -e
partition="$1"
bootpart="$2"
mpoint="$3"
......@@ -11,7 +13,14 @@ parse_grub_menu () {
mpoint="$1"
rootpart="$2"
bootpart="$3"
kernel=""
parameters=""
initrd=""
title=""
while read line; do
debug "parsing: $line"
set -- $line
case "$1" in
title)
......@@ -39,7 +48,7 @@ parse_grub_menu () {
if [ -n "$kernel" ] && \
[ -e "$mpoint/$kernel" ] && \
[ -e "$mpoint/$initrd" ]; then
echo "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
found_item=1
fi
kernel=""
......@@ -52,6 +61,7 @@ parse_grub_menu () {
}
if [ -e "$mpoint/boot/grub/menu.lst" ]; then
debug "parsing menu.lst"
parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub/menu.lst"
fi
......
#!/bin/sh
. /usr/share/os-prober/common.sh
set -e
partition="$1"
bootpart="$2"
mpoint="$3"
......@@ -7,6 +9,18 @@ type="$4"
found_item=0
title=""
rootdev=""
kernel=""
parameters=""
initrd=""
read_only=""
default_rootdev=""
default_kernel=""
default_parameters=""
default_initrd=""
default_read_only=""
dequote () {
item="${1%\"}"
echo "${item#\"}"
......@@ -22,8 +36,10 @@ recordstanza () {
parameters="root=$rootdev $parameters"
fi
parameters=${parameters% }
echo "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
found_item=1
else
debug "cannot find $kernel or $initrd, not recording"
fi
title=""
rootdev="$default_rootdev"
......@@ -47,6 +63,7 @@ parse_lilo_conf () {
bootpart="$3"
IFS=" ="
while read line; do
debug "parsing: $line"
set -- $line
case $1 in
root)
......@@ -79,6 +96,7 @@ parse_lilo_conf () {
}
if [ -e "$mpoint/etc/lilo.conf" ]; then
debug "parsing lilo.conf"
parse_lilo_conf "$mpoint" "$partition" "$bootpart" < "$mpoint/etc/lilo.conf"
fi
......
#!/bin/sh
. /usr/share/os-prober/common.sh
set -e
partition="$1"
bootpart="$2"
mpoint="$3"
......@@ -26,8 +28,10 @@ recordstanza () {
parameters="root=$rootdev $parameters"
fi
parameters="${parameters% }"
echo "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
record "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
found_item=1
else
debug "cannot find $kernel or $initrd; not recording"
fi
title=
rootdev="$default_rootdev"
......@@ -51,6 +55,7 @@ parse_yaboot_conf () {
bootpart="$3"
IFS=" ="
while read line; do
debug "parsing: $line"
set -- $line
case $1 in
root)
......@@ -94,6 +99,7 @@ case "`archdetect`" in
esac
if [ -e "$mpoint/etc/yaboot.conf" ]; then
debug "parsing yaboot.conf"
parse_yaboot_conf "$mpoint" "$partition" "$bootpart" < "$mpoint/etc/yaboot.conf"
fi
......
#!/bin/sh
set -e
. /usr/share/os-prober/common.sh
partitions () {
find /dev/discs/ -follow -type b | grep /part
}
for prog in /usr/lib/os-probes/init/*; do
if [ -x $prog ] && [ -f $prog ]; then
debug "running init $prog"
$prog || true
fi
done
......@@ -14,9 +17,12 @@ done
for partition in $(partitions); do
if ! grep -q "^$partition " /proc/mounts; then
for test in /usr/lib/os-probes/*; do
if [ -x $test ] && [ -f $test ] && \
$test $partition; then
break
if [ -x $test ] && [ -f $test ]; then
debug "running $test on $partition"
if $test $partition; then
debug "os detected by $test"
break
fi
fi
done
fi
......
......@@ -3,6 +3,8 @@
set -e
partition=$1
. /usr/share/os-prober/common.sh
tmpmnt=/var/lib/os-prober/mount
if [ ! -d $tmpmnt ]; then
mkdir $tmpmnt
......@@ -20,12 +22,16 @@ done
for type in $types $delaytypes; do
if mount -o ro -t $type $partition $tmpmnt 2>/dev/null; then
debug "mounted as $type filesystem"
for test in /usr/lib/os-probes/mounted/*; do
if [ -f $test ] && [ -x $test ] && \
$test $partition $tmpmnt $type; then
umount $tmpmnt
rmdir $tmpmnt || true
exit 0
debug "running subtest $test"
if [ -f $test ] && [ -x $test ]; then
if $test $partition $tmpmnt $type; then
debug "os found by subtest $test"
umount $tmpmnt
rmdir $tmpmnt || true
exit 0
fi
fi
done
umount $tmpmnt
......
......@@ -2,6 +2,8 @@
# Test for LSB systems.
set -e
. /usr/share/os-prober/common.sh
partition="$1"
dir="$2"
type="$3"
......@@ -41,5 +43,5 @@ if [ -z "$short" ]; then
short="UnknownLSB"
fi
echo "$partition:$long:$short:linux"
result "$partition:$long:$short:linux"
exit 0
......@@ -30,7 +30,7 @@ if [ -e "`ls $dir/lib/ld-linux* 2>/dev/null`" ]; then
fi
label=$(count_next_label $short)
echo "$partition:$long:$label:linux"
result "$partition:$long:$label:linux"
exit 0
else
exit 1
......
......@@ -6,10 +6,6 @@ partition=$1
mpoint=$2
type=$3
debug() {
logger -t freedos-prober "debug: $@"
}
# Weed out stuff that doesn't apply to us
case "$type" in
vfat) debug "$1 is a FAT32 partition" ;;
......@@ -19,7 +15,7 @@ esac
if [ -e "$2/kernel.sys" -a -e "$2/command.com" ]; then
label=$(count_next_label FreeDOS)
echo "$1:FreeDOS:$label:chain"
result "$1:FreeDOS:$label:chain"
exit 0
else
exit 1
......
......@@ -7,10 +7,6 @@ partition=$1
mpoint=$2
type=$3
debug() {
logger -t microsoft-prober "debug: $@"
}
# Weed out stuff that doesn't apply to us
case "$type" in
ntfs) debug "$1 is a NTFS partition" ;;
......@@ -36,4 +32,4 @@ else
fi
label=$(count_next_label $short)
echo "${partition}:${long}:${short}:chain"
result "${partition}:${long}:${short}:chain"
......@@ -9,7 +9,7 @@ type="$3"
if [ -e "$dir/servers/exec" ] && [ -x "$dir/hurd/init" ]; then
label=$(count_next_label Hurd)
echo "$partition:GNU/Hurd:$label:hurd"
result "$partition:GNU/Hurd:$label:hurd"
exit 0
else
exit 1
......
......@@ -10,7 +10,7 @@ type="$3"
if [ "$type" = minix ] && [ -f "$dir/minix" ]; then
# XXX will chain loading work?
label=$(count_next_label Minix)
echo "$partition:Minix:$label:chain"
result "$partition:Minix:$label:chain"
exit 0
else
exit 1
......
......@@ -4,10 +4,6 @@
set -e
debug() {
logger -t classic-prober "$@"
}
partition=$1
mpoint=$2
fstype=$3
......@@ -19,7 +15,7 @@ esac
if [ -e "$dir/System Folder/System" ]; then
label=$(count_next_label MacOS)
echo "${partition}:Macintosh System 6/7, OS 8/9:${label}:chain"
result "${partition}:Macintosh System 6/7, OS 8/9:${label}:chain"
exit 0
else
exit 1
......
......@@ -4,10 +4,6 @@
set -e
debug() {
logger -t classic-prober "debug: $@"
}
partition=$1
mpoint=$2
fstype=$3
......@@ -19,7 +15,7 @@ esac
if [ -e "$dir/System Folder/System" ]; then
label=$(count_next_label MacOS)
echo "${partition}:Macintosh System 6/7, OS 8/9:${label}:macos"
result "${partition}:Macintosh System 6/7, OS 8/9:${label}:macos"
exit 0
else
exit 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment