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.

198 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. ( set -x
  27. rm -f /boot/grub/device.map
  28. grub-mkdevicemap --no-floppy; )
  29. EOT
  30. )"
  31. }
  32. normalize_device() {
  33. local master_devid this_devid this_devname
  34. local device="$1"
  35. master_devid="`ls -lL $device | awk '{print $5 $6;}'`"
  36. while read this_devid this_devname; do
  37. if [ "$this_devid" = "$master_devid" ]; then
  38. device="$this_devname"
  39. fi
  40. done < <( ls -lL --time-style='+xx' /dev/[hs]d[a-z]* |
  41. awk '{print $5 $6 " " $8;}'; )
  42. echo "$device"
  43. }
  44. convert_device () {
  45. device="$1"
  46. # extract device type (block) and major number for root drive
  47. user_drive_maj=`ls -Ll $device |
  48. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  49. # does the bios know about the above drive?
  50. tmp_part=""
  51. for bios_drive in `grep -v '^#' /boot/grub/device.map|awk '{print $2}'`; do
  52. test -e $bios_drive || continue
  53. bios_drive_maj=`ls -Ll $bios_drive |
  54. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  55. if [ "$user_drive_maj" = "$bios_drive_maj" ]; then
  56. # yupi ya yeh! we found the drive!
  57. root_drive=`grep $bios_drive /boot/grub/device.map | awk '{print $1}'`
  58. tmp_part=`ls -Ll $device | awk '{print $6}'`
  59. break
  60. fi
  61. done
  62. # give up
  63. if [ -z "$tmp_part" ]; then
  64. echo "(unknown)"
  65. return
  66. fi
  67. # convert the partition number to GRUB style
  68. if [ $tmp_part -gt 64 ]; then
  69. # hd[bdfh]
  70. # this doesn't handle the disk itself correctly - just the partitions
  71. root_part=$[$tmp_part-65]
  72. else
  73. root_part=$[$tmp_part-1]
  74. fi
  75. unset tmp_part
  76. drive=`echo $root_drive | sed "s:)$:,$root_part):"`
  77. # Do we need some user confirmation to this result???
  78. # ...
  79. unset device
  80. echo $drive
  81. }
  82. create_boot_menu() {
  83. cat << EOT > /boot/grub/grub.cfg
  84. timeout 8
  85. default 0
  86. fallback 1
  87. title ROCK Linux
  88. linux $bootdrive$bootpath/vmlinuz root=/dev/ram0 ro
  89. initrd $bootdrive$bootpath/initrd.img
  90. EOT
  91. if [ -f /boot/memtest86.bin ] ; then
  92. cat << EOT >> /boot/grub/grub.cfg
  93. title MemTest86 (SGI memory tester)
  94. linux $bootdrive$bootpath/memtest86.bin
  95. EOT
  96. fi
  97. gui_message "This is the new /boot/grub/grub.cfg file:
  98. $( cat /boot/grub/grub.cfg )"
  99. }
  100. grub_install() {
  101. gui_cmd 'Installing GRUB' "$( cat << "EOT"
  102. ( set -x
  103. grub-mkimage -o /boot/grub/core.img _chain pc ext2
  104. grub-setup -r $bootdrive '(hd0)'; )
  105. EOT
  106. )"
  107. }
  108. grub_init() {
  109. rootdev="`grep ' / ' /proc/mounts | tail -n 1 | \
  110. awk '/\/dev\// { print $1; }'`"
  111. bootdev="`grep ' /boot ' /proc/mounts | tail -n 1 | \
  112. awk '/\/dev\// { print $1; }'`"
  113. if [ "$rootdev" = "/dev/root" -a '!' -e /dev/root ]; then
  114. rootdev="`cat /proc/cmdline | tr ' ' '\n' | \
  115. grep '^root=' | cut -f2- -d= | head -n1`"
  116. fi
  117. [ -z "$bootdev" ] && bootdev="$rootdev"
  118. rootdev=`normalize_device $rootdev`
  119. bootdev=`normalize_device $bootdev`
  120. # i=0
  121. # rootdev="$( cd `dirname $rootdev` ; pwd -P )/$( basename $rootdev )"
  122. # while [ -L $rootdev ] ; do
  123. # directory="$( cd `dirname $rootdev` ; pwd -P )"
  124. # rootdev="$( ls -l $rootdev | sed 's,.* -> ,,' )"
  125. # [ "${rootdev##/*}" ] && rootdev="$directory/$rootdev"
  126. # i=$(( $i + 1 )) ; [ $i -gt 20 ] && rootdev="Not found!"
  127. # done
  128. # i=0
  129. # bootdev="$( cd `dirname $bootdev` ; pwd -P )/$( basename $bootdev )"
  130. # while [ -L $bootdev ] ; do
  131. # directory="$( cd `dirname $bootdev` ; pwd -P )"
  132. # bootdev="$( ls -l $bootdev | sed 's,.* -> ,,' )"
  133. # [ "${bootdev##/*}" ] && bootdev="$directory/$bootdev"
  134. # i=$(( $i + 1 )) ; [ $i -gt 20 ] && bootdev="Not found!"
  135. # done
  136. if [ -s /boot/grub/device.map ] ; then
  137. rootdrive=`convert_device $rootdev`
  138. bootdrive=`convert_device $bootdev`
  139. else
  140. rootdrive='No Device Map found!'
  141. bootdrive='No Device Map found!'
  142. fi
  143. if [ "$rootdrive" = "$bootdrive" ]
  144. then bootpath="/boot" ; else bootpath="" ; fi
  145. }
  146. grub_setup() {
  147. if gui_yesno "Do you want to install the GRUB bootloader in MBR now?"; then
  148. grub_init; create_device_map
  149. grub_init; create_boot_menu
  150. grub_init; grub_install
  151. fi
  152. }
  153. main() {
  154. while
  155. grub_init
  156. gui_menu grub 'GRUB Boot Loader Setup' \
  157. '(Re-)Create GRUB Device Map' 'create_device_map' \
  158. "Root Device ... $rootdev" "" \
  159. "Boot Drive .... $bootdrive$boot_path" "" \
  160. '' '' \
  161. '(Re-)Create default boot menu' 'create_boot_menu' \
  162. '(Re-)Install GRUB in MBR of (hd0)' 'grub_install' \
  163. '' '' \
  164. "Edit /boot/grub/device.map (Device Map)" \
  165. "gui_edit 'GRUB Device Map' /boot/grub/device.map" \
  166. "Edit /boot/grub/grub.cfg (Boot Menu)" \
  167. "gui_edit 'GRUB Boot Menu' /boot/grub/grub.cfg"
  168. do : ; done
  169. }