[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: making your system robust
From: |
Yoshinori K. Okuji |
Subject: |
Re: making your system robust |
Date: |
Tue, 29 Jun 2004 12:44:00 +0200 |
User-agent: |
KMail/1.6.1 |
On Monday 28 June 2004 16:02, Robert Millan wrote:
> Uhm. I think it's quite hard to support all possible variations of
> menu.lst in a script that sets the proper setdefault options, while
> ensuring there's no collateral effect. Do you have a particular
> scheme in mind for modifying it from the script?
It's quite trivial for me. Here is an example to set up a menu.lst (not
complete or not tested):
#! /bin/bash
# Arguments.
boot=$0
# Obtain the current entry number.
current=0
default=`grep ^default /boot/grub/menu.lst | sed -e 's/default
*\(saved|[0-9]*\)/\1/'`
case "$default" in
saved)
line=`head -1 /boot/grub/menu.lst`
if echo $line | grep -q; then
current=`echo $line | sed -e 's/^\([0-9][0-9]*\).*/\1/'`
fi
;;
[0-9]*)
current=$default
;;
esac
# Make a temporary file to set fallback and default correctly.
tmp=/tmp/menu.lst.$$
cat <<EOF >$tmp
default saved
fallback $current
EOF
in_entry=0
num=0
while read line; do
if test $in_entry = 0; then
# Skip default and fallback in the original.
if cat $line | grep -q ^default; then
:
elif cat $line | grep -q ^fallback; then
:
elif cat $line | grep -q ^title; then
in_entry=1
echo $line >> $tmp
else
echo $line >> $tmp
fi
else
# Count entries.
if cat $line | grep -q ^title; then
num=`expr $num + 1`
fi
# If this is the target entry, insert savedefault and ignore it in
the original.
if test $boot -eq $num; then
if cat $line | grep -q ^title; then
echo $line >> $tmp
echo "savedefault fallback" >> $tmp
elif cat $line | grep -q ^savedefault; then
:
else
echo $line >> $tmp
fi
else
echo $line >> $tmp
fi
fi
done < /boot/grub/menu.lst
# Finish.
mv -f $tmp /boot/grub/menu.lst
exit 0
Probably it is necessary to add more code, for example, because this
does not take it into account that the user might run this script more
than once. And, it is better to restore the original menu.lst at next
boot time. Maybe using an init script.
Okuji
- Re: making your system robust, (continued)
- Re: making your system robust, Marco Gerards, 2004/06/20
- Re: making your system robust, Robert Millan, 2004/06/25
- Re: making your system robust, Yoshinori K. Okuji, 2004/06/25
- Re: making your system robust, Robert Millan, 2004/06/25
- Re: making your system robust, Yoshinori K. Okuji, 2004/06/26
- Re: making your system robust, Robert Millan, 2004/06/26
- Re: making your system robust, Yoshinori K. Okuji, 2004/06/28
- Re: making your system robust, Hans-Peter Jansen, 2004/06/28
- Re: making your system robust, Yoshinori K. Okuji, 2004/06/28
- Re: making your system robust, Robert Millan, 2004/06/28
- Re: making your system robust,
Yoshinori K. Okuji <=
- Re: making your system robust, Robert Millan, 2004/06/29
- Re: making your system robust, Yoshinori K. Okuji, 2004/06/30
- Re: making your system robust, Robert Millan, 2004/06/30