home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 November - Disc 1 / PCNET_CD_2006_11_1.iso / linux / gparted-livecd-0.3.1-1.iso / gparted / usr / sbin / grubconfig < prev    next >
Encoding:
Text File  |  2005-08-04  |  40.6 KB  |  1,373 lines

  1. #!/bin/bash
  2. #
  3. # Copyright 2005 Kent Robotti <robotti@godmail.com> 8-4-2005
  4. # All rights reserved.
  5. #
  6. # Redistribution and use of this script, with or without modification, is
  7. # permitted provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of this script must retain the above copyright
  10. #    notice, this list of conditions and the following disclaimer.
  11. #
  12. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  15. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  18. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  19. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  20. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  21. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. #
  23. # grubconfig is based on liloconfig by Patrick Volkerding fron the
  24. # Slackware Linux distribution.
  25. #
  26. # Copyright 1994, 1998, 1999  Patrick Volkerding, Moorhead, Minnesota USA
  27. # Copyright 2002, 2003, 2004  Slackware Linux, Inc, Concord, CA
  28. # All rights reserved.
  29. #
  30. # Redistribution and use of this script, with or without modification, is
  31. # permitted provided that the following conditions are met:
  32. #
  33. # 1. Redistributions of this script must retain the above copyright
  34. #    notice, this list of conditions and the following disclaimer.
  35. #
  36. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  37. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  38. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  39. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  41. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  42. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  43. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  44. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  45. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. #
  47.  
  48. TMP=/tmp/grubconfig
  49. BOOT_TMP=/tmp/boot
  50. CONSOLETYPE=standard
  51. CONSOLENUM=normal
  52.  
  53. rm -rf $TMP $BOOT_TMP
  54. mkdir -p $TMP $BOOT_TMP
  55.  
  56. PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin
  57.  
  58. # Menu to check if we want to use VESA framebuffer support:
  59. use_framebuffer() {
  60. CONSOLETYPE=standard
  61. CONSOLENUM=normal
  62. if grep -q "29 fb" /proc/devices ; then
  63.   dialog --title "CONFIGURE GRUB TO USE FRAME BUFFER CONSOLE?" \
  64.   --menu "Looking at /proc/devices, it seems your kernel has support for \
  65. the Linux frame buffer console.  If we enable this, it \
  66. will allow more rows and columns of text on the screen and give you a cool \
  67. penguin logo at boot time.  However, the frame buffer text console is \
  68. slower than a standard text console.  In addition, not every video card \
  69. or monitor supports all of these video modes.  Would you like to use the \
  70. frame buffer console, or the standard Linux console?" 0 0 0 \
  71.   "standard" "Use the standard Linux console (the safe choice)" \
  72.   "640x480x256" "Frame buffer console, 640x480x256" \
  73.   "800x600x256" "Frame buffer console, 800x600x256" \
  74.   "1024x768x256" "Frame buffer console, 1024x768x256" \
  75.   "640x480x32k" "Frame buffer console, 640x480x32k" \
  76.   "800x600x32k" "Frame buffer console, 800x600x32k" \
  77.   "1024x768x32k" "Frame buffer console, 1024x768x32k" \
  78.   "640x480x64k" "Frame buffer console, 640x480x64k" \
  79.   "800x600x64k" "Frame buffer console, 800x600x64k" \
  80.   "1024x768x64k" "Frame buffer console, 1024x768x64k" \
  81.   2> $TMP/reply
  82.   if [ ! $? = 0 ]; then
  83.     chroot_umount
  84.     exit
  85.   fi
  86. # Frame buffer modes above 1024x768 look terrible except
  87. # on LCD panels, and 32 bit color is slow.  Since we don't
  88. # even need to run a framebuffer console to run framebuffer
  89. # X anymore, these modes aren't of much real use.
  90. #  "1280x1024x256" "Frame buffer console, 1280x1024x256" \
  91. #  "1600x1200x256" "Frame buffer console, 1600x1200x256" \
  92. #  "1280x1024x32k" "Frame buffer console, 1280x1024x32k" \
  93. #  "1600x1200x32k" "Frame buffer console, 1600x1200x32k" \
  94. #  "1280x1024x64k" "Frame buffer console, 1280x1024x64k" \
  95. #  "1600x1200x64k" "Frame buffer console, 1600x1200x64k" \
  96. #  "640x480x16m" "Frame buffer console, 640x480x16.8m" \
  97. #  "800x600x16m" "Frame buffer console, 800x600x16.8m" \
  98. #  "1024x768x16m" "Frame buffer console, 1024x768x16.8m" \
  99. #  "1280x1024x16m" "Frame buffer console, 1280x1024x16.8m" \
  100. #  "1600x1200x16m" "Frame buffer console, 1600x1200x16.8m"
  101.   CONSOLETYPE="`cat $TMP/reply`"
  102.   if [ "$CONSOLETYPE" = "standard" ]; then
  103.     CONSOLENUM=normal
  104.   elif [ "$CONSOLETYPE" = "1600x1200x16m" ]; then
  105.     CONSOLENUM=799
  106.   elif [ "$CONSOLETYPE" = "1600x1200x64k" ]; then
  107.     CONSOLENUM=798
  108.   elif [ "$CONSOLETYPE" = "1600x1200x32k" ]; then
  109.     CONSOLENUM=797
  110.   elif [ "$CONSOLETYPE" = "1600x1200x256" ]; then
  111.     CONSOLENUM=796
  112.   elif [ "$CONSOLETYPE" = "1280x1024x16m" ]; then
  113.     CONSOLENUM=795
  114.   elif [ "$CONSOLETYPE" = "1280x1024x64k" ]; then
  115.     CONSOLENUM=794
  116.   elif [ "$CONSOLETYPE" = "1280x1024x32k" ]; then
  117.     CONSOLENUM=793
  118.   elif [ "$CONSOLETYPE" = "1280x1024x256" ]; then
  119.     CONSOLENUM=775
  120.   elif [ "$CONSOLETYPE" = "1024x768x16m" ]; then
  121.     CONSOLENUM=792
  122.   elif [ "$CONSOLETYPE" = "1024x768x64k" ]; then
  123.     CONSOLENUM=791
  124.   elif [ "$CONSOLETYPE" = "1024x768x32k" ]; then
  125.     CONSOLENUM=790
  126.   elif [ "$CONSOLETYPE" = "1024x768x256" ]; then
  127.     CONSOLENUM=773
  128.   elif [ "$CONSOLETYPE" = "800x600x16m" ]; then
  129.     CONSOLENUM=789
  130.   elif [ "$CONSOLETYPE" = "800x600x64k" ]; then
  131.     CONSOLENUM=788
  132.   elif [ "$CONSOLETYPE" = "800x600x32k" ]; then
  133.     CONSOLENUM=787
  134.   elif [ "$CONSOLETYPE" = "800x600x256" ]; then
  135.     CONSOLENUM=771
  136.   elif [ "$CONSOLETYPE" = "640x480x16m" ]; then
  137.     CONSOLENUM=786
  138.   elif [ "$CONSOLETYPE" = "640x480x64k" ]; then
  139.     CONSOLENUM=785
  140.   elif [ "$CONSOLETYPE" = "640x480x32k" ]; then
  141.     CONSOLENUM=784
  142.   elif [ "$CONSOLETYPE" = "640x480x256" ]; then
  143.     CONSOLENUM=769
  144.   fi
  145. fi
  146. }
  147.  
  148. chroot_umount() {
  149. if [ "$CHROOT" = "YES" ]; then
  150.   umount /proc
  151. fi
  152. }
  153.  
  154. create_devices() {
  155.       fdisk -l >$TMP/DEV 2>$TMP/null
  156. }
  157.  
  158. hd_mbr() {
  159.       mbr_dev="`grep "^Disk /dev/" $TMP/DEV | head -n 1 | cut -d ' ' -f 2 | cut -b 1-8`"
  160.       mbr_dev2="`grep "^Disk /dev/" $TMP/DEV | tail -n 1 | cut -d ' ' -f 2 | cut -b 1-8`"
  161.  
  162. if [ -z "$mbr_dev" ]; then
  163.          $DIALOG --title "ERROR" --msgbox \
  164.         "I can't find a device to install GRUB to!" 5 60
  165.          umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  166.          rm -rf $TMP
  167.          chroot_umount
  168.          exit
  169. elif [ $mbr_dev2 = $mbr_dev ]; then
  170. mbr_grub_dev=hd0
  171. if ! probe $mbr_dev; then
  172.          $DIALOG --title "ERROR" --msgbox \
  173.         "I can't find the device '$mbr_dev', so I can't install GRUB!" 5 68
  174.          umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  175.          rm -rf $TMP
  176.          chroot_umount
  177.          exit
  178. fi
  179. else
  180. while :
  181. do
  182. cat << EOF >$TMP/tmpmsg
  183. Usually GRUB is installed to the MBR of the primary
  184. hard drive, in your case '$mbr_dev'.
  185.  
  186. If you have more than one hard drive and want GRUB installed
  187. to the MBR of another hard drive, put the device below, or
  188. leave the box blank for '$mbr_dev'.
  189. EOF
  190.  
  191.     $DIALOG --title "HARD DRIVE MBR" --inputbox "`cat $TMP/tmpmsg`" 14 68 2> $TMP/mbr_dev
  192.     if [ ! $? = 0 ]; then
  193.       umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  194.       rm -rf $TMP
  195.       chroot_umount
  196.       echo
  197.       echo "Cancelled!"
  198.       exit
  199.     fi
  200.     
  201.      MBR_DEV="`cat $TMP/mbr_dev`"
  202.  
  203.      if [ -n "$MBR_DEV" ]; then
  204.          old_mbr_dev=$mbr_dev
  205.          mbr_dev=$MBR_DEV
  206.      fi     
  207.      
  208.      if probe $mbr_dev; then
  209.          break;
  210.      else
  211.          $DIALOG --title "ERROR" --msgbox \
  212.         "I can't find the device '$mbr_dev'." 5 45
  213.          mbr_dev=$old_mbr_dev
  214.          continue;
  215.      fi
  216. done
  217. NUM=0
  218. grep "^Disk /dev/" $TMP/DEV | cut -d ' ' -f 2 | cut -b 1-8 | while read dev; do
  219. echo "hd$NUM" >$TMP/mbr_grub_dev
  220. if [ "$dev" = "$mbr_dev" ]; then
  221. break
  222. fi
  223. NUM=$(( $NUM + 1 ))
  224. done
  225. mbr_grub_dev="`cat $TMP/mbr_grub_dev`"
  226. fi
  227. }
  228.  
  229. initrd() {
  230. if [ "$ROOT_DEVICE" = "$1" ]; then
  231. if ls $BOOT/initrd* 1>$TMP/null 2>$TMP/null ; then
  232. initrd=`ls -1 -t $BOOT/initrd* | head -n 1`
  233. if [ ! "$3" = "no" ]; then
  234.   $DIALOG --title "INITRD FOUND" --yesno "Do you want to include \
  235. the initrd '$initrd' in the GRUB config file?" 7 66
  236. return=$?
  237. else
  238. return=0
  239. fi
  240. if [ $return = 0 ]; then
  241.     $DIALOG --title "Working..." --infobox \
  242.     "Creating /boot/grub/$grub_config file on $ROOT_DEVICE..." 3 60
  243.      sleep 3
  244. size=`gzip -l $initrd 2>$TMP/null | grep -v uncompressed_name | awk '{print $2}'`
  245. if [ ! "$size" = "" ]; then
  246. size=$(( $size / 1024 ))
  247. else
  248. size=$(( `ls -l $initrd | awk '{print $5}'` / 1024 ))
  249. fi
  250.   KERNEL="`echo $KERNEL | awk '{print $1,$2,$3}'` ramdisk_size=$size root=/dev/ram0 rw"
  251.   cat << EOF > $2
  252. # Linux bootable initrd config begins
  253.   title Linux initrd $initrd on ($1)
  254.   root ($hd,$p2)
  255.   $KERNEL
  256.   initrd $initrd
  257. # Linux bootable initrd config ends
  258. EOF
  259. fi
  260. fi
  261. fi
  262. }
  263.  
  264. get_root_dev() {
  265. NUM=0
  266. grep "^Disk /dev/" $TMP/DEV | cut -d ' ' -f 2 | cut -b 1-8 | while read dev; do
  267. echo "hd$NUM" >$TMP/hd_grub
  268. dev2="`echo $1 | cut -b 1-8`"
  269. if [ "$dev" = "$dev2" ]; then
  270. break
  271. fi
  272. NUM=$(( $NUM + 1 ))
  273. done
  274. hd="`cat $TMP/hd_grub`"
  275. }
  276.  
  277. other() {
  278.  D=`echo "$@" | cut -d ' ' -f 1`
  279.  get_root_dev $D
  280.  
  281. if echo "$@" | grep -q HURD ; then
  282. grub --no-floppy --batch << EOF 1>$TMP/find_file 2>$TMP/null
  283. find ($hd,$p2)/boot/gnumach.gz
  284. quit
  285. EOF
  286. if grep -q "($hd,$p2)" $TMP/find_file ; then
  287. OTHER="root ($hd,$p2)
  288.   kernel /boot/gnumach.gz root=device:$hd"s"$p1
  289.   module /hurd/ext2fs.static --multiboot-command-line=\${kernel-command-line} --host-priv-port=\${host-port} --device-master-port=\${device-port} --exec-server-task=\${exec-task} -T typed \${root} \$(task-create) \$(task-resume)
  290.   module /lib/ld.so.1 /hurd/exec \$(exec-task=task-create)"
  291. echo "GNU/Hurd on ($DOSP)" > $TMP/label
  292. else
  293. OTHER="rootnoverify ($hd,$p2)
  294.   makeactive
  295.   chainloader --force +1"
  296. echo "SCO Unixware on ($DOSP)" > $TMP/label
  297. fi
  298. elif echo "$@" | grep -q BSD ; then
  299. if echo "$@" | grep -q FreeBSD ; then
  300. OTHER="root ($hd,$p2,a)
  301.   kernel /boot/loader"
  302. else  
  303. OTHER="rootnoverify ($hd,$p2)
  304.   chainloader +1"
  305. fi
  306. elif echo "$@" | grep -q QNX ; then
  307. OTHER="map (hd0) ($hd)
  308.   map ($hd) (hd0)
  309.   rootnoverify ($hd,$p2)
  310.   chainloader +4"
  311. elif echo "$@" | grep -q -E "Plan 9|BeOS|Minix" ; then
  312. OTHER="rootnoverify ($hd,$p2)
  313.   chainloader +1"
  314. elif [ ! "$hd" = "hd0" ]; then
  315. if [ "$p2" = "0" ]; then
  316. OTHER="map (hd0) ($hd)
  317.   map ($hd) (hd0)
  318.   rootnoverify ($hd,$p2)
  319.   makeactive
  320.   chainloader +1"
  321. else
  322. OTHER="map (hd0) ($hd)
  323.   map ($hd) (hd0)
  324.   map (hd0,0) ($hd,$p2)
  325.   map ($hd,$p2) (hd0,0)
  326.   rootnoverify ($hd,$p2)
  327.   makeactive
  328.   chainloader +1"
  329. fi
  330. else
  331. if [ "$p2" = "0" ]; then
  332. OTHER="rootnoverify (hd0,$p2)
  333.   makeactive
  334.   chainloader +1"
  335. else
  336. OTHER="map (hd0,0) (hd0,$p2)
  337.   map (hd0,$p2) (hd0,0)
  338.   rootnoverify (hd0,$p2)
  339.   makeactive
  340.   chainloader +1"
  341. fi
  342. fi
  343. }
  344.  
  345. # This function scans for bootable partitions (making some assumptions along
  346. # the way which may or may not be correct, but usually work), and sets up
  347. # GRUB in either the superblock, or the MBR.
  348. simplegrub()
  349. {
  350.  if grep -q "OS/2 Boot Manager" $TMP/DEV 2> $TMP/null ; then
  351.   $DIALOG --title "OS/2 BOOT MANAGER FOUND" --yesno \
  352.   "Your system appears to have Boot Manager, a boot menu system provided \
  353. with OS/2 and Partition Magic.  If you like, we can install a very simple \
  354. GRUB boot block at the start of your Linux partition.  Then, you can \
  355. add the partition to the Boot Manager menu, and you'll be able to use \
  356. Boot Manager to boot Linux.  Would you like to install GRUB in a Boot \
  357. Manager compatible way?" 11 65
  358.   if [ $? = 0 ]; then
  359.     TG=Root
  360.     skip=yes
  361.   fi
  362. fi
  363.  
  364. if [ ! "$skip" = "yes" ]; then
  365.  $DIALOG --title "SELECT GRUB DESTINATION" --menu \
  366. "GRUB can be installed to a variety of places:\n\
  367. \n\
  368.   1. The superblock of a Linux partition '$ROOT_DEVICE',\n\
  369.      (which could be made the bootable partition with DOS or\n\
  370.      Linux fdisk, or booted with a Boot Manager like OS/2 etc.)\n\
  371.   2. A formatted floppy disk.\n\
  372.   3. The Master Boot Record of a hard drive.\n\
  373. \n\
  374. Options 1 and 2 are the safest, but option 1 does require a little\n\
  375. extra work later (setting the partition bootable with fdisk).\n\
  376. Which option would you like?" \
  377.  20 72 3 \
  378.  "Root" "Install to superblock of Linux partition" \
  379.  "Floppy" "Install to a formatted floppy in /dev/fd0 (A:)" \
  380.  "MBR" "Install to Master Boot Record (possibly unsafe)" \
  381.  2> $TMP/reply
  382.  if [ ! $? = 0 ]; then
  383.    chroot_umount
  384.    exit
  385.  fi
  386.  TG="`cat $TMP/reply`"
  387. fi
  388.  
  389.  if [ "$TG" = "MBR" ]; then
  390.   hd_mbr
  391.   MBR=YES
  392.  elif [ "$TG" = "Root" ]; then
  393.   MBR=NO
  394.  elif [ "$TG" = "Floppy" ]; then
  395.   GRUB_TARGET="/dev/fd0"
  396.   MBR=NO
  397.  fi
  398.  
  399.     $DIALOG --title "Working..." --infobox \
  400.     "Creating /boot/grub/$grub_config file on $ROOT_DEVICE..." 3 60
  401.      sleep 3
  402.  
  403.  # Search for Linux partitions:
  404.  grep "83  Linux" $TMP/DEV | while read PART ; do 
  405.  if [ ! "$PART" = "" ]; then
  406.   LNXP="`echo $PART | cut -f 1 -d ' '`"
  407.   p1=`echo $LNXP | cut -b9-`
  408.   p2=$(( $p1 - 1 ))
  409.  
  410.   get_root_dev $LNXP
  411.  
  412.   KERNEL="kernel /boot/vmlinuz root=$LNXP ro vga=$CONSOLENUM"
  413.  
  414.   title="Linux on ($LNXP)"
  415.  
  416.   num="`echo $LNXP | cut -b8-`" 
  417.  
  418.   cat << EOF > $TMP/part.$num.sort
  419. # Linux bootable partition config begins
  420.   title $title
  421.   root ($hd,$p2)
  422.   $KERNEL
  423. # Linux bootable partition config ends
  424. EOF
  425. initrd $LNXP $TMP/initrd.conf no
  426.  fi
  427. done
  428.  
  429.  # OK, now let's look for DOS/WIN/OS2/BSD/HURD partitions:
  430. grep "^/dev/" $TMP/DEV | grep -E "DOS|Win95|W95|FAT|BSD|NTFS|HURD|QNX|Minix|Plan|BeOS" | \
  431. grep -v "Ext'd" | grep -v "Extend" | grep -v -i "swap" | while read PART ; do
  432.   if [ ! "$PART" = "" ]; then
  433.   DOSP="`echo $PART | cut -f 1 -d ' '`"
  434.   p1=`echo $DOSP | cut -b9-`
  435.   p2=$(( $p1 - 1 ))
  436.   if echo $PART | grep -q -E "Win95|W95|NTFS" ; then
  437.   LABEL="Windows on ($DOSP)"
  438.   elif echo $PART | grep -q -E "DOS|FAT" ; then
  439.   LABEL="DOS on ($DOSP)"
  440.   elif echo $PART | grep -q "FreeBSD" ; then
  441.   LABEL="FreeBSD on ($DOSP)"
  442.   elif echo $PART | grep -q "OpenBSD" ; then
  443.   LABEL="OpenBSD on ($DOSP)"
  444.   elif echo $PART | grep -q "NetBSD" ; then
  445.   LABEL="NetBSD on ($DOSP)"
  446.   elif echo $PART | grep -q "BSD" ; then
  447.   LABEL="BSD on ($DOSP)"
  448.   elif echo $PART | grep -q "Minix" ; then
  449.   LABEL="Minix on ($DOSP)"
  450.   elif echo $PART | grep -q "QNX" ; then
  451.   LABEL="QNX on ($DOSP)"
  452.   elif echo $PART | grep -q "BeOS" ; then
  453.   LABEL="BeOS on ($DOSP)"
  454.   elif echo $PART | grep -q "Plan 9" ; then
  455.   LABEL="Plan 9 on ($DOSP)"
  456.   fi
  457.  
  458.   other $PART
  459.  
  460.   if echo $PART | grep -q "HURD" ; then
  461.   LABEL="`cat $TMP/label`"
  462.   fi
  463.  
  464.   num="`echo $DOSP | cut -b8-`" 
  465.  
  466.   cat << EOF > $TMP/part.$num.sort
  467. # Other bootable partition config begins
  468.   title $LABEL
  469.   $OTHER
  470. # Other bootable partition config ends
  471. EOF
  472. fi
  473. done
  474.  # Done, now we must install GRUB:
  475.  chmod 644 $BOOT/grub/$grub_config
  476.  message=yes
  477.  installcolor;
  478.  umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  479.  rm -rf $TMP
  480. }
  481.  
  482. find_kernel() {
  483. cat << EOF > $TMP/tmpmsg
  484. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  485. `grep "^$PART" $TMP/fdisk.list`
  486.  
  487. Where on the above Linux partition is the kernel you
  488. want GRUB to boot?
  489.  
  490. The default is '/boot/vmlinuz'. Just press enter for it.
  491. EOF
  492.  
  493.     $DIALOG --title "KERNEL LOCATION" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/kernel
  494.     if [ $? = 1 -o $? = 255 ]; then
  495.       umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  496.       rm -rf $TMP
  497.       chroot_umount
  498.       echo
  499.       echo "Cancelled!"
  500.       exit
  501.     else
  502.       kernel="`cat $TMP/kernel`"
  503.     if [ "$kernel" = "" ]; then
  504.       KERNEL="kernel /boot/vmlinuz root=$PART ro vga=$CONSOLENUM"
  505.     else
  506.       KERNEL="kernel $kernel root=$PART ro vga=$CONSOLENUM"
  507.     fi
  508.    fi
  509.  
  510. cat << EOF > $TMP/tmpmsg
  511. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  512. `grep "^$PART" $TMP/fdisk.list`
  513.  
  514. `echo $KERNEL | cut -d ' ' -f 2-`
  515.  
  516. Do you want to pass any other options to the above kernel?
  517. For example: hdd=scsi
  518.  
  519. Put then on one line one after the other or leave box blank.
  520. EOF
  521.  
  522.     $DIALOG --title "KERNEL OPTIONS" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/reply
  523.     APPEND="`cat $TMP/reply`"
  524. }
  525.  
  526. install_grub()
  527. {
  528. NUM=0
  529. grep "^Disk /dev/" $TMP/DEV | cut -d ' ' -f 2 | cut -b 1-8 | while read dev; do
  530. echo "hd$NUM" >$TMP/root_dev
  531. dev2="`echo $ROOT_DEVICE | cut -b 1-8`"
  532. if [ "$dev" = "$dev2" ]; then
  533. break
  534. fi
  535. NUM=$(( $NUM + 1 ))
  536. done
  537. root_dev="`cat $TMP/root_dev`"
  538.  
  539.      p1=`echo $ROOT_DEVICE | cut -b 9-`
  540.      p2=$(( $p1 - 1 ))
  541.  
  542. rm -f $TMP/grub.conf
  543. for f in `ls $TMP/part.*.sort`
  544. do
  545. cat $f >> $TMP/grub.conf
  546. done
  547.  
  548. if [ -f $TMP/initrd.conf ]; then
  549.   cat $TMP/initrd.conf >> $TMP/grub.conf
  550. fi
  551.  
  552. cat << EOF >> $TMP/grub.conf
  553. title --- For help press 'c', type: 'help'
  554. root (hd0)
  555. title --- For usage examples, type: 'cat /boot/grub/grub.txt'
  556. root (hd0)
  557. EOF
  558.  
  559. cat << EOF > $BOOT/grub/grub.txt
  560. =======================================================================
  561. This is an example of how to use the GRUB edit function.
  562.  
  563. Highlight the menu entry you want to edit and press 'e', then
  564. highlight the line you want to edit and press 'e'. Add what
  565. you want to the line 'acpi=off' etc. and press enter, then
  566. 'b' to boot.
  567.  
  568. Examples of the difference between Linux and GRUB device names.
  569.  
  570. Linux IDE:    GRUB IDE:    Linux SCSI:    GRUB SCSI:
  571. /dev/hda1       (hd0,0)        /dev/sda1       (hd0,0)
  572. /dev/hda2       (hd0,1)        /dev/sda2       (hd0,1)
  573. /dev/hda3       (hd0,2)        /dev/sda3       (hd0,2)
  574. /dev/hda4       (hd0,3)        /dev/sda4       (hd0,3)
  575. /dev/hdb1       (hd1,0)        /dev/sdb1       (hd1,0)
  576. /dev/hdb2       (hd1,1)        /dev/sdb2       (hd1,1)
  577. /dev/hdb3       (hd1,2)        /dev/sdb3       (hd1,2)
  578. /dev/hdb4       (hd1,3)        /dev/sdb4       (hd1,3)
  579.  
  580. These are some examples of how to use GRUB from the command prompt.
  581.  
  582. Press the 'c' key for the command prompt.
  583.  
  584. If you want to boot a Linux system on a partition, using its kernel
  585. /boot/vmlinuz etc., do this.
  586.  
  587. grub> root (hd0,1)
  588. grub> kernel /boot/vmlinuz root=/dev/hda2 ro
  589. grub> boot
  590.  
  591. You could do this to find what partition the kernel is on.
  592.  
  593. For example, show me what partitions have /boot/vmlinuz.
  594.  
  595. grub> find /boot/vmlinuz
  596. (hd0,1)
  597. (hd0,2)
  598.  
  599. If you want to boot a Windows partition, do this.
  600.  
  601. For example, boot partition on /dev/hda1.
  602.  
  603. grub> rootnoverify (hd0,0)
  604. grub> makeactive
  605. grub> chainloader +1
  606. grub> boot
  607.  
  608. If you want to boot a FreeBSD partition, using /boot/loader.
  609.  
  610. For example, boot FreeBSD partition on /dev/hda4.
  611.  
  612. grub> root (hd0,3,a)
  613. grub> kernel /boot/loader
  614. grub> boot
  615.  
  616. If that doesn't work, try this.
  617.  
  618. grub> rootnoverify (hd0,3,a)
  619. grub> chainloader +1
  620. grub> boot
  621. ==============================================================
  622.  
  623. Press the [Esc] key to return to the GRUB menu.
  624. EOF
  625.  
  626. sync
  627.  
  628. if [ "$MBR" = "NO" ]; then
  629. if [ "$GRUB_TARGET" = "/dev/fd0" ]; then
  630. rm -f $BOOT/grub/device.map
  631. grub --device-map=$BOOT/grub/device.map --batch << EOF 1>$TMP/error 2>$TMP/null
  632. root ($root_dev,$p2)
  633. setup (fd0)
  634. quit
  635. EOF
  636. SUCCESS=0
  637. grep -q Error $TMP/error && SUCCESS=1
  638. installed="installed on the floppy disk"
  639. else
  640. rm -f $BOOT/grub/device.map
  641. grub --device-map=$BOOT/grub/device.map --no-floppy --batch << EOF 1>$TMP/error 2>$TMP/null
  642. root ($root_dev,$p2)
  643. setup ($root_dev,$p2)
  644. quit
  645. EOF
  646. SUCCESS=0
  647. grep -q Error $TMP/error && SUCCESS=1
  648. installed="installed on the Linux partition $ROOT_DEVICE"
  649. fi
  650. else
  651. dd if=$mbr_dev of=$BOOT/grub/mbr.`echo $mbr_dev | cut -b 6-8`.$$ bs=512 count=1 >$TMP/null 2>&1 && \
  652. backup_mbr=$BOOT/grub/mbr.`echo $mbr_dev | cut -b 6-8`.$$
  653. rm -f $BOOT/grub/device.map
  654. grub --device-map=$BOOT/grub/device.map --no-floppy --batch << EOF 1>$TMP/error 2>$TMP/null
  655. root ($root_dev,$p2)
  656. setup ($mbr_grub_dev)
  657. quit
  658. EOF
  659. SUCCESS=0
  660. grep -q Error $TMP/error && SUCCESS=1
  661. installed="installed on the MBR of $mbr_dev"
  662. fi  
  663.  
  664.      if [ -r $BOOT/grub/$grub_config ]; then
  665.           mv $BOOT/grub/$grub_config $BOOT/grub/$grub_config.old.$$
  666.      fi
  667.  
  668. if [ ! "$backup_mbr" = "" ]; then
  669. mbr_backup=`basename $backup_mbr` 
  670.  cat << EOF > $BOOT/grub/$grub_config
  671. # GRUB configuration file '/boot/grub/$grub_config'.
  672. # generated by 'grubconfig'.  `date +%c 2>$TMP/null`
  673. #
  674. # The backup copy of the MBR for drive '$mbr_dev' is
  675. # here '/boot/grub/$mbr_backup'.  You can restore it like this.
  676. # dd if=$mbr_backup of=$mbr_dev bs=512 count=1
  677. #
  678. # Start GRUB global section
  679. #timeout 30
  680. #color light-gray/blue black/light-gray
  681. # End GRUB global section
  682. EOF
  683. else
  684.  cat << EOF > $BOOT/grub/$grub_config
  685. # GRUB configuration file '/boot/grub/$grub_config'.
  686. # generated by 'grubconfig'.  `date +%c 2>$TMP/null`
  687. #
  688. # Start GRUB global section
  689. #timeout 30
  690. #color light-gray/blue black/light-gray
  691. # End GRUB global section
  692. EOF
  693. fi
  694. cat $TMP/grub.conf >> $BOOT/grub/$grub_config
  695. chmod 644 $BOOT/grub/$grub_config
  696. }
  697.  
  698. installcolor()
  699. {
  700. if [ "$GRUB_TARGET" = "/dev/fd0" ]; then
  701. while :
  702. do
  703.      $DIALOG --title "FLOPPY DISK" --menu \
  704. "The floppy should be formatted. \n\
  705. Put the floppy in the drive and press enter." 10 55 2 \
  706.  "Ready" "The floppy is already formatted" \
  707.  "Format" "Format the floppy" 2> $TMP/reply
  708.       if [ ! $? = 0 ]; then
  709.         chroot_umount
  710.         exit
  711.       elif ! (dd if=/dev/fd0 of=$TMP/null bs=1 count=1 1>$TMP/null 2>$TMP/null) ; then
  712.         continue
  713.       fi
  714.       REPLY="`cat $TMP/reply`"
  715.       if [ "$REPLY" = "Format" ]; then
  716.       [ -b /dev/fd0h1440 ] && fd=/dev/fd0h1440
  717.       [ -b /dev/fd0H1440 ] && fd=/dev/fd0H1440
  718.       [ -b /dev/fd0u1440 ] && fd=/dev/fd0u1440
  719.       if [ -x "`type -path fdformat`" ]; then
  720.         $DIALOG --title "Formatting floppy..." --infobox \
  721.         "fdformat -n $fd" 3 35
  722.         fdformat -n $fd || continue
  723.       elif [ -x "`type -path superformat`" ]; then
  724.         $DIALOG --title "Formatting floppy..." --infobox \
  725.         "superformat -f $fd" 3 35
  726.         superformat -f $fd || continue
  727.       else
  728.          $DIALOG --title "ERROR" --msgbox \
  729.         "Can't find 'fdformat' or 'superformat' to format floppy." 5 65
  730.          continue
  731.       fi
  732.       fi
  733.         break
  734. done
  735. fi
  736.  
  737.    $DIALOG --infobox "\nInstalling the GRUB Bootloader..." 5 40
  738.    sleep 2 
  739.  
  740.    if [ ! "$KILL" = "NO" ]; then
  741.      if [ -r /proc/sys/kernel/printk ]; then
  742.         echo 3 >/proc/sys/kernel/printk
  743.      else
  744.         killall klogd 2>$TMP/null
  745.         sleep 1
  746.         klogd -c 3 2>$TMP/null
  747.      fi
  748.    fi
  749.    
  750.    install_grub
  751.  
  752.  if [ ! "$SUCCESS" = "0" ]; then # some GRUB error occured
  753.   if [ ! "$backup_mbr" = "" -a ! "$mbr_dev" = "" ]; then
  754.   if [ -s "$backup_mbr" ]; then
  755.   if dd if=$mbr_dev bs=512 count=1 | grep -q GRUB ; then
  756.      dd if=$backup_mbr of=$mbr_dev bs=512 count=1 >$TMP/null 2>&1
  757.   fi
  758.   fi
  759.   fi
  760. cat $TMP/error >$TMP/tmpmsg
  761. cat << EOF >>$TMP/tmpmsg
  762. -----------------------------------------------------------------------
  763. Sorry, but the attempt to install GRUB has returned an error, so GRUB
  764. has not been correctly installed.  You'll have to use a bootdisk to
  765. start your machine instead.  It may be possible to get GRUB working by
  766. editing the /boot/grub/$grub_config file and reinstalling GRUB manually.
  767. See the GRUB man page and info documentation in /usr/info for more help.
  768. -----------------------------------------------------------------------
  769. EOF
  770.   $DIALOG --title "GRUB INSTALL ERROR" --msgbox "`cat $TMP/tmpmsg`" 0 0
  771.  else
  772.   if [ "$message" = "yes" ]; then
  773. cat << EOF >$TMP/tmpmsg
  774.  
  775. GRUB was successfully $installed.
  776.  
  777. You should check and edit the '/boot/grub/$grub_config'
  778. file on '$ROOT_DEVICE', if needed. You may want to change
  779. the location '/boot/vmlinuz', and/or options passed to any
  780. Linux kernel listed there.
  781.  
  782. EOF
  783.    $DIALOG --title "GRUB INSTALL SUCCESS" --msgbox "`cat $TMP/tmpmsg`" 12 70
  784.   else
  785.    $DIALOG --title "GRUB INSTALL SUCCESS" --msgbox \
  786.    "GRUB was successfully $installed." 5 70
  787.   fi
  788.  fi
  789. }
  790.  
  791. # 'probe()' borrowed from GRUB QuickInst.
  792. probe()
  793. {
  794.  [ ! -z "`dd if=$1 bs=1 count=1 2>$TMP/null | tr '\0' x`" ]
  795.  return
  796. }
  797.  
  798.    DIALOG=`type -path dialog`
  799.    if [ ! -x "$DIALOG" ]; then
  800.      echo "This script requires the 'dialog' program to run."
  801.      chroot_umount
  802.      exit 1
  803.    fi
  804.  
  805.  if [ ! `whoami` = "root" ]; then
  806.      $DIALOG --title "NOT ROOT" --msgbox \
  807.      "You need to be 'root' to run this script." 5 50
  808.      chroot_umount
  809.      exit
  810.  fi
  811.  
  812.  if [ ! -x "`type -path grub`" ]; then
  813.      $DIALOG --title "CAN'T FIND GRUB" --msgbox \
  814.      "I can't find 'grub' on the system." 5 40
  815.      chroot_umount
  816.      exit
  817.  fi
  818.  
  819.  BOOT=/boot
  820.  if grep -q $BOOT/grub/grub.conf 2>$TMP/null `type -path grub` ; then
  821.     grub_config=grub.conf
  822.  else
  823.     grub_config=menu.lst
  824.  fi
  825.  
  826. root_device() {
  827. # Determine the root partition (such as /dev/hda2)
  828.     ROOT_DEVICE="`mount 2>$TMP/null | grep " on / " | awk '{print $1}'`"
  829.  
  830.   if [ -z "$ROOT_DEVICE" -a -s /etc/fstab ]; then
  831.     ROOT_DEVICE="`grep -v "^#" /etc/fstab 2>$TMP/null | grep " / " | awk '{print $1}'`"
  832.   fi
  833.   
  834.   if [ -n "$ROOT_DEVICE" ]; then
  835.   if ! echo $ROOT_DEVICE | grep -q -E "/dev/sd|/dev/hd" ; then
  836.      unset ROOT_DEVICE
  837.   fi
  838.   fi
  839.   
  840.     if [ -n "$ROOT_DEVICE" ]; then
  841. cat << EOF > $TMP/tmpmsg
  842. Where do you want the GRUB files to go?
  843.  
  844. The default is to put them in /boot/grub on the current
  845. partition '$ROOT_DEVICE'.  To accept this default, leave
  846. the line below unchanged and hit ENTER (this should be
  847. fine for most users).  If (for some reason) you want to
  848. use a different partition, change it on the line below
  849. and hit ENTER.
  850. EOF
  851. else
  852. cat << EOF > $TMP/tmpmsg
  853. Where do you want the GRUB files to go?
  854.  
  855. Usually they are put with the kernel in the /boot directory.
  856. What partition has the /boot directory you want to use?
  857. Put the partition (/dev/hda2 etc.) in the box below:
  858. EOF
  859.     fi
  860.  
  861. while :
  862. do
  863.  
  864.     $DIALOG --title "SELECT GRUB PARTITION" --inputbox "`cat $TMP/tmpmsg`" 0 0 "$ROOT_DEVICE" 2> $TMP/root_device
  865.     if [ ! $? = 0 ]; then
  866.       umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  867.       rm -rf $TMP
  868.       chroot_umount
  869.       exit
  870.     fi    
  871.       ROOT_DEV=`cat $TMP/root_device`
  872.  
  873.      if [ "$ROOT_DEVICE" = "" -a "$ROOT_DEV" = "" ]; then
  874.        continue
  875.      fi
  876.  
  877.      if [ "$ROOT_DEVICE" = "$ROOT_DEV" ]; then
  878.        break
  879.      fi
  880.     
  881.        if [ ! "$ROOT_DEV" = "" ]; then
  882.          ROOT_DEVICE=`cat $TMP/root_device`
  883.        fi
  884.     
  885.         if ! grep "^$ROOT_DEVICE" $TMP/DEV | grep -q "83  Linux" ; then
  886.       $DIALOG --title "ERROR" --msgbox \
  887.           "The partition '$ROOT_DEVICE' is not Linux." 5 55
  888.       continue
  889.         fi
  890.        
  891.        if mount 2>$TMP/null | grep -q "^$ROOT_DEVICE" 2>$TMP/null ; then
  892.            BOOT="`mount 2>$TMP/null | grep $ROOT_DEVICE | cut -d ' ' -f 3`/boot"
  893.          if echo "fooboo" > $BOOT/fooboo 2>$TMP/null ; then
  894.         rm -f $BOOT/fooboo
  895.          else
  896.         $DIALOG --title "ERROR" --msgbox \
  897.            "The partition '$ROOT_DEVICE' is mounted read-only, \
  898.            either unmount it or mount it read-write." 6 55
  899.            rm -rf $TMP
  900.            chroot_umount
  901.        exit
  902.      fi
  903.            break
  904.        else
  905.        umount $BOOT_TMP 2>$TMP/null
  906.        mkdir -p $BOOT_TMP
  907.        mount -o rw $ROOT_DEVICE $BOOT_TMP 1>$TMP/null 2>$TMP/error
  908.        if [ ! $? = 0 ]; then
  909.        echo "" >> $TMP/error
  910.        echo "I couldn't mount '$ROOT_DEVICE' read-write!" >> $TMP/error
  911.        $DIALOG --title "MOUNT ERROR" --textbox "$TMP/error" 0 0
  912.        umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  913.        rm -rf $TMP
  914.        chroot_umount
  915.        exit
  916.        fi
  917.        BOOT=$BOOT_TMP/boot
  918.        break
  919.        fi
  920.  done
  921.  
  922.     $DIALOG --title "" --infobox "Working..." 3 20
  923.     sleep 1
  924.     
  925.  fs=`mount | grep "^$ROOT_DEVICE" | awk '{print $5}'`
  926.  [ "$fs" = "ext2" -o "$fs" = "ext3" ] && fs=e2fs
  927.  [ "$fs" = "msdos" ] && fs=fat
  928.  [ "$fs" = "vfat" ] && fs=fat
  929.  
  930.  if [ -d /usr/share/grub -o -d /usr/lib/grub -o -d /usr/local/share/grub ]; then
  931.    mkdir -p $BOOT/grub
  932.  if [ -d /usr/share/grub ]; then
  933.    cp -p /usr/share/grub/*/*stage* $BOOT/grub 2>$TMP/null
  934.  elif [ -d /usr/local/share/grub ]; then
  935.    cp -p /usr/local/share/grub/*/*stage* $BOOT/grub 2>$TMP/null
  936.  elif [ -d /usr/lib/grub ]; then
  937.    cp -p /usr/lib/grub/*/*stage* $BOOT/grub 2>$TMP/null
  938.  fi
  939.  
  940.  for f in stage1 stage2 $fs"_stage1_5"
  941.  do
  942.  if [ ! -f $BOOT/grub/$f ]; then
  943.  echo "ERROR: Can't find '$f' from the grub package."
  944.  echo "If you have the grub package installed, you should have a"
  945.  echo "/usr/lib/grub, /usr/share/grub, or /usr/local/share/grub"
  946.  echo "directory, containing the stage files."
  947.  chroot_umount
  948.  exit 1
  949.  fi 
  950.  done
  951.  else
  952.  echo "ERROR: Can't find stage files from the grub package."
  953.  echo "If you have the grub package installed, you should have a"
  954.  echo "/usr/lib/grub, /usr/share/grub, or /usr/local/share/grub"
  955.  echo "directory, containing the stage files."
  956.  chroot_umount
  957.  exit 1
  958.  fi
  959. }
  960.  
  961. HDR="no" # this means the header section of /boot/grub/menu.lst has not yet
  962.          # been configured
  963. LNX="no" # this means no Linux partition has been defined as bootable
  964.          # through GRUB. Both of these must change to "yes" before GRUB will
  965.          # install from this script.
  966.  
  967.  # OK, now let's see if we should automate things:
  968.  $DIALOG --title "GRUBCONFIG v1.27 Kent Robotti <robotti@godmail.com>" --menu \
  969.  "GRUB is a generic bootloader.  There's a simple installation which tries\
  970.  to automatically set up GRUB to boot Linux (also DOS, Windows, BSD, HURD,\
  971.  QNX, PLAN9, BEOS, Minix, and OS/2 if found).  For more advanced users, the expert\
  972.  option offers more control over the installation process." 13 67 2 \
  973.  "simple" "Try to install GRUB automatically" \
  974.  "expert" "Use expert GRUB setup menu" 2> $TMP/reply
  975.  if [ ! $? = 0 ]; then
  976.   rm -rf $TMP
  977.   chroot_umount
  978.   echo
  979.   exit
  980.  fi
  981.  
  982.   REPLY="`cat $TMP/reply`"
  983.  
  984.   if [ ! -r /proc/partitions ]; then
  985.     CHROOT=YES
  986.     mkdir -p /proc
  987.     mount -t proc proc /proc
  988.   fi
  989.  
  990.  if [ "$REPLY" = "simple" ]; then
  991.   # Do simple GRUB setup
  992.    use_framebuffer
  993.    $DIALOG --title "" --infobox "Working..." 3 20
  994.    sleep 1
  995.    create_devices
  996.    root_device
  997.      if [ -r /proc/sys/kernel/printk ]; then
  998.         echo 3 >/proc/sys/kernel/printk
  999.         KILL=NO
  1000.      else
  1001.         killall klogd 2>$TMP/null
  1002.         sleep 1
  1003.         klogd -c 3 2>$TMP/null
  1004.         KILL=NO
  1005.      fi
  1006.    simplegrub
  1007.    umount $BOOT_TMP 2>$TMP/null
  1008.    rm -rf $TMP $BOOT_TMP
  1009.    chroot_umount
  1010.    exit
  1011.  fi
  1012.  # drop through to last option: (use the expert menus)
  1013.  while [ 0 ]; do
  1014.   $DIALOG --title "EXPERT GRUB INSTALLATION" --menu \
  1015. "This menu directs the creation of the GRUB config file. \
  1016. To install, you make a new GRUB configuration file by creating a new header \
  1017. and then adding one or more bootable partitions to the file. Once you've done \
  1018. this, you can select the install option. If you make \
  1019. a mistake, you can always start over by choosing 'Begin'. \
  1020. Which option would you like?" 18 76 7 \
  1021. "Begin" "Start GRUB configuration with a new GRUB header" \
  1022. "Linux" "Add Linux partition to GRUB config file" \
  1023. "Other" "Add DOS/WIN/BSD/OS2/HURD partition to GRUB config file" \
  1024. "Install" "Install GRUB" \
  1025. "Skip" "Skip GRUB installation or exit this menu" \
  1026. "View" "View your current /boot/grub/$grub_config" \
  1027. "Help" "Read the GRUB Bootloader HELP file" 2> $TMP/reply
  1028.   if [ ! $? = 0 ]; then
  1029.    REPLY="Skip"
  1030.   else
  1031.    REPLY="`cat $TMP/reply`"
  1032.   fi
  1033.   if [ "$REPLY" = "Begin" ]; then
  1034.     use_framebuffer
  1035.  
  1036.     $DIALOG --title "" --infobox "Working..." 3 20
  1037.     sleep 1
  1038.  
  1039.     create_devices
  1040.  
  1041.    $DIALOG --title "SELECT GRUB TARGET LOCATION" --menu "GRUB can be installed \
  1042. to a variety of places: the master boot record of a hard drive, \
  1043. the superblock of a Linux partition (which could be made \
  1044. active with fdisk, or booted with a boot manager), or a formatted floppy disk, \
  1045. If you're using a boot system such as OS/2's Boot Manager, you should use \
  1046. the "Root" selection. Please pick a target location:" 15 68 3 \
  1047. "Root" "Use superblock of Linux partition" \
  1048. "Floppy" "Use a formatted floppy disk in the boot drive" \
  1049. "MBR" "Use the Master Boot Record (possibly unsafe)" \
  1050. 2> $TMP/reply
  1051.    if [ $? = 1 -o $? = 255 ]; then
  1052.     HDR="no"
  1053.     continue;
  1054.    else
  1055.     LNX="no"
  1056.     TG="`cat $TMP/reply`"
  1057.    fi
  1058.    if [ "$TG" = "MBR" ]; then
  1059.     hd_mbr
  1060.     MBR=YES
  1061.    elif [ "$TG" = "Root" ]; then
  1062.     MBR=NO
  1063.    elif [ "$TG" = "Floppy" ]; then
  1064.     GRUB_TARGET="/dev/fd0"    
  1065.     MBR=NO
  1066.    else
  1067.     HDR="no"
  1068.     continue;
  1069.    fi
  1070.     HDR="yes"
  1071.     root_device
  1072.   elif [ "$REPLY" = "Linux" ]; then
  1073.    if [ "$HDR" = "yes" ]; then
  1074. echo "Press the [Space] key to untag any you don't want to include." > $TMP/tmpmsg1
  1075. echo "Device Boot Start End Blocks Id System" >> $TMP/tmpmsg1
  1076. grep "^/dev/" $TMP/DEV | grep "83  Linux" | grep -v "Ext'd" | grep -v "Extend" > $TMP/tmpmsg2
  1077.  
  1078. if [ -s $TMP/tmpmsg2 ]; then
  1079. echo '$DIALOG --title "POSSIBLE LINUX PARTITIONS" --cr-wrap --checklist "`cat $TMP/tmpmsg1`" 0 0 0 \' > $TMP/tmpmsg3
  1080. cat $TMP/tmpmsg2 | sed "/^$/d" | while read device ; do
  1081. device_name="`echo "$device" | awk '{print $1}'`"
  1082. device_info="`echo "$device" | awk '{print $2,$3,$4,$5,$6,$7}'`"
  1083. echo "$device_name" | sed "/^$/d" | sed -e 's/.*/"&" '"'$device_info'"' on \\/' >> $TMP/tmpmsg3
  1084. done
  1085. echo "2> $TMP/parts" >> $TMP/tmpmsg3
  1086.  
  1087.     . $TMP/tmpmsg3
  1088.     if [ $? = 1 -o $? = 255 ]; then
  1089.      rm -f $TMP/tmpmsg*
  1090.      continue
  1091.     else
  1092.      cat $TMP/tmpmsg2 > $TMP/fdisk.list
  1093.      rm -f $TMP/tmpmsg*
  1094.     fi
  1095. else
  1096.       $DIALOG --title "" --msgbox \
  1097.      "No Linux partitions found!" 5 35
  1098.       continue
  1099. fi
  1100.     
  1101.     if [ -s $TMP/parts ]; then
  1102.       cat $TMP/parts | sed "s/\"//g" | sed "/^$/d" > $TMP/parts.a
  1103.     else
  1104.       $DIALOG --title "" --msgbox \
  1105.      "No Linux partitions chosen!" 5 35
  1106.       continue
  1107.     fi
  1108.         
  1109.     for PART in `cat $TMP/parts.a` ; do
  1110.  
  1111. cat << EOF > $TMP/tmpmsg
  1112. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  1113. `grep "^$PART" $TMP/fdisk.list`
  1114.  
  1115. Now you must select a name for the above partition.
  1116. You'll use this name to specify a partition to boot from
  1117. the GRUB menu.  Something like 'Slackware Linux' etc. might
  1118. not be a bad choice.
  1119.  
  1120. The default is 'Linux on ($PART)'.  Just press ENTER for it.
  1121. (the menu will add 'on ($PART)' for you automatically)
  1122. EOF
  1123.     $DIALOG --title "SELECT PARTITION NAME" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/reply
  1124.     if [ ! $? = 0 ]; then
  1125.      break;
  1126.     fi
  1127.      LABEL="`cat $TMP/reply`"
  1128.     if [ "$LABEL" = "" ]; then
  1129.      LABEL="Linux"
  1130.     fi    
  1131.     
  1132.   p1=`echo $PART | cut -b 9-`
  1133.   p2=$(( $p1 - 1 ))
  1134.  
  1135.   find_kernel
  1136.   get_root_dev $PART
  1137.  
  1138.   num="`echo $PART | cut -b8-`" 
  1139.  
  1140.   cat << EOF > $TMP/part.$num.sort
  1141. # Linux bootable partition config begins
  1142.   title $LABEL on ($PART)
  1143.   root ($hd,$p2)
  1144.   $KERNEL $APPEND
  1145. # Linux bootable partition config ends
  1146. EOF
  1147. initrd $PART $TMP/initrd.conf
  1148. done
  1149.    else
  1150.     $DIALOG --title "CAN'T ADD LINUX PARTITION" --msgbox "You can't add \
  1151. partitions unless you start over with a new GRUB header." 6 60
  1152.     continue
  1153.    fi
  1154.    LNX="yes"
  1155.   elif [ "$REPLY" = "Other" ]; then
  1156.    if [ "$HDR" = "yes" ]; then
  1157.    rm -f $TMP/parts
  1158. echo "Press the [Space] key to untag any you don't want to include." > $TMP/tmpmsg1
  1159. echo "Device Boot Start End Blocks Id System" >> $TMP/tmpmsg1
  1160. grep "^/dev/" $TMP/DEV | grep -E "DOS|Win95|W95|FAT|NTFS|BSD|HURD|QNX|BeOS|Minix|Plan" | \
  1161. grep -v "Ext'd" | grep -v "Extend" | grep -v -i "swap" > $TMP/tmpmsg2
  1162.  
  1163. if [ -s $TMP/tmpmsg2 ]; then
  1164. echo '$DIALOG --title "POSSIBLE DOS/WIN/OS2/BSD etc. PARTITIONS" --cr-wrap --checklist "`cat $TMP/tmpmsg1`" 0 0 0 \' > $TMP/tmpmsg3
  1165. cat $TMP/tmpmsg2 | sed "/^$/d" | while read device ; do
  1166. device_name="`echo "$device" | awk '{print $1}'`"
  1167. device_info="`echo "$device" | awk '{print $2,$3,$4,$5,$6,$7}'`"
  1168. echo "$device_name" | sed "/^$/d" | sed -e 's/.*/"&" '"'$device_info'"' on \\/' >> $TMP/tmpmsg3
  1169. done
  1170. echo "2> $TMP/parts" >> $TMP/tmpmsg3
  1171.  
  1172.     . $TMP/tmpmsg3
  1173.     if [ ! $? = 0 ]; then
  1174.      rm -f $TMP/tmpmsg*
  1175.      continue
  1176.     else
  1177.      cat $TMP/tmpmsg2 > $TMP/fdisk.list
  1178.     fi
  1179. fi
  1180.  
  1181.     if [ ! -s $TMP/tmpmsg2 ]; then
  1182.       $DIALOG --title "" --msgbox \
  1183.      "No Other partitions found!" 5 35
  1184.       rm -f $TMP/tmpmsg*
  1185.       continue
  1186.     elif [ -s $TMP/parts ]; then
  1187.       cat $TMP/parts | sed "s/\"//g" | sed "/^$/d" > $TMP/parts.a
  1188.     else
  1189.       $DIALOG --title "" --msgbox \
  1190.      "No Other partitions chosen!" 5 35
  1191.       rm -f $TMP/tmpmsg*
  1192.       continue
  1193.     fi
  1194.       rm -f $TMP/tmpmsg*
  1195.     
  1196.     for PART in `cat $TMP/parts.a` ; do
  1197. cat << EOF > $TMP/tmpmsg
  1198. `echo "   Device Boot      Start         End      Blocks   Id  System"`
  1199. `grep "^$PART" $TMP/fdisk.list`
  1200.  
  1201. Now you must select a name for the above partition.
  1202. You'll use this name to specify a partition to boot from
  1203. the GRUB menu. 'DOS, Win2k, WinXP, FreeBSD, GNU/Hurd,
  1204. etc.' might not be a bad choice.
  1205. EOF
  1206.  
  1207.     $DIALOG --title "SELECT PARTITION NAME" --cr-wrap --inputbox "`cat $TMP/tmpmsg`" 0 0 2> $TMP/reply
  1208.     if [ ! $? = 0 ]; then
  1209.      break;
  1210.     fi
  1211.      LABEL="`cat $TMP/reply`"
  1212.     if [ "$LABEL" = "" ]; then
  1213.      LABEL=Unknown
  1214.     fi    
  1215.     p1=`echo $PART | cut -b 9-`
  1216.     p2=$(( $p1 - 1 ))
  1217.  
  1218.     part=`grep "^$PART" $TMP/fdisk.list`
  1219.  
  1220.     other $part
  1221.  
  1222.     num="`echo $PART | cut -b8-`" 
  1223.  
  1224.   cat << EOF > $TMP/part.$num.sort
  1225. # Other bootable partition config begins
  1226.   title $LABEL on ($PART)
  1227.   $OTHER
  1228. # Other bootable partition config ends
  1229. EOF
  1230. done
  1231.    else
  1232.     $DIALOG --title "CAN'T ADD OTHER PARTITION" --msgbox "You can't add \
  1233. partitions unless you start over with a new GRUB header." 6 60
  1234.     continue
  1235.    fi
  1236.   elif [ "$REPLY" = "Install" ]; then
  1237.    if [ "$LNX" = "no" ]; then
  1238.     $DIALOG --title "CAN'T INSTALL GRUB" --msgbox "GRUB could not be \
  1239. installed. If you have not created a GRUB configuration file by defining \
  1240. a new header and adding at least one Linux bootable partition to it, you \
  1241. must do so before installing GRUB." 8 70
  1242.     continue
  1243.    else
  1244.        installcolor;
  1245.        umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  1246.        rm -rf $TMP
  1247.    fi
  1248.    rm -f $TMP/tmpmsg
  1249.    break
  1250.   elif [ "$REPLY" = "Skip" ]; then
  1251.    umount $BOOT_TMP 2>$TMP/null && rmdir $BOOT_TMP
  1252.    rm -rf $TMP
  1253.    chroot_umount
  1254.    break
  1255.   elif [ "$REPLY" = "View" ]; then
  1256.   
  1257.   rm -f $TMP/view.conf
  1258.   if ls $TMP/part.*.sort 2>$TMP/null ; then
  1259.   for f in `ls $TMP/part.*.sort`
  1260.   do
  1261.     cat $f >> $TMP/view.conf
  1262.   done
  1263.   fi
  1264.   
  1265.   if [ -f $TMP/initrd.conf ]; then
  1266.     cat $TMP/initrd.conf >> $TMP/view.conf
  1267.     rm -f $TMP/initrd.conf
  1268.   fi
  1269.    
  1270.    if [ -r $TMP/view.conf ]; then
  1271.     $DIALOG --title "YOUR NEW /boot/grub/$grub_config" --textbox "$TMP/view.conf" 22 70
  1272.    else
  1273.     if [ -r $BOOT/grub/$grub_config ]; then
  1274.      $DIALOG --title "YOUR CURRENT /boot/grub/$grub_config" --textbox "$BOOT/grub/$grub_config" 22 70
  1275.     else
  1276.      $DIALOG --title "NO CONFIG FILE FOUND" --msgbox "Sorry, but you don't \
  1277. have a GRUB configuration file that can be viewed." 6 60
  1278.     fi
  1279.    fi
  1280.   elif [ "$REPLY" = "Help" ]; then
  1281. cat << EOF > $TMP/tmpmsg
  1282.  
  1283. This script 'grubconfig' helps you install the GRUB bootloader
  1284. on your Linux system.
  1285.  
  1286. It supports IDE and SCSI devices and has no support for RAID devices.
  1287.  
  1288. These are the options you can use at the GRUB expert install menu:
  1289.  
  1290. 1. Start GRUB configuration with a new GRUB header.
  1291.  
  1292.    This is the first step to start a new configuration file,
  1293.    /boot/grub/$grub_config, with no OS's entered into it (yet).
  1294.  
  1295.    You'll be asked where you want to install GRUB. This
  1296.    can be to your Master Boot Record, a Linux partition's
  1297.    superblock (for OS/2's Boot Manager etc. to boot), or
  1298.    to a 1.44 MB formatted floppy disk. 
  1299.    
  1300.    Try installing to a floppy disk first, if it works
  1301.    on the floppy it will probably work on the MBR, or
  1302.    superblock.
  1303.    
  1304.    Once you've started a new /boot/grub/$grub_config file, you must
  1305.    add at least one OS to it before you can install GRUB.
  1306.  
  1307.    Next you'll want to add at least one Linux partition, the
  1308.    one that will hold the GRUB files in /boot/grub.
  1309.  
  1310.    You then may want to add other partitions, if you have any.
  1311.    
  1312. 2. Menu choices to add Linux and other DOS/WIN/BSD/OS2/HURD/QNX/
  1313.    PLAN9/BEOS/Minix partitions to the /boot/grub/$grub_config
  1314.    file.
  1315.  
  1316.    These all pretty much work the same way. You'll be asked 
  1317.    which partitions you want to include in the grub menu, and 
  1318.    you'll also be asked to assign a label to each partition.
  1319.    The label can be any name such as Redhat Linux, Slackware Linux,
  1320.    or WinXP etc.
  1321.  
  1322. 3. Install GRUB
  1323.    
  1324.    Once you've looked at your new config file and are 
  1325.    satisfied with the way it looks, pick this option to 
  1326.    install GRUB and exit the GRUB installation menu.
  1327.  
  1328. Other options:
  1329.  
  1330.   -- View your current /boot/grub/$grub_config file
  1331.  
  1332.    If you haven't begun building a new $grub_config file, this choice
  1333.    will let you take a look at the existing one in /boot/grub
  1334.    on your GRUB Linux partition. 
  1335.  
  1336.    If you have begun constructing a new $grub_config file, this
  1337.    option will let you view the progress on that.
  1338.  
  1339.  -- Skip GRUB installation or exit this menu
  1340.  
  1341.   This option skips GRUB installation. Use this if you don't 
  1342.   want to install GRUB, or if you've already installed it and 
  1343.   want to exit.
  1344.  
  1345.  -- Help - Read this GRUB Bootloader HELP file 
  1346.  
  1347. -----------
  1348.  
  1349. Other GRUB information:
  1350.  
  1351.   GRUB on the Master Boot Record can be removed easily.
  1352.    
  1353.   DOS/Win9x fdisk has a 'fdisk /mbr' option that restores the original
  1354.   master boot record. You can also restore your original boot sector from
  1355.   the copy 'grubconfig' makes in /boot/grub/mbr.device.number.
  1356.   
  1357.   This is probably the best way to go about it.
  1358.   
  1359.   # dd if=/boot/grub/mbr.device.number of=/dev/device bs=512 count=1
  1360.   
  1361.   If you want to make any changes, you don't need to run grubconfig
  1362.   again, you can just edit /boot/grub/$grub_config by hand.
  1363.   
  1364. --- end of GRUB help
  1365.  
  1366. grubconfig is based on liloconfig by Patrick Volkerding fron the
  1367. Slackware Linux distribution.
  1368. EOF
  1369.    $DIALOG --title "GRUB INSTALLATION HELP" --textbox "$TMP/tmpmsg" 22 74
  1370.   fi
  1371.  done
  1372.  
  1373.