MenuBootloader 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #! /bin/bash -
  2. #
  3. # This file is part of the 'dragora-installer'.
  4. #
  5. # Purpose: Installation of GRUB boot loader into /media/dragora-root.
  6. # Exit immediately on any error
  7. set -e
  8. # Make sure to have /proc and /dev available to install GRUB
  9. if ! mountpoint -q /media/dragora-root/dev
  10. then
  11. mount --bind /dev /media/dragora-root/dev
  12. fi
  13. if ! mountpoint -q /media/dragora-root/proc
  14. then
  15. mount -t proc proc /media/dragora-root/proc
  16. fi
  17. if ! mountpoint -q /media/dragora-root/sys
  18. then
  19. mount -t sysfs sysfs /media/dragora-root/sys
  20. fi
  21. # Loop for the main menu
  22. while true
  23. do
  24. dialog --colors \
  25. --backtitle "\\ZbBoot loader installation" \
  26. --title "GRand Unified Bootloader" \
  27. --default-button "${_default_button:-ok}" \
  28. --ok-label "Install" \
  29. --cancel-label "Ignore & Continue" \
  30. --menu \
  31. "It's time to install a boot loader (GNU GRUB).\\n\\n\
  32. If you do not have a boot loader, it is recommended to install it in\\n\
  33. the Master Boot Record (MBR). It is possible to overwrite your current \
  34. boot loader.\\n\\n\
  35. You can also install the boot loader on the Root partition (superblock), \
  36. but note that the partition needs the boot flag to boot. If you have not \
  37. used this flag before when you created the partitions you can do so later \
  38. by invoking 'cfdisk' or 'fdisk'." 19 72 2 \
  39. "0" "Install GRUB on the Master Boot Record" \
  40. "1" "Install GRUB on the Super block" \
  41. 2> "${SUBTMPDIR}/return-MenuBootloader" || _status=$?
  42. if test -n "$_status" && test $_status -gt 0
  43. then
  44. if test $_status -eq 1
  45. then
  46. return 0 # Ignore exit status on 'Cancel'.
  47. fi
  48. return "$_status" # Any other dialog(1) code.
  49. fi
  50. answer="$(cat -- "${SUBTMPDIR}"/return-MenuBootloader)"
  51. # Check for selected options
  52. case $answer in
  53. 0 | 1) ## Master Boot Record or Super block
  54. # Defining the title of the subsequent menu
  55. if test "$answer" = 0
  56. then
  57. _submenu_title="Master Boot Record"
  58. else
  59. _submenu_title="Super block"
  60. fi
  61. # Check if it is a logical volume
  62. if pvs | grep -q dev
  63. then
  64. array=()
  65. pvs --ignorelockingfailure --noheadings | awk '{ print $1 }' | \
  66. while IFS='' read -r line
  67. do
  68. array+=("$line")
  69. done
  70. # Verify in which partition to install
  71. if (( ${#array[*]} > 1 ))
  72. then
  73. i=0
  74. for partition in "${array[@]}"
  75. do
  76. partition="${partition/[0-9]*/}"
  77. xlist[i++]=$partition
  78. xlist[i++]=""
  79. done
  80. unset -v i partition
  81. # Remove possible duplicate elements
  82. xlist=( $(printf '%s\n' "${xlist[@]}" | awk '!s[$0]++') )
  83. dialog --colors \
  84. --backtitle "\\ZbBoot loader installation" \
  85. --title "$_submenu_title" \
  86. --menu \
  87. "More than one disk or partition has been detected.\\n\\n\
  88. Please select the boot loader destination:" 0 0 0 "${xlist[@]}" \
  89. 2> "${SUBTMPDIR}/return-MenuBootloader_cases" || continue;
  90. BOOT_DEVICE="$(cat -- "${SUBTMPDIR}"/return-MenuBootloader_cases)"
  91. else
  92. BOOT_DEVICE="${array[0]}"
  93. fi
  94. unset -v array xlist
  95. fi
  96. unset -v _submenu_title
  97. # To fallback if 'BOOT_DEVICE' is not defined, null
  98. BOOT_DEVICE="${BOOT_DEVICE:=$(cat -- "${SUBTMPDIR}"/root_device)}"
  99. # If the superblock was not chosen, we do not need
  100. # the device number to install on the MBR
  101. if test "$answer" != 1
  102. then
  103. BOOT_DEVICE="${BOOT_DEVICE/[0-9]*/}"
  104. fi
  105. unset -v answer
  106. # GRUB Installation
  107. dialog --clear
  108. echo "Boot loader installation on $BOOT_DEVICE ..."
  109. echo ""
  110. mkdir -p -- /media/dragora-root/boot/grub
  111. echo ""
  112. chroot /media/dragora-root /usr/sbin/grub-install --force $BOOT_DEVICE
  113. echo ""
  114. echo "Generating configuration file (as /boot/grub/grub.cfg) ..."
  115. echo ""
  116. chroot /media/dragora-root /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
  117. sleep 5
  118. unset -v BOOT_DEVICE
  119. _default_button=cancel
  120. continue;
  121. ;;
  122. esac
  123. done