heads/initrd/init
Francis Lam efd662c63a
adds a USB boot option with basic parsing to kexec
Supports booting from USB media using either the root device or
a signed ISO as the boot device.  Boot options are parsed with
quick/dirty shell scripts to infer kexec params.

Closes #195 and begins to address #196
2017-04-29 13:40:34 -04:00

71 lines
1.7 KiB
Bash
Executable File

#!/bin/ash
# This is the very first script invoked by the Linux kernel and is
# running out of the ram disk. There are no fileysstems mounted.
# It is important to have a way to invoke a recovery shell in case
# the boot scripts are messed up, but also important to modify the
# PCRs if this happens to prevent the TPM disk keys from being revealed.
# First thing it is vital to mount the /dev and other system directories
mkdir /proc /sys /dev /tmp /boot /media 2>&- 1>&-
mount /dev
mount /proc
mount /sys
# Recovery shells will erase anything from here
mkdir -p /tmp/secret
# Setup our path
export PATH=/sbin:/bin
# Now it is safe to print a banner
if [ -r /etc/motd ]; then
cat /etc/motd
fi
# Load the date from the hardware clock, setting it in local time
hwclock -l -s
# Read the system configuration parameters
. /etc/functions
. /etc/config
if [ ! -x "$CONFIG_BOOTSCRIPT" ]; then
recovery 'Boot script missing? Entering recovery shell'
# just in case...
tpm extend -ix 4 -ic recovery
exec /bin/ash
fi
# Give the user a second to enter a recovery shell
read \
-t "1" \
-p "Press 'r' for recovery shell or 'u' for usb: " \
-n 1 \
boot_option
echo
if [ "$boot_option" = "r" ]; then
# Start an interactive shell
recovery 'User requested recovery shell'
# just in case...
tpm extend -ix 4 -ic recovery
exec /bin/ash
fi
if [ "$boot_option" = "u" ]; then
echo '***** USB boot'
exec /bin/usb-init
# just in case...
tpm extend -ix 4 -ic recovery
exec /bin/ash
fi
echo '***** Normal boot'
exec "$CONFIG_BOOTSCRIPT"
# We should never reach here, but just in case...
recovery 'Boot script failure? Entering recovery shell'
# belts and suspenders, just in case...
tpm extend -ix 4 -ic recovery
exec /bin/ash