From: Nick Bowler Date: Tue, 19 Aug 2014 23:55:07 +0000 (-0400) Subject: Add new kexec bootloader-like script. X-Git-Url: https://git.draconx.ca/gitweb/scripts.git/commitdiff_plain/a32c6119947e576c9d9456b736a4b71537bcd4f1 Add new kexec bootloader-like script. --- diff --git a/init-kexec.sh b/init-kexec.sh new file mode 100755 index 0000000..848db62 --- /dev/null +++ b/init-kexec.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# +# Copyright © 2014 Nick Bowler +# +# Very simple kexec-based "bootloader", intended to be run as init. Allows +# the user to select one of a list of kernels, or boot a default if no user +# action is given within the timeout. +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. + +default=vmlinuz +cmdline='root=/dev/vda init=/sbin/init.sysv' +timeout=10 +width=60 + +do_dialog() { + dmesg --console-off >/dev/null 2>&1 + exec 3>&1 + eval_result=`printf 'dialog_output=' + command dialog --keep-tite --quoted "$@" 2>&1 1>&3 + printf '\ndialog_status=%d\n' $?` + exec 3>&- + dmesg --console-on >/dev/null 2>&1 + eval "$eval_result" && (exit $dialog_status) +} + +do_shell() { + printf 'Cancelled; dropping to shell\n' 1>&2 + + test "$$" = 1 && exec /bin/sh + exit 1 +} + +if do_dialog --defaultno --ok-label Skip --pause \ + 'Booting default (Ctrl+C to interrupt)...' 8 $width $timeout +then + kernel=$default +else + do_dialog --no-tags --default-item "$default" --menu \ + 'Select kernel to boot, or cancel to exit to shell.' \ + 20 $width 20 \ + 'vmlinuz.old' 'vmlinuz.old' \ + 'vmlinuz' 'vmlinuz' || do_shell + kernel=$dialog_output +fi + +printf 'Selected %s\n' "$kernel" + +kexec -l "/boot/$kernel" --command-line="$cmdline" || do_shell +if test "$$" = 1; then + # Only execute new kernel if we are init. + kexec -e +fi + +# Failing that, drop to shell. +do_shell