home *** CD-ROM | disk | FTP | other *** search
- #! /bin/bash
-
- # Script to create an initial LILO config file.
- #
- # Usage:
- # mk_lilo_conf [root_dir] [ -m mbr_device ] [ -o other_system_entry ] [ -o ... ]
- #
- # root_dir: the directory the root partition is mounted to (defaults to "/")
- # mbr_device: the device that gets the MBR (if any; default: no MBR is written)
- # other_system_entry: (table is optional)
- # "partition label [table]"
- #
- # Example:
- #
- # mk_lilo_conf /blub -m /dev/hda -o "/dev/hda1 dos" -o "/dev/hda2 win /dev/hda"
- #
- # As an alternative, specify the root & boot devices via environment
- # variables. e.g.: rootdev=/dev/hda bootdev=/dev/hda1 mk_lilo_conf
- #
- # If no boot device could be found, the root device is taken instead.
- #
- # To make a bootable floppy, specify /dev/fd0 as mbr_device.
- #
- # If kernel & initrd exceed the 1023 cylinder limit *and* LILO is to be installed
- # on a floppy, a complete boot disk is created (using syslinux).
- #
- # on errors:
- # exit code > 0
- #
- # Version 1.07
- #
- # Author: Steffen Winterfeldt <wfeldt@suse.de>
- # (c) 1999 SuSE GmbH
-
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # general configurable parameters
-
- # the kernel images to use; must be in $boot_dir
- kernels="vmlinuz vmlinuz.suse"
-
- # LILO entry names (corresponding to $kernels)
- lilolabels="linux suse"
-
- # initial ram disks (corresponding to $kernels); dto. in $boot_dir
- initrds="initrd initrd.suse"
-
- # if we need an append line (*not* for the frame buffer vga=xxxx argument)
- #append=
-
- # for frame buffers; the number *must* be in hex, without any leading 0x
- # e.g. vga=0301
- vga=
-
- # show boot prompt and wait for $prompt/10 seconds (empty -> no prompt)
- prompt=30
-
- # lilo config (may be empty -> no lilo configured)
- lilo=/etc/lilo.conf
-
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # adapt these only if needed
-
- # *full* paths
- boot_dir=/boot
-
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # should be nothing to change below...
-
- tmp_msg=/tmp/msg$$
-
- clean_up () {
- rm -f $tmp_msg
- }
-
- error () {
- echo "$2"
- clean_up
- exit $1
- }
-
- get_device () {
- x1=`mount 2>/dev/null | grep "on $1 "`
- x2=`echo \`echo "$x1" | wc -l\``
- x3=`echo "$x1" | cut -f 1 -d " "`
-
- if [ "$x2" = 1 -a -b "$x3" ] ; then
- echo "$x3"
- fi
- }
-
- write_lilo_conf_global () {
- xx1=
- [ "$bootdev" ] && xx1=$bootdev
- [ "$mbr" -a "$mbr" != /dev/fd0 ] && xx1=$mbr
- xx2=normal
- [ "$vga" ] && xx2=$((0x$vga))
- cat <<-blubber >$tmp_msg
- boot = $xx1
- vga = $xx2
- read-only
- blubber
- [ "$linear" ] && echo "linear" >>$tmp_msg
- if [ "$1" ] ; then
- echo "prompt" >>$tmp_msg
- echo "timeout = $1" >>$tmp_msg
- fi
- if [ "$message" ] ; then
- echo "message = $message" >>$tmp_msg
- fi
- echo >>$tmp_msg
- }
-
- write_lilo_conf_linux () {
- xx3=
- [ "$initrd" ] && xx3=" initrd = $initrd"
- xx4=
- [ "$append" ] && xx4=" append = \"$append\""
- cat <<-blubber >>$tmp_msg
- image = $kernel
- label = $lilolabel
- root = $rootdev
- blubber
- [ "$xx3" ] && echo "$xx3" >>$tmp_msg
- [ "$xx4" ] && echo "$xx4" >>$tmp_msg
- echo >>$tmp_msg
- }
-
- write_lilo_conf_other () {
- xx5=
- [ "$3" ] && xx5=" table = $3"
- cat <<-blubber >>$tmp_msg
- other = $1
- label = $2
- blubber
- [ "$xx5" ] && echo "$xx5" >>$tmp_msg
- echo >>$tmp_msg
- }
-
- if [ "$1" != -o ] ; then
- root_dir="$1"
- shift
- else
- root_dir=
- fi
-
- [ "$root_dir" ] || root_dir=/
- if [ -z "$rootdev" ] ; then
- rootdev=`get_device "$root_dir"`
- [ "$rootdev" ] || error 11 "usage: mk_lilo_conf [root_dir]"
- fi
- echo "using \"$rootdev\" as root device (mounted on \"$root_dir\")"
-
- root_dirx="$root_dir"
- [ "$root_dirx" = / ] && root_dirx=
- if [ -z "$bootdev" ] ; then
- bootdev=`get_device "$root_dirx$boot_dir"`
- [ "$bootdev" ] || bootdev="$rootdev"
- fi
- echo "using \"$bootdev\" as boot partition (mounted on \"$root_dirx$boot_dir\")"
-
- initrd_a=($initrds)
- lilolabels_a=($lilolabels)
-
- message="$boot_dir/message"
- [ -f "$message" ] || message=
-
- mbr=
- if [ "$1" = -m -a "$2" ] ; then
- mbr="$2"
- shift 2
- fi
-
- write_lilo_conf_global $prompt
-
- kernel_idx=0
- for k in $kernels ; do
-
- kernel="$boot_dir/$k"
- [ -f "$root_dirx/$kernel" ] || error 12 "no such kernel image: \"$root_dirx/$kernel\""
-
- initrd="$boot_dir/${initrd_a[$kernel_idx]}"
-
- lilolabel="${lilolabels_a[$kernel_idx]}"
-
- echo -n "creating lilo entry for kernel \"$kernel\" (as \"$lilolabel\"), "
-
- if [ -f "$root_dirx$initrd" ] ; then
- echo "initrd \"$root_dirx$initrd\""
- else
- echo "no initrd"
- initrd=
- fi
-
- write_lilo_conf_linux
-
- kernel_idx=$((kernel_idx+1))
-
- done
-
- while [ "$1" = "-o" -a "$2" ] ; do
- write_lilo_conf_other $2
- shift 2
- done
-
- cp $tmp_msg $root_dir$lilo || error 13 "failed to install lilo config file"
-
- llog="$root_dir$boot_dir/lilo.log"
- echo -n >$llog
- rm -f $root_dir$boot_dir/floppy
-
- if [ "$mbr" ] ; then
- b="$bootdev"
- [ "$mbr" = /dev/fd0 ] && b=/dev/fd0
- lilo -v -r $root_dir -b $b -m $boot_dir/map2 >>$llog 2>&1 || {
- if [ "$mbr" = /dev/fd0 ] ; then
- if grep -s -q 'Cylinder number is too big' $llog ; then
- export rootdev
- mk_boot_floppy || error $? "syslinux failed"
- dd if=$root_dir$boot_dir/floppy of=/dev/fd0 bs=36b 2>/dev/null || error 14 "floppy write failed"
- exit 0
- else
- error 15 "lilo failed"
- fi
- else
- error 16 "lilo failed"
- fi
- }
- echo "===========================" >>$llog
- fi
- lilo -v -r $root_dir >>$llog 2>&1 || error 17 "lilo failed"
-
- clean_up
-
-