From 1fc123df4a7c46acaf16edee714d2f0f73d723cd Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Fri, 23 Oct 2020 18:35:39 -0500 Subject: [PATCH] gui-init: improve handling of blank/missing disk Check for presence of CONFIG_BOOT_DEV, and if missing or unable to be mounted, present the user with a menu offering the option to select another disk, boot from USB, continue to main menu, or drop to a recovery shell. Signed-off-by: Matt DeVillier --- initrd/bin/gui-init | 52 ++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/initrd/bin/gui-init b/initrd/bin/gui-init index ceef9da6..ecd7df33 100755 --- a/initrd/bin/gui-init +++ b/initrd/bin/gui-init @@ -14,27 +14,41 @@ mount_boot() # Mount local disk if it is not already mounted while ! grep -q /boot /proc/mounts ; do - # ensure default boot device is set - if [ ! -e "$CONFIG_BOOT_DEV" ]; then - if (whiptail $BG_COLOR_ERROR --clear --title "ERROR: $CONFIG_BOOT_DEV missing!" \ - --yesno "The /boot device $CONFIG_BOOT_DEV could not be found!\n\nYou will need to configure the correct device for /boot.\n\nWould you like to configure the /boot device now?" 30 90) then + # try to mount if CONFIG_BOOT_DEV exists + if [ -e "$CONFIG_BOOT_DEV" ]; then + mount -o ro $CONFIG_BOOT_DEV /boot + [[ $? -eq 0 ]] && continue + fi + + # CONFIG_BOOT_DEV doesn't exist or couldn't be mounted, so give user options + whiptail $BG_COLOR_ERROR --clear --title "ERROR: No Bootable OS Found!" \ + --menu " No bootable OS was found on the default boot device $CONFIG_BOOT_DEV. + How would you like to proceed?" 30 90 4 \ + 'b' ' Select a new boot device' \ + 'u' ' Boot from USB' \ + 'm' ' Continue to the main menu' \ + 'x' ' Exit to recovery shell' \ + 2>/tmp/whiptail || recovery "GUI menu failed" + + option=$(cat /tmp/whiptail) + case "$option" in + b ) config-gui.sh boot_device_select - else - # exit to main menu + if [ $? -eq 0 ]; then + # update CONFIG_BOOT_DEV + . /tmp/config + fi + ;; + u ) + exec /bin/usb-init + ;; + m ) break - fi - fi - # update CONFIG_BOOT_DEV - . /tmp/config - mount -o ro $CONFIG_BOOT_DEV /boot - if [ $? -ne 0 ]; then - if (whiptail $BG_COLOR_ERROR --clear --title 'ERROR: Cannot mount /boot' \ - --yesno "The /boot partition at $CONFIG_BOOT_DEV could not be mounted!\n\nWould you like to configure the /boot device now?" 30 90) then - config-gui.sh boot_device_select - else - recovery "Unable to mount /boot" - fi - fi + ;; + * ) + recovery "User requested recovery shell" + ;; + esac done } verify_global_hashes()