home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / bin / mk_lilo_conf < prev    next >
Encoding:
Text File  |  2000-03-30  |  5.3 KB  |  234 lines

  1. #! /bin/bash
  2.  
  3. # Script to create an initial LILO config file.
  4. #
  5. # Usage:
  6. #   mk_lilo_conf [root_dir] [ -m mbr_device ] [ -o other_system_entry ] [ -o ... ]
  7. #
  8. #   root_dir: the directory the root partition is mounted to (defaults to "/")
  9. #   mbr_device: the device that gets the MBR (if any; default: no MBR is written)
  10. #   other_system_entry: (table is optional)
  11. #     "partition label [table]"
  12. #
  13. # Example:
  14. #
  15. # mk_lilo_conf /blub -m /dev/hda -o "/dev/hda1 dos" -o "/dev/hda2 win /dev/hda"
  16. #
  17. # As an alternative, specify the root & boot devices via environment
  18. # variables. e.g.: rootdev=/dev/hda bootdev=/dev/hda1 mk_lilo_conf
  19. #
  20. # If no boot device could be found, the root device is taken instead.
  21. #
  22. # To make a bootable floppy, specify /dev/fd0 as mbr_device.
  23. #
  24. # If kernel & initrd exceed the 1023 cylinder limit *and* LILO is to be installed
  25. # on a floppy, a complete boot disk is created (using syslinux).
  26. #
  27. # on errors:
  28. #   exit code > 0
  29. #
  30. # Version 1.07
  31. #
  32. # Author: Steffen Winterfeldt <wfeldt@suse.de>
  33. # (c) 1999 SuSE GmbH
  34.  
  35. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  36. # general configurable parameters
  37.  
  38. # the kernel images to use; must be in $boot_dir
  39. kernels="vmlinuz vmlinuz.suse"
  40.  
  41. # LILO entry names (corresponding to $kernels)
  42. lilolabels="linux suse"
  43.  
  44. # initial ram disks (corresponding to $kernels); dto. in $boot_dir
  45. initrds="initrd initrd.suse"
  46.  
  47. # if we need an append line (*not* for the frame buffer vga=xxxx argument)
  48. #append=
  49.  
  50. # for frame buffers; the number *must* be in hex, without any leading 0x
  51. # e.g. vga=0301
  52. vga=
  53.  
  54. # show boot prompt and wait for $prompt/10 seconds (empty -> no prompt)
  55. prompt=30
  56.  
  57. # lilo config (may be empty -> no lilo configured)
  58. lilo=/etc/lilo.conf
  59.  
  60. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  61. # adapt these only if needed
  62.  
  63. # *full* paths
  64. boot_dir=/boot
  65.  
  66. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  67. # should be nothing to change below...
  68.  
  69. tmp_msg=/tmp/msg$$
  70.  
  71. clean_up () {
  72.   rm -f $tmp_msg
  73. }
  74.  
  75. error () {
  76.   echo "$2"
  77.   clean_up
  78.   exit $1
  79. }
  80.  
  81. get_device () {
  82.   x1=`mount 2>/dev/null | grep "on $1 "`
  83.   x2=`echo \`echo "$x1" | wc -l\``
  84.   x3=`echo "$x1" | cut -f 1 -d " "`
  85.  
  86.   if [ "$x2" = 1 -a -b "$x3" ] ; then
  87.     echo "$x3"
  88.   fi
  89. }
  90.  
  91. write_lilo_conf_global () {
  92.   xx1=
  93.   [ "$bootdev" ] && xx1=$bootdev
  94.   [ "$mbr" -a "$mbr" != /dev/fd0 ] && xx1=$mbr
  95.   xx2=normal
  96.   [ "$vga" ] && xx2=$((0x$vga))
  97.   cat <<-blubber >$tmp_msg
  98.     boot    = $xx1
  99.     vga    = $xx2
  100.     read-only
  101.     blubber
  102.   [ "$linear" ] && echo "linear" >>$tmp_msg
  103.   if [ "$1" ] ; then
  104.     echo "prompt" >>$tmp_msg
  105.     echo "timeout    = $1" >>$tmp_msg
  106.   fi
  107.   if [ "$message" ] ; then
  108.     echo "message    = $message" >>$tmp_msg
  109.   fi
  110.   echo >>$tmp_msg
  111. }
  112.  
  113. write_lilo_conf_linux () {
  114.   xx3=
  115.   [ "$initrd" ] && xx3="  initrd = $initrd"
  116.   xx4=
  117.   [ "$append" ] && xx4="  append = \"$append\""
  118.   cat <<-blubber >>$tmp_msg
  119.       image  = $kernel
  120.       label  = $lilolabel
  121.       root   = $rootdev
  122.     blubber
  123.   [ "$xx3" ] && echo "$xx3" >>$tmp_msg
  124.   [ "$xx4" ] && echo "$xx4" >>$tmp_msg
  125.   echo >>$tmp_msg
  126. }
  127.  
  128. write_lilo_conf_other () {
  129.   xx5=
  130.   [ "$3" ] && xx5="  table  = $3"
  131.   cat <<-blubber >>$tmp_msg
  132.       other  = $1
  133.       label  = $2
  134.     blubber
  135.   [ "$xx5" ] && echo "$xx5" >>$tmp_msg
  136.   echo >>$tmp_msg
  137. }
  138.  
  139. if [ "$1" != -o ] ; then
  140.   root_dir="$1"
  141.   shift
  142. else
  143.   root_dir=
  144. fi
  145.  
  146. [ "$root_dir" ] || root_dir=/
  147. if [ -z "$rootdev" ] ; then
  148.     rootdev=`get_device "$root_dir"`
  149.     [ "$rootdev" ] || error 11 "usage: mk_lilo_conf [root_dir]"
  150. fi
  151. echo "using \"$rootdev\" as root device (mounted on \"$root_dir\")"
  152.  
  153. root_dirx="$root_dir"
  154. [ "$root_dirx" = / ] && root_dirx=
  155. if [ -z "$bootdev" ] ; then
  156.     bootdev=`get_device "$root_dirx$boot_dir"`
  157.     [ "$bootdev" ] || bootdev="$rootdev"
  158. fi
  159. echo "using \"$bootdev\" as boot partition (mounted on \"$root_dirx$boot_dir\")"
  160.  
  161. initrd_a=($initrds)
  162. lilolabels_a=($lilolabels)
  163.  
  164. message="$boot_dir/message"
  165. [ -f "$message" ] || message=
  166.  
  167. mbr=
  168. if [ "$1" = -m -a "$2" ] ; then
  169.   mbr="$2"
  170.   shift 2
  171. fi
  172.  
  173. write_lilo_conf_global $prompt
  174.  
  175. kernel_idx=0
  176. for k in $kernels ; do
  177.  
  178.   kernel="$boot_dir/$k"
  179.   [ -f "$root_dirx/$kernel" ] || error 12 "no such kernel image: \"$root_dirx/$kernel\""
  180.  
  181.   initrd="$boot_dir/${initrd_a[$kernel_idx]}"
  182.  
  183.   lilolabel="${lilolabels_a[$kernel_idx]}"
  184.  
  185.   echo -n "creating lilo entry for kernel \"$kernel\" (as \"$lilolabel\"), "
  186.  
  187.   if [ -f "$root_dirx$initrd" ] ; then
  188.     echo "initrd \"$root_dirx$initrd\""
  189.   else
  190.     echo "no initrd"
  191.     initrd=
  192.   fi
  193.  
  194.   write_lilo_conf_linux
  195.  
  196.   kernel_idx=$((kernel_idx+1))
  197.  
  198. done
  199.  
  200. while [ "$1" = "-o" -a "$2" ] ; do
  201.   write_lilo_conf_other $2
  202.   shift 2
  203. done
  204.  
  205. cp $tmp_msg $root_dir$lilo || error 13 "failed to install lilo config file"
  206.  
  207. llog="$root_dir$boot_dir/lilo.log"
  208. echo -n >$llog
  209. rm -f $root_dir$boot_dir/floppy
  210.  
  211. if [ "$mbr" ] ; then
  212.   b="$bootdev"
  213.   [ "$mbr" = /dev/fd0 ] && b=/dev/fd0
  214.   lilo -v -r $root_dir -b $b -m $boot_dir/map2 >>$llog 2>&1 || {
  215.     if [ "$mbr" = /dev/fd0 ] ; then
  216.       if grep -s -q 'Cylinder number is too big' $llog ; then
  217.         export rootdev
  218.         mk_boot_floppy || error $? "syslinux failed"
  219.         dd if=$root_dir$boot_dir/floppy of=/dev/fd0 bs=36b 2>/dev/null || error 14 "floppy write failed"
  220.         exit 0
  221.       else
  222.         error 15 "lilo failed"
  223.       fi
  224.     else
  225.       error 16 "lilo failed"
  226.     fi
  227.   }
  228.   echo "===========================" >>$llog
  229. fi
  230. lilo -v -r $root_dir >>$llog 2>&1 || error 17 "lilo failed"
  231.  
  232. clean_up
  233.  
  234.