mirror of
https://github.com/linuxboot/heads.git
synced 2024-12-30 01:38:56 +00:00
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:
parent
e8f3d206c5
commit
0897a20b84
@ -30,7 +30,7 @@ while true; do
|
|||||||
recovery "User requested recovery shell"
|
recovery "User requested recovery shell"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$totp_confim" = "n" ]; then
|
if [ "$totp_confirm" = "n" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "To correct clock drift: 'date -s HH:MM:SS'"
|
echo "To correct clock drift: 'date -s HH:MM:SS'"
|
||||||
echo "and save it to the RTC: 'hwclock -w'"
|
echo "and save it to the RTC: 'hwclock -w'"
|
||||||
@ -41,18 +41,21 @@ while true; do
|
|||||||
|
|
||||||
if [ "$totp_confirm" = "u" ]; then
|
if [ "$totp_confirm" = "u" ]; then
|
||||||
exec /bin/usb-init
|
exec /bin/usb-init
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$totp_confirm" = "m" ]; then
|
if [ "$totp_confirm" = "m" ]; then
|
||||||
# Try to select a kernel from the menu
|
# Try to select a kernel from the menu
|
||||||
mount_boot
|
mount_boot
|
||||||
kexec-select-boot -m -b /boot -c "grub.cfg"
|
kexec-select-boot -m -b /boot -c "grub.cfg"
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$totp_confirm" = "y" -o "$totp_confirm" != " " ]; then
|
if [ "$totp_confirm" = "y" -o -n "$totp_confirm" ]; then
|
||||||
# Try to boot the default
|
# Try to boot the default
|
||||||
mount_boot
|
mount_boot
|
||||||
kexec-select-boot -b /boot -c "grub.cfg"
|
kexec-select-boot -b /boot -c "grub.cfg" \
|
||||||
|
|| recovery "Failed default boot"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
@ -11,6 +11,7 @@ unique="n"
|
|||||||
valid_hash="n"
|
valid_hash="n"
|
||||||
valid_global_hash="n"
|
valid_global_hash="n"
|
||||||
valid_rollback="n"
|
valid_rollback="n"
|
||||||
|
force_menu="n"
|
||||||
while getopts "b:d:p:a:r:c:uim" arg; do
|
while getopts "b:d:p:a:r:c:uim" arg; do
|
||||||
case $arg in
|
case $arg in
|
||||||
b) bootdir="$OPTARG" ;;
|
b) bootdir="$OPTARG" ;;
|
||||||
@ -20,7 +21,7 @@ while getopts "b:d:p:a:r:c:uim" arg; do
|
|||||||
r) remove="$OPTARG" ;;
|
r) remove="$OPTARG" ;;
|
||||||
c) config="$OPTARG" ;;
|
c) config="$OPTARG" ;;
|
||||||
u) unique="y" ;;
|
u) unique="y" ;;
|
||||||
m) show_menu="y" ;;
|
m) force_menu="y" ;;
|
||||||
i) valid_hash="y"; valid_rollback="y" ;;
|
i) valid_hash="y"; valid_rollback="y" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -153,6 +154,7 @@ save_default_option() {
|
|||||||
echo "+++ Saved defaults to device"
|
echo "+++ Saved defaults to device"
|
||||||
sleep 2
|
sleep 2
|
||||||
default_failed="n"
|
default_failed="n"
|
||||||
|
force_menu="n"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
echo "Failed to save defaults"
|
echo "Failed to save defaults"
|
||||||
@ -172,9 +174,7 @@ default_select() {
|
|||||||
expectedoption=`cat $TMP_DEFAULT_FILE`
|
expectedoption=`cat $TMP_DEFAULT_FILE`
|
||||||
option=`head -n $default_index $TMP_MENU_FILE | tail -1`
|
option=`head -n $default_index $TMP_MENU_FILE | tail -1`
|
||||||
if [ "$option" != "$expectedoption" ]; then
|
if [ "$option" != "$expectedoption" ]; then
|
||||||
warn "!!! Boot entry has changed - please set a new default"
|
die "!!! Boot entry has changed - please set a new default"
|
||||||
sleep 5
|
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
parse_option
|
parse_option
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ default_select() {
|
|||||||
echo "+++ Verified default boot hashes "
|
echo "+++ Verified default boot hashes "
|
||||||
valid_hash='y'
|
valid_hash='y'
|
||||||
else
|
else
|
||||||
die "$TMP_DEFAULT_HASH_FILE: default boot hash mismatch"
|
die "!!! $TMP_DEFAULT_HASH_FILE: default boot hash mismatch"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "+++ Executing default boot for $name:"
|
echo "+++ Executing default boot for $name:"
|
||||||
@ -208,8 +208,15 @@ user_select() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ "$option_confirm" = "d" ]; then
|
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
|
continue
|
||||||
|
else
|
||||||
|
echo "+++ Rebooting to start the new default option"
|
||||||
|
sleep 2
|
||||||
|
reboot \
|
||||||
|
|| die "!!! Failed to reboot system"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
do_boot
|
do_boot
|
||||||
@ -218,13 +225,11 @@ user_select() {
|
|||||||
do_boot()
|
do_boot()
|
||||||
{
|
{
|
||||||
if [ "$CONFIG_BOOT_REQ_ROLLBACK" = "y" -a "$valid_rollback" = "n" ]; then
|
if [ "$CONFIG_BOOT_REQ_ROLLBACK" = "y" -a "$valid_rollback" = "n" ]; then
|
||||||
warn "!!! Missing required rollback counter state"
|
die "!!! Missing required rollback counter state"
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$CONFIG_BOOT_REQ_HASH" = "y" -a "$valid_hash" = "n" ]; then
|
if [ "$CONFIG_BOOT_REQ_HASH" = "y" -a "$valid_hash" = "n" ]; then
|
||||||
warn "!!! Missing required boot hashes"
|
die "!!! Missing required boot hashes"
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -r "$TMP_KEY_DEVICES" ]; then
|
if [ -r "$TMP_KEY_DEVICES" ]; then
|
||||||
@ -286,6 +291,7 @@ while true; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$default_failed" != "y" \
|
if [ "$default_failed" != "y" \
|
||||||
|
-a "$force_menu" = "n" \
|
||||||
-a -r "$TMP_DEFAULT_FILE" \
|
-a -r "$TMP_DEFAULT_FILE" \
|
||||||
-a -r "$TMP_DEFAULT_HASH_FILE" ] \
|
-a -r "$TMP_DEFAULT_HASH_FILE" ] \
|
||||||
; then
|
; then
|
||||||
|
10
initrd/bin/poweroff
Executable file
10
initrd/bin/poweroff
Executable 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
10
initrd/bin/reboot
Executable 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
|
Loading…
Reference in New Issue
Block a user