#!/bin/bash # Copyright Jean-Philippe Guillemin . This program is free software; you can redistribute # it and/or modify it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at your option) # any later version. Please take a look at http://www.gnu.org/copyleft/gpl.htm # # liloz is intended to be called instead of lilo to enable multi-boot against several # different partitions, which is not supported by lilo alone without mounting all # partitions and modifying the lilo configuration. # lilotemp="/boot/tmp" mkdir -p $lilotemp config="$lilotemp/lilo.conf" rm -f $config 2>/dev/null findmountpoint(){ # already mounted ? mountpoint=$(mount | grep "$1" | sed -n 's/.*[ \t]*on[ \t]*\(.*\)[ \t]*type.*/\1/p') if [ "$mountpoint" == "" ] ; then # So we search in fstab mountpoint=$(cat /etc/fstab | grep "$1" | sed -n 's/^[ \t]*[^ \t]*[ \t]*\([^ \t]*\)[ \t].*$/\1/p') if [ "$mountpoint" == "" ] ; then # Still nothing ? ok let's create our own mountpoint=${lilotemp}${1} mkdir -p $mountpoint fi mount $1 $mountpoint 2>/dev/null fi [ "$( echo $mountpoint | grep '^[/ \t]*$')" ] && mountpoint="" echo $mountpoint } echoimage(){ if [ -e $part ] ; then mountpoint=$(findmountpoint $part) if [ -e ${mountpoint}${image} ] ; then echo "image = ${mountpoint}${image}" [ "$append" != "" ] && echo " append = $append" echo " root = $part" [ "$initrd" != "" ] && echo " initrd = ${mountpoint}${initrd}" echo " label = $label" [ "$readonly" != "" ] && echo " $readonly" fi fi } # What follow was simple at the time of writing it :) # In short : we parse lilo.conf to create a more multi-partition ready version found="0" while read line ; do if [ "$(echo $line | grep '^other')" ] ; then if [ "$found" == "linux" ] ; then echoimage >> $config fi echo "$line" >> $config found="other" continue elif [ "$(echo $line | grep '^image')" ] ; then if [ "$found" == "linux" ] ; then echoimage >> $config fi found="linux" image="$(echo $line | sed -e 's/^[ \t]*image[ \t]*=[ \t]*\(.*\)/\1/')" root="" initrd="" label="" readonly="" append="" continue elif [ "$found" == "linux" ] && [ "$(echo $line | grep '^root')" ] ; then part="$(echo $line | sed -e 's/^[ \t]*root[ \t]*=[ \t]*\(.*\)/\1/')" continue elif [ "$found" == "linux" ] && [ "$(echo $line | grep '^initrd')" ] ; then initrd="$(echo $line | sed -e 's/^[ \t]*initrd[ \t]*=[ \t]*\(.*\)/\1/')" continue elif [ "$found" == "linux" ] && [ "$(echo $line | grep '^label')" ] ; then label="$(echo $line | sed -e 's/^[ \t]*label[ \t]*=[ \t]*\(.*\)/\1/')" continue elif [ "$found" == "linux" ] && [ "$(echo $line | grep '^read-only')" ] ; then readonly="read-only" continue elif [ "$found" == "linux" ] && [ "$(echo $line | grep '^read-only')" ] ; then append="$(echo $line | sed -e 's/^[ \t]*append[ \t]*=[ \t]*\(.*\)/\1/')" continue else if [ "$found" == "linux" ] ; then echoimage >> $config found="0" fi [ "$(echo $line | grep "^\#")" ] && continue [ "$line" == "" ] && continue if [ "$(echo $line | grep '^other')" ] ; then echo "$line" >> $config found="other" continue fi if [ "$found" == "other" ] ; then echo " $line" >> $config else echo "$line" >> $config fi fi done < /etc/lilo.conf if [ "$found" == "linux" ] ; then echoimage >> $config fi /sbin/lilo "$@" -C $config SUCCESS=$? umount $lilotemp/dev/* 2>/dev/null exit $SUCCESS