[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: remote access to boot loader?



Peter Ruprecht wrote:

I have a system that uses GRUB to dual-boot WindowsXP and RHEL 4.  It's
in a remote location, so when it reboots I don't have console access to
choose to boot the OS that's not the default.  Does anyone know of a
clever way to address this problem?
I've attached the script I use. Hopefully it won't get eaten by the list monster. I call it "winboot" and I do "winboot xp" and it'll boot Win XP. You can give any argument that selects something to boot unambiguously or you can give no arguments and be prompted for something to choose.

On some systems I uncomment the "exec reboot" to save me some extra typing.

jch
#!/bin/bash

if [ $(id -u) -ne 0 ]; then
    echo "${0##*/}: must be superuser" >&2
    exit 1
fi

unset DISPLAY

setboot ()
{
    echo "savedefault --default=$(($1-1)) --once" |
	grub --no-curses --device-map=/boot/grub/device.map >/dev/null
    #exec reboot
}

kernels=$(awk '$1 == "title" {sub(/^title[ 	]*/, ""); print $0;}'  /boot/grub/grub.conf)

# Choose from the command line?
if [ $# -ne 0 ]
then case $(echo "$kernels" | fgrep -ci "$*") in
     0) echo "${0##*/}: no such boot selection: \"$*\"" >&2
        exit 1
	;;
     1) N=$(echo "$kernels" | fgrep -ni $1)
        setboot ${N%%:*}
        exit 0
        ;;
     *) echo "${0##*/}: ambiguous boot selection: \"$*\":" >&2
        echo "$kernels" | fgrep -i "$*" | sed 's/^/	/' >&2
	exit 1
     esac
fi

# Offer a choice
IFS="
"
set $kernels

PS3="boot? "
select boot
do
    if [ -n "$boot" ]
    then setboot $REPLY
    fi
    break
done

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]