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.

160 lines
4.7 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 - 2005 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. convert_device () {
  32. device="$1"
  33. # extract device type (block) and major number for root drive
  34. user_drive_maj=`ls -Ll $device |
  35. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  36. # does your bios know about the above drive?
  37. for bios_drive in `grep -v '^#' /boot/grub/device.map|awk '{print $2}'`; do
  38. bios_drive_maj=`ls -l $bios_drive |
  39. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  40. if [ "$user_drive_maj" = "$bios_drive_maj" ]; then
  41. # yupi ya yeh! we found your drive!
  42. root_drive=`grep $bios_drive /boot/grub/device.map | awk '{print $1}'`
  43. tmp_part=`ls -Ll $device | awk '{print $6}'`
  44. break
  45. fi
  46. done
  47. # convert the partition number to GRUB style
  48. if [ $tmp_part -gt 64 ]; then
  49. # hd[bdfh]
  50. # this doesn't handle the disk itself correctly - just the partitions
  51. root_part=$[$tmp_part-65]
  52. else
  53. root_part=$[$tmp_part-1]
  54. fi
  55. unset tmp_part
  56. drive=`echo $root_drive | sed "s:)$:,$root_part):"`
  57. # Do we need some user confirmation to this result???
  58. # ...
  59. unset device
  60. echo $drive
  61. }
  62. create_boot_menu() {
  63. cat << EOT > /boot/grub/menu.lst
  64. timeout 8
  65. default 0
  66. fallback 1
  67. title ROCK Linux
  68. kernel $bootdrive$bootpath/vmlinuz root=$rootdev ro
  69. initrd $bootdrive$bootpath/initrd.img
  70. EOT
  71. if [ -f /boot/memtest86.bin ] ; then
  72. cat << EOT >> /boot/grub/menu.lst
  73. title MemTest86 (SGI memory tester)
  74. kernel $bootdrive$bootpath/memtest86.bin
  75. EOT
  76. fi
  77. gui_message "This is the new /boot/grub/menu.lst file:
  78. $( cat /boot/grub/menu.lst )"
  79. }
  80. grub_install() {
  81. gui_cmd 'Installing GRUB' "echo -e 'root $bootdrive\\nsetup (hd0)\\nquit' | grub --batch --device-map=/boot/grub/device.map"
  82. }
  83. grub_init() {
  84. rootdev="`grep ' / ' /proc/mounts | tail -n 1 | \
  85. awk '/\/dev\// { print $1; }'`"
  86. bootdev="`grep ' /boot ' /proc/mounts | tail -n 1 | \
  87. awk '/\/dev\// { print $1; }'`"
  88. [ -z "$bootdev" ] && bootdev="$rootdev"
  89. i=0
  90. rootdev="$( cd `dirname $rootdev` ; pwd -P )/$( basename $rootdev )"
  91. while [ -L $rootdev ] ; do
  92. directory="$( cd `dirname $rootdev` ; pwd -P )"
  93. rootdev="$( ls -l $rootdev | sed 's,.* -> ,,' )"
  94. [ "${rootdev##/*}" ] && rootdev="$directory/$rootdev"
  95. i=$(( $i + 1 )) ; [ $i -gt 20 ] && rootdev="Not found!"
  96. done
  97. i=0
  98. bootdev="$( cd `dirname $bootdev` ; pwd -P )/$( basename $bootdev )"
  99. while [ -L $bootdev ] ; do
  100. directory="$( cd `dirname $bootdev` ; pwd -P )"
  101. bootdev="$( ls -l $bootdev | sed 's,.* -> ,,' )"
  102. [ "${bootdev##/*}" ] && bootdev="$directory/$bootdev"
  103. i=$(( $i + 1 )) ; [ $i -gt 20 ] && bootdev="Not found!"
  104. done
  105. if [ -s /boot/grub/device.map ] ; then
  106. rootdrive=`convert_device $rootdev`
  107. bootdrive=`convert_device $bootdev`
  108. else
  109. rootdrive='No Device Map found!'
  110. bootdrive='No Device Map found!'
  111. fi
  112. if [ "$rootdrive" = "$bootdrive" ]
  113. then bootpath="/boot" ; else bootpath="" ; fi
  114. }
  115. grub_setup() {
  116. if gui_yesno "Do you want to install the GRUB bootloader in MBR now?"; then
  117. grub_init; create_device_map
  118. grub_init; create_boot_menu
  119. grub_init; grub_install
  120. fi
  121. }
  122. main() {
  123. while
  124. grub_init
  125. gui_menu grub 'GRUB Boot Loader Setup' \
  126. '(Re-)Create GRUB Device Map' 'create_device_map' \
  127. "Root Device ... $rootdev" "" \
  128. "Boot Drive .... $bootdrive$boot_path" "" \
  129. '' '' \
  130. '(Re-)Create default boot menu' 'create_boot_menu' \
  131. '(Re-)Install GRUB in MBR of (hd0)' 'grub_install' \
  132. '' '' \
  133. "Edit /boot/grub/device.map (Device Map)" \
  134. "gui_edit 'GRUB Device Map' /boot/grub/device.map" \
  135. "Edit /boot/grub/menu.lst (Boot Menu)" \
  136. "gui_edit 'GRUB Boot Menu' /boot/grub/menu.lst"
  137. do : ; done
  138. }