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.

144 lines
4.4 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 - 2003 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. title MemTest86 (SGI memory tester)
  71. kernel $bootdrive$bootpath/memtest86.bin
  72. EOT
  73. gui_message "This is the new /boot/grub/menu.lst file:
  74. $( cat /boot/grub/menu.lst )"
  75. }
  76. grub_install() {
  77. gui_cmd 'Installing GRUB' "echo -e 'root $bootdrive\\nsetup (hd0)\\nquit' | grub --batch --device-map=/boot/grub/device.map"
  78. }
  79. main() {
  80. while
  81. rootdev="`grep ' / ' /proc/mounts | tail -1 | \
  82. awk '/\/dev\// { print $1; }'`"
  83. bootdev="`grep ' /boot ' /proc/mounts | tail -1 | \
  84. awk '/\/dev\// { print $1; }'`"
  85. [ -z "$bootdev" ] && bootdev="$rootdev"
  86. i=0
  87. rootdev="$( cd `dirname $rootdev` ; pwd -P )/$( basename $rootdev )"
  88. while [ -L $rootdev ] ; do
  89. directory="$( cd `dirname $rootdev` ; pwd -P )"
  90. rootdev="$( ls -l $rootdev | sed 's,.* -> ,,' )"
  91. [ "${rootdev##/*}" ] && rootdev="$directory/$rootdev"
  92. i=$(( $i + 1 )) ; [ $i -gt 20 ] && rootdev="Not found!"
  93. done
  94. i=0
  95. bootdev="$( cd `dirname $bootdev` ; pwd -P )/$( basename $bootdev )"
  96. while [ -L $bootdev ] ; do
  97. directory="$( cd `dirname $bootdev` ; pwd -P )"
  98. bootdev="$( ls -l $bootdev | sed 's,.* -> ,,' )"
  99. [ "${bootdev##/*}" ] && bootdev="$directory/$bootdev"
  100. i=$(( $i + 1 )) ; [ $i -gt 20 ] && bootdev="Not found!"
  101. done
  102. if [ -s /boot/grub/device.map ] ; then
  103. rootdrive=`convert_device $rootdev`
  104. bootdrive=`convert_device $bootdev`
  105. else
  106. rootdrive='No Device Map found!'
  107. bootdrive='No Device Map found!'
  108. fi
  109. if [ "$rootdrive" = "$bootdrive" ]
  110. then bootpath="/boot" ; else bootpath="" ; fi
  111. gui_menu grub 'GRUB Boot Loader Setup' \
  112. '(Re-)Create GRUB Device Map' 'create_device_map' \
  113. "Root Device ... $rootdev" "" \
  114. "Boot Drive .... $bootdrive$boot_path" "" \
  115. '' '' \
  116. '(Re-)Create default boot menu' 'create_boot_menu' \
  117. '(Re-)Install GRUB in MBR of (hd0)' 'grub_install' \
  118. '' '' \
  119. "Edit /boot/grub/device.map (Device Map)" \
  120. "gui_edit 'GRUB Device Map' /boot/grub/device.map" \
  121. "Edit /boot/grub/menu.lst (Boot Menu)" \
  122. "gui_edit 'GRUB Boot Menu' /boot/grub/menu.lst"
  123. do : ; done
  124. }