mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
6.1 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/package/x86/grub/stone_mod_grub.sh
  9. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. #
  23. # [MAIN] 70 grub GRUB Boot Loader Setup
  24. create_device_map() {
  25. gui_cmd '(Re-)Create GRUB Device Map' "$( cat << "EOT"
  26. rm -vf /boot/grub/device.map
  27. echo quit | grub --batch --device-map=/boot/grub/device.map
  28. EOT
  29. )"
  30. }
  31. normalize_device() {
  32. local master_devid this_devid this_devname
  33. local device="$1"
  34. master_devid="`ls -lL $device | awk '{print $5 $6;}'`"
  35. while read this_devid this_devname; do
  36. if [ "$this_devid" = "$master_devid" ]; then
  37. device="$this_devname"
  38. fi
  39. done < <( ls -lL --time-style='+xx' /dev/[hs]d[a-z]* |
  40. awk '{print $5 $6 " " $8;}'; )
  41. echo "$device"
  42. }
  43. convert_device () {
  44. device="$1"
  45. # extract device type (block) and major number for root drive
  46. user_drive_maj=`ls -Ll $device |
  47. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  48. # does the bios know about the above drive?
  49. tmp_part=""
  50. for bios_drive in `grep -v '^#' /boot/grub/device.map|awk '{print $2}'`; do
  51. test -e $bios_drive || continue
  52. bios_drive_maj=`ls -Ll $bios_drive |
  53. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  54. if [ "$user_drive_maj" = "$bios_drive_maj" ]; then
  55. # yupi ya yeh! we found the drive!
  56. root_drive=`grep $bios_drive /boot/grub/device.map | awk '{print $1}'`
  57. tmp_part=`ls -Ll $device | awk '{print $6}'`
  58. break
  59. fi
  60. done
  61. # give up
  62. if [ -z "$tmp_part" ]; then
  63. echo "(unknown)"
  64. return
  65. fi
  66. # convert the partition number to GRUB style
  67. if [ $tmp_part -gt 64 ]; then
  68. # hd[bdfh]
  69. # this doesn't handle the disk itself correctly - just the partitions
  70. root_part=$[$tmp_part-65]
  71. else
  72. root_part=$[$tmp_part-1]
  73. fi
  74. unset tmp_part
  75. drive=`echo $root_drive | sed "s:)$:,$root_part):"`
  76. # Do we need some user confirmation to this result???
  77. # ...
  78. unset device
  79. echo $drive
  80. }
  81. create_boot_menu() {
  82. cat << EOT > /boot/grub/menu.lst
  83. timeout 8
  84. default 0
  85. title ROCKate 1024
  86. kernel $bootdrive$bootpath/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x317 rw
  87. initrd $bootdrive$bootpath/initrd.img
  88. title ROCKate 1280
  89. kernel $bootdrive$bootpath/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x31A rw
  90. initrd $bootdrive$bootpath/initrd.img
  91. title ROCKate 800
  92. kernel $bootdrive$bootpath/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x314 rw
  93. initrd $bootdrive$bootpath/initrd.img
  94. title ROCKate 640
  95. kernel $bootdrive$bootpath/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x311 rw
  96. initrd $bootdrive$bootpath/initrd.img
  97. title ROCKate Text only
  98. kernel $bootdrive$bootpath/vmlinuz root=/dev/ram init=/linuxrc vga=0 rw 3
  99. initrd $bootdrive$bootpath/initrd.img
  100. EOT
  101. if [ -f /boot/memtest86.bin ] ; then
  102. cat << EOT >> /boot/grub/menu.lst
  103. title MemTest86 (SGI memory tester)
  104. kernel $bootdrive$bootpath/memtest86.bin
  105. EOT
  106. fi
  107. gui_message "This is the new /boot/grub/menu.lst file:
  108. $( cat /boot/grub/menu.lst )"
  109. }
  110. grub_install() {
  111. gui_cmd 'Installing GRUB' "echo -e 'root $bootdrive\\nsetup (hd0)\\nquit' | grub --batch --device-map=/boot/grub/device.map"
  112. }
  113. grub_init() {
  114. rootdev="`grep ' / ' /proc/mounts | tail -n 1 | \
  115. awk '/\/dev\// { print $1; }'`"
  116. bootdev="`grep ' /boot ' /proc/mounts | tail -n 1 | \
  117. awk '/\/dev\// { print $1; }'`"
  118. if [ "$rootdev" = "/dev/root" -a '!' -e /dev/root ]; then
  119. rootdev="`cat /proc/cmdline | tr ' ' '\n' | \
  120. grep '^root=' | cut -f2- -d= | head -n1`"
  121. fi
  122. [ -z "$bootdev" ] && bootdev="$rootdev"
  123. rootdev=`normalize_device $rootdev`
  124. bootdev=`normalize_device $bootdev`
  125. # i=0
  126. # rootdev="$( cd `dirname $rootdev` ; pwd -P )/$( basename $rootdev )"
  127. # while [ -L $rootdev ] ; do
  128. # directory="$( cd `dirname $rootdev` ; pwd -P )"
  129. # rootdev="$( ls -l $rootdev | sed 's,.* -> ,,' )"
  130. # [ "${rootdev##/*}" ] && rootdev="$directory/$rootdev"
  131. # i=$(( $i + 1 )) ; [ $i -gt 20 ] && rootdev="Not found!"
  132. # done
  133. # i=0
  134. # bootdev="$( cd `dirname $bootdev` ; pwd -P )/$( basename $bootdev )"
  135. # while [ -L $bootdev ] ; do
  136. # directory="$( cd `dirname $bootdev` ; pwd -P )"
  137. # bootdev="$( ls -l $bootdev | sed 's,.* -> ,,' )"
  138. # [ "${bootdev##/*}" ] && bootdev="$directory/$bootdev"
  139. # i=$(( $i + 1 )) ; [ $i -gt 20 ] && bootdev="Not found!"
  140. # done
  141. if [ -s /boot/grub/device.map ] ; then
  142. rootdrive=`convert_device $rootdev`
  143. bootdrive=`convert_device $bootdev`
  144. else
  145. rootdrive='No Device Map found!'
  146. bootdrive='No Device Map found!'
  147. fi
  148. if [ "$rootdrive" = "$bootdrive" ]
  149. then bootpath="/boot" ; else bootpath="" ; fi
  150. }
  151. grub_setup() {
  152. if gui_yesno "Do you want to install the GRUB bootloader in MBR now?"; then
  153. grub_init; create_device_map
  154. grub_init; create_boot_menu
  155. grub_init; grub_install
  156. fi
  157. }
  158. main() {
  159. while
  160. grub_init
  161. gui_menu grub 'GRUB Boot Loader Setup' \
  162. '(Re-)Create GRUB Device Map' 'create_device_map' \
  163. "Root Device ... $rootdev" "" \
  164. "Boot Drive .... $bootdrive$boot_path" "" \
  165. '' '' \
  166. '(Re-)Create default boot menu' 'create_boot_menu' \
  167. '(Re-)Install GRUB in MBR of (hd0)' 'grub_install' \
  168. '' '' \
  169. "Edit /boot/grub/device.map (Device Map)" \
  170. "gui_edit 'GRUB Device Map' /boot/grub/device.map" \
  171. "Edit /boot/grub/menu.lst (Boot Menu)" \
  172. "gui_edit 'GRUB Boot Menu' /boot/grub/menu.lst"
  173. do : ; done
  174. }