OpenSDE Packages Database (without history before r20070)
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.

181 lines
5.0 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../grub/stone_mod_grub.sh
  5. # Copyright (C) 2006 - 2008 The OpenSDE Project
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. # Copyright (C) 1998 - 2003 Clifford Wolf
  8. #
  9. # More information can be found in the files COPYING and README.
  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; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. #
  17. # [MAIN] 70 grub GRUB Boot Loader Setup
  18. # [SETUP] 90 grub
  19. create_kernel_list() {
  20. first=1
  21. for x in `(cd /boot/ ; ls vmlinuz_* ) | sort -r` ; do
  22. ver=${x/vmlinuz_/}
  23. if [ $first = 1 ] ; then
  24. label=linux ; first=0
  25. else
  26. label=linux-$ver
  27. fi
  28. cat << EOT
  29. title $label
  30. kernel $bootdrive$bootpath/$x root=$rootdev ro
  31. initrd $bootdrive$bootpath/initrd-${ver}.img
  32. EOT
  33. done
  34. }
  35. create_device_map() {
  36. gui_cmd '(Re-)Create GRUB Device Map' "$( cat << "EOT"
  37. rm -vf /boot/grub/device.map
  38. echo quit | grub --batch --device-map=/boot/grub/device.map
  39. EOT
  40. )"
  41. }
  42. convert_device () {
  43. device="$1"
  44. # extract device type (block) and major number for root drive
  45. user_drive_maj=`ls -Ll $device |
  46. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  47. # does your bios know about the above drive?
  48. for bios_drive in `grep -v '^#' /boot/grub/device.map|awk '{print $2}'`; do
  49. bios_drive_maj=`ls -l $bios_drive |
  50. awk '{if ($6 < 64) printf("%c%d0", $1, $5); else printf("%c%d1", $1, $5)}'`
  51. if [ "$user_drive_maj" = "$bios_drive_maj" ]; then
  52. # yupi ya yeh! we found your drive!
  53. root_drive=`grep $bios_drive /boot/grub/device.map | awk '{print $1}'`
  54. tmp_part=`ls -Ll $device | awk '{print $6}'`
  55. break
  56. fi
  57. done
  58. # convert the partition number to GRUB style
  59. if [ $tmp_part -gt 64 ]; then
  60. # hd[bdfh]
  61. # this doesn't handle the disk itself correctly - just the partitions
  62. root_part=$[$tmp_part-65]
  63. else
  64. root_part=$[$tmp_part-1]
  65. fi
  66. unset tmp_part
  67. drive=`echo $root_drive | sed "s:)$:,$root_part):"`
  68. # Do we need some user confirmation to this result???
  69. # ...
  70. unset device
  71. echo $drive
  72. }
  73. create_boot_menu() {
  74. cat << EOT > /boot/grub/menu.lst
  75. timeout 8
  76. default 0
  77. fallback 1
  78. EOT
  79. [ -f /boot/opensde-grub-splash.xpm.gz ] && cat << EOT >> /boot/grub/menu.lst
  80. foreground = 000000
  81. background = e4e6e3
  82. splashimage $bootdrive$bootpath/opensde-grub-splash.xpm.gz
  83. EOT
  84. create_kernel_list >> /boot/grub/menu.lst
  85. [ -f /boot/memtest86.bin ] && cat << EOT >> /boot/grub/menu.lst
  86. title MemTest86 (memory tester)
  87. kernel $bootdrive$bootpath/memtest86.bin
  88. EOT
  89. gui_message "This is the new /boot/grub/menu.lst file:
  90. $( cat /boot/grub/menu.lst )"
  91. }
  92. grub_install() {
  93. gui_cmd 'Installing GRUB' "echo -e 'root $bootdrive\\nsetup (hd0)\\nquit' | grub --batch --device-map=/boot/grub/device.map"
  94. }
  95. main() {
  96. rootdev="`grep ' / ' /proc/mounts | tail -n 1 | \
  97. awk '/\/dev\// { print $1; }'`"
  98. bootdev="`grep ' /boot ' /proc/mounts | tail -n 1 | \
  99. awk '/\/dev\// { print $1; }'`"
  100. [ -z "$bootdev" ] && bootdev="$rootdev"
  101. i=0
  102. rootdev="$( cd `dirname $rootdev` ; pwd -P )/$( basename $rootdev )"
  103. while [ -L $rootdev ] ; do
  104. directory="$( cd `dirname $rootdev` ; pwd -P )"
  105. rootdev="$( ls -l $rootdev | sed 's,.* -> ,,' )"
  106. [ "${rootdev##/*}" ] && rootdev="$directory/$rootdev"
  107. i=$(( $i + 1 )) ; [ $i -gt 20 ] && rootdev="Not found!"
  108. done
  109. i=0
  110. bootdev="$( cd `dirname $bootdev` ; pwd -P )/$( basename $bootdev )"
  111. while [ -L $bootdev ] ; do
  112. directory="$( cd `dirname $bootdev` ; pwd -P )"
  113. bootdev="$( ls -l $bootdev | sed 's,.* -> ,,' )"
  114. [ "${bootdev##/*}" ] && bootdev="$directory/$bootdev"
  115. i=$(( $i + 1 )) ; [ $i -gt 20 ] && bootdev="Not found!"
  116. done
  117. if [ -s /boot/grub/device.map ] ; then
  118. rootdrive=`convert_device $rootdev`
  119. bootdrive=`convert_device $bootdev`
  120. else
  121. rootdrive='No Device Map found!'
  122. bootdrive='No Device Map found!'
  123. fi
  124. if [ "$rootdev" = "$bootdev" ]
  125. then bootpath="/boot" ; else bootpath= ; fi
  126. if [ ! -f /boot/grub/menu.lst ] ; then
  127. if gui_yesno "GRUB does not appear to be configured.
  128. Automatically install GRUB now?"; then
  129. create_device_map
  130. rootdrive=`convert_device $rootdev`
  131. bootdrive=`convert_device $bootdev`
  132. create_boot_menu
  133. if ! grub_install; then
  134. gui_message "There was an error while installing GRUB."
  135. fi
  136. fi
  137. fi
  138. while
  139. gui_menu grub 'GRUB Boot Loader Setup' \
  140. '(Re-)Create GRUB Device Map' 'create_device_map' \
  141. "Root Device ... $rootdev" "" \
  142. "Boot Drive .... $bootdrive$boot_path" "" \
  143. '' '' \
  144. '(Re-)Create boot menu with installed kernels' 'create_boot_menu' \
  145. '(Re-)Install GRUB in MBR of (hd0)' 'grub_install' \
  146. '' '' \
  147. "Edit /boot/grub/device.map (Device Map)" \
  148. "gui_edit 'GRUB Device Map' /boot/grub/device.map" \
  149. "Edit /boot/grub/menu.lst (Boot Menu)" \
  150. "gui_edit 'GRUB Boot Menu' /boot/grub/menu.lst"
  151. do : ; done
  152. }