Ensure recovery for failed default boot

Should close #223

Added reboot and poweroff scripts using /proc/sysrq-trigger

Also cleaned up the boot loop in generic-init
This commit is contained in:
Francis Lam 2017-07-22 14:57:46 -04:00
parent e8f3d206c5
commit 0897a20b84
No known key found for this signature in database
GPG Key ID: 0A59C698920806EB
4 changed files with 43 additions and 14 deletions

View File

@ -30,7 +30,7 @@ while true; do
recovery "User requested recovery shell"
fi
if [ "$totp_confim" = "n" ]; then
if [ "$totp_confirm" = "n" ]; then
echo ""
echo "To correct clock drift: 'date -s HH:MM:SS'"
echo "and save it to the RTC: 'hwclock -w'"
@ -41,18 +41,21 @@ while true; do
if [ "$totp_confirm" = "u" ]; then
exec /bin/usb-init
continue
fi
if [ "$totp_confirm" = "m" ]; then
# Try to select a kernel from the menu
mount_boot
kexec-select-boot -m -b /boot -c "grub.cfg"
continue
fi
if [ "$totp_confirm" = "y" -o "$totp_confirm" != " " ]; then
if [ "$totp_confirm" = "y" -o -n "$totp_confirm" ]; then
# Try to boot the default
mount_boot
kexec-select-boot -b /boot -c "grub.cfg"
kexec-select-boot -b /boot -c "grub.cfg" \
|| recovery "Failed default boot"
fi
done

View File

@ -11,6 +11,7 @@ unique="n"
valid_hash="n"
valid_global_hash="n"
valid_rollback="n"
force_menu="n"
while getopts "b:d:p:a:r:c:uim" arg; do
case $arg in
b) bootdir="$OPTARG" ;;
@ -20,7 +21,7 @@ while getopts "b:d:p:a:r:c:uim" arg; do
r) remove="$OPTARG" ;;
c) config="$OPTARG" ;;
u) unique="y" ;;
m) show_menu="y" ;;
m) force_menu="y" ;;
i) valid_hash="y"; valid_rollback="y" ;;
esac
done
@ -153,6 +154,7 @@ save_default_option() {
echo "+++ Saved defaults to device"
sleep 2
default_failed="n"
force_menu="n"
return
else
echo "Failed to save defaults"
@ -172,9 +174,7 @@ default_select() {
expectedoption=`cat $TMP_DEFAULT_FILE`
option=`head -n $default_index $TMP_MENU_FILE | tail -1`
if [ "$option" != "$expectedoption" ]; then
warn "!!! Boot entry has changed - please set a new default"
sleep 5
return
die "!!! Boot entry has changed - please set a new default"
fi
parse_option
@ -185,7 +185,7 @@ default_select() {
echo "+++ Verified default boot hashes "
valid_hash='y'
else
die "$TMP_DEFAULT_HASH_FILE: default boot hash mismatch"
die "!!! $TMP_DEFAULT_HASH_FILE: default boot hash mismatch"
fi
echo "+++ Executing default boot for $name:"
@ -208,8 +208,15 @@ user_select() {
done
if [ "$option_confirm" = "d" ]; then
# reload settings to reflect new default
if [ ! -r "$TMP_KEY_DEVICES" ]; then
# rerun primary boot loop to boot the new default option
continue
else
echo "+++ Rebooting to start the new default option"
sleep 2
reboot \
|| die "!!! Failed to reboot system"
fi
fi
do_boot
@ -218,13 +225,11 @@ user_select() {
do_boot()
{
if [ "$CONFIG_BOOT_REQ_ROLLBACK" = "y" -a "$valid_rollback" = "n" ]; then
warn "!!! Missing required rollback counter state"
return
die "!!! Missing required rollback counter state"
fi
if [ "$CONFIG_BOOT_REQ_HASH" = "y" -a "$valid_hash" = "n" ]; then
warn "!!! Missing required boot hashes"
return
die "!!! Missing required boot hashes"
fi
if [ -r "$TMP_KEY_DEVICES" ]; then
@ -286,6 +291,7 @@ while true; do
fi
if [ "$default_failed" != "y" \
-a "$force_menu" = "n" \
-a -r "$TMP_DEFAULT_FILE" \
-a -r "$TMP_DEFAULT_HASH_FILE" ] \
; then

10
initrd/bin/poweroff Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# Sync all mounted filesystems
echo s > /proc/sysrq-trigger
# Remount all mounted filesystems in read-only mode
echo u > /proc/sysrq-trigger
# Shut off the system
echo o > /proc/sysrq-trigger

10
initrd/bin/reboot Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# Sync all mounted filesystems
echo s > /proc/sysrq-trigger
# Remount all mounted filesystems in read-only mode
echo u > /proc/sysrq-trigger
# Immediately reboot the system, without unmounting or syncing filesystems
echo b > /proc/sysrq-trigger