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

  1. #! /bin/bash
  2.  
  3. # Script to create an initial LILO config file.
  4. #
  5. # Usage:
  6. #   mk_boot_floppy [root_dir]
  7. #
  8. #   root_dir: the directory the root partition is mounted to (defaults to "/")
  9. #
  10. # Example:
  11. #
  12. # mk_boot_floppy /blub
  13. #
  14. # As an alternative, specify the root device using the environment variable
  15. # rootdev; e.g. rootdev=/dev/hda mk_boot_floppy
  16. #
  17. # on errors:
  18. #   exit code > 0
  19. #
  20. # Version 1.07
  21. #
  22. # Author: Steffen Winterfeldt <wfeldt@suse.de>
  23. # (c) 1999 SuSE GmbH
  24.  
  25. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  26. # general configurable parameters
  27.  
  28. # the kernel images to use; must be in $boot_dir
  29. kernel=vmlinuz
  30.  
  31. # initial ram disks (corresponding to $kernels); dto. in $boot_dir
  32. initrd=initrd
  33.  
  34. # if we need an append line (*not* for the frame buffer vga=xxxx argument)
  35. append=
  36.  
  37. # for frame buffers; the number *must* be in hex, without any leading 0x
  38. # e.g. vga=0301
  39. vga=
  40.  
  41. # boot floppy image (may be empty -> no floppy created)
  42. floppy=floppy
  43.  
  44. # show boot prompt and wait for $prompt/10 seconds (empty -> no prompt)
  45. prompt=30
  46.  
  47.  
  48. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  49. # adapt these only if needed
  50.  
  51. syslinux=/usr/sbin/syslinux
  52.  
  53. # *full* paths
  54. boot_dir=/boot
  55.  
  56. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  57. # should be nothing to change below...
  58.  
  59. tmp_msg=/tmp/msg$$
  60. tmp_boot=/tmp/boot$$
  61. tmp_mnt=/tmp/mnt$$
  62. is_mounted=
  63.  
  64. clean_up () {
  65.   [ "$is_mounted" ] && umount $tmp_mnt
  66.   rm -f $tmp_msg $tmp_boot
  67.   [ -d $tmp_mnt ] && rmdir $tmp_mnt
  68. }
  69.  
  70. error () {
  71.   echo "$2"
  72.   clean_up
  73.   exit $1
  74. }
  75.  
  76. get_device () {
  77.   x1=`mount 2>/dev/null | grep "on $1 "`
  78.   x2=`echo \`echo "$x1" | wc -l\``
  79.   x3=`echo "$x1" | cut -f 1 -d " "`
  80.  
  81.   if [ "$x2" = 1 -a -b "$x3" ] ; then
  82.     echo "$x3"
  83.   fi
  84. }
  85.  
  86. dos_image_144 () {
  87.   [ "$1" ] || return
  88.   (
  89.     echo -ne "\037\213\010\010\226j\2758\002\003tigz\000\223\357\346\340\230"
  90.     echo -ne "\226\265\327\202\211\271\044\223\341\355\215\215\274M\001\042"
  91.     echo -ne "\254\027\276o\274xC@}\203Q\324#\226\200\027L\036\211\047\335\326"
  92.     echo -ne "\044\274\3162\363QHr,\140\022>k\371\364\354\356\263\272\367\037"
  93.     echo -ne "\337\274\352[{\253O\311[3H\356\351\256\370\243j\233f\310\226]"
  94.     echo -ne "_5\343\235\333\363WA2\367E\353\242\212\337\267\037\344a\000\202"
  95.     echo -ne "\3727\217Wn\237s\371\350\332\273\267\331\030F\301(\030\005\243"
  96.     echo -ne "\140\024\014\006\260\357)\353\252\204\007\377\031\032\304\030"
  97.     echo -ne "\000\036\332-\245\015\006\000\000"
  98.   ) | gunzip -c | gunzip -c >$1
  99. }
  100.  
  101. root_dir="$1"
  102. [ "$root_dir" ] || root_dir=/
  103. if [ -z "$rootdev" ] ; then
  104.   rootdev=`get_device "$root_dir"`
  105. fi
  106. [ "$rootdev" ] || error 21 "usage: mk_boot_floppy [root_dir]"
  107. root_dirx="$root_dir"
  108. [ "$root_dirx" = / ] && root_dirx=
  109. echo "using \"$rootdev\" as root device (mounted on \"$root_dir\")"
  110.  
  111. [ -x $syslinux ] || error 22 "no syslinux installed"
  112.  
  113. dos_image_144 $tmp_boot
  114. $syslinux -s $tmp_boot || error 23 "syslinux failed"
  115.  
  116. k="$root_dirx$boot_dir/$kernel"
  117. [ -f "$k" ] || error 24 "no kernel image: \"$k\""
  118. i="$root_dirx$boot_dir/$initrd"
  119.  
  120. echo -n "creating boot disk \"$root_dirx$boot_dir/$floppy\" for kernel \"$k\", "
  121.  
  122. if [ -f "$i" ] ; then
  123.   echo "initrd \"$i\""
  124. else
  125.   echo "no initrd"
  126.   i=
  127. fi
  128.  
  129. mkdir $tmp_mnt
  130. mount -tmsdos -oloop $tmp_boot $tmp_mnt 2>/dev/null || {
  131.   error 25 "failed to mount image"
  132. }
  133. is_mounted=1
  134.  
  135. cp $k $tmp_mnt/linux || error 26 "failed to add kernel"
  136. [ "$i" ] && {
  137.  cp $i $tmp_mnt/$initrd || error 26 "failed to add initrd"
  138. }
  139.  
  140. echo -n >$tmp_msg
  141. cp $tmp_msg $tmp_mnt/message
  142.  
  143. xx1=
  144. [ "$i" ] && xx1=" initrd=$initrd"
  145. xx2=
  146. [ "$vga" ] && xx2=" vga=$vga"
  147. cat <<-blubber >$tmp_msg
  148.     default linux
  149.     append$xx1 rw root=$rootdev$xx2 $append
  150.     display message
  151.     blubber
  152. if [ "$prompt" ] ; then
  153.   echo "prompt 1" >>$tmp_msg
  154.   echo "timeout $prompt" >>$tmp_msg
  155. fi
  156.  
  157. cp $tmp_msg $tmp_mnt/syslinux.cfg || error 26 "failed to add syslinux.cfg"
  158.  
  159. umount $tmp_mnt
  160. is_mounted=
  161.  
  162. cp $tmp_boot $root_dirx$boot_dir/$floppy || error 27 "failed to install boot floppy"
  163.  
  164. clean_up
  165.  
  166.