3 # Copyright © 2014 Nick Bowler
5 # Very simple kexec-based "bootloader", intended to be run as init. Allows
6 # the user to select one of a list of kernels, or boot a default if no user
7 # action is given within the timeout.
9 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
10 # This is free software: you are free to do what the fuck you want to.
11 # There is NO WARRANTY, to the extent permitted by law.
14 cmdline='root=/dev/vda init=/sbin/init.sysv'
19 dmesg --console-off >/dev/null 2>&1
21 eval_result=`printf 'dialog_output='
22 command dialog --keep-tite --quoted "$@" 2>&1 1>&3
23 printf '\ndialog_status=%d\n' $?`
25 dmesg --console-on >/dev/null 2>&1
26 eval "$eval_result" && (exit $dialog_status)
30 printf 'Cancelled; dropping to shell\n' 1>&2
32 test "$$" = 1 && exec /bin/sh
36 if do_dialog --defaultno --ok-label Skip --pause \
37 'Booting default (Ctrl+C to interrupt)...' 8 $width $timeout
41 do_dialog --no-tags --default-item "$default" --menu \
42 'Select kernel to boot, or cancel to exit to shell.' \
44 'vmlinuz.old' 'vmlinuz.old' \
45 'vmlinuz' 'vmlinuz' || do_shell
49 printf 'Selected %s\n' "$kernel"
51 kexec -l "/boot/$kernel" --command-line="$cmdline" || do_shell
52 if test "$$" = 1; then
53 # Only execute new kernel if we are init.
57 # Failing that, drop to shell.