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.

192 lines
5.5 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. fallback 1
  86. title ROCK Linux
  87. kernel $bootdrive$bootpath/vmlinuz root=/dev/ram0 ro
  88. initrd $bootdrive$bootpath/initrd.img
  89. EOT
  90. if [ -f /boot/memtest86.bin ] ; then
  91. cat << EOT >> /boot/grub/menu.lst
  92. title MemTest86 (SGI memory tester)
  93. kernel $bootdrive$bootpath/memtest86.bin
  94. EOT
  95. fi
  96. gui_message "This is the new /boot/grub/menu.lst file:
  97. $( cat /boot/grub/menu.lst )"
  98. }
  99. grub_install() {
  100. gui_cmd 'Installing GRUB' "echo -e 'root $bootdrive\\nsetup (hd0)\\nquit' | grub --batch --device-map=/boot/grub/device.map"
  101. }
  102. grub_init() {
  103. rootdev="`grep ' / ' /proc/mounts | tail -n 1 | \
  104. awk '/\/dev\// { print $1; }'`"
  105. bootdev="`grep ' /boot ' /proc/mounts | tail -n 1 | \
  106. awk '/\/dev\// { print $1; }'`"
  107. if [ "$rootdev" = "/dev/root" -a '!' -e /dev/root ]; then
  108. rootdev="`cat /proc/cmdline | tr ' ' '\n' | \
  109. grep '^root=' | cut -f2- -d= | head -n1`"
  110. fi
  111. [ -z "$bootdev" ] && bootdev="$rootdev"
  112. rootdev=`normalize_device $rootdev`
  113. bootdev=`normalize_device $bootdev`
  114. # i=0
  115. # rootdev="$( cd `dirname $rootdev` ; pwd -P )/$( basename $rootdev )"
  116. # while [ -L $rootdev ] ; do
  117. # directory="$( cd `dirname $rootdev` ; pwd -P )"
  118. # rootdev="$( ls -l $rootdev | sed 's,.* -> ,,' )"
  119. # [ "${rootdev##/*}" ] && rootdev="$directory/$rootdev"
  120. # i=$(( $i + 1 )) ; [ $i -gt 20 ] && rootdev="Not found!"
  121. # done
  122. # i=0
  123. # bootdev="$( cd `dirname $bootdev` ; pwd -P )/$( basename $bootdev )"
  124. # while [ -L $bootdev ] ; do
  125. # directory="$( cd `dirname $bootdev` ; pwd -P )"
  126. # bootdev="$( ls -l $bootdev | sed 's,.* -> ,,' )"
  127. # [ "${bootdev##/*}" ] && bootdev="$directory/$bootdev"
  128. # i=$(( $i + 1 )) ; [ $i -gt 20 ] && bootdev="Not found!"
  129. # done
  130. if [ -s /boot/grub/device.map ] ; then
  131. rootdrive=`convert_device $rootdev`
  132. bootdrive=`convert_device $bootdev`
  133. else
  134. rootdrive='No Device Map found!'
  135. bootdrive='No Device Map found!'
  136. fi
  137. if [ "$rootdrive" = "$bootdrive" ]
  138. then bootpath="/boot" ; else bootpath="" ; fi
  139. }
  140. grub_setup() {
  141. if gui_yesno "Do you want to install the GRUB bootloader in MBR now?"; then
  142. grub_init; create_device_map
  143. grub_init; create_boot_menu
  144. grub_init; grub_install
  145. fi
  146. }
  147. main() {
  148. while
  149. grub_init
  150. gui_menu grub 'GRUB Boot Loader Setup' \
  151. '(Re-)Create GRUB Device Map' 'create_device_map' \
  152. "Root Device ... $rootdev" "" \
  153. "Boot Drive .... $bootdrive$boot_path" "" \
  154. '' '' \
  155. '(Re-)Create default boot menu' 'create_boot_menu' \
  156. '(Re-)Install GRUB in MBR of (hd0)' 'grub_install' \
  157. '' '' \
  158. "Edit /boot/grub/device.map (Device Map)" \
  159. "gui_edit 'GRUB Device Map' /boot/grub/device.map" \
  160. "Edit /boot/grub/menu.lst (Boot Menu)" \
  161. "gui_edit 'GRUB Boot Menu' /boot/grub/menu.lst"
  162. do : ; done
  163. }