2016-07-25 14:08:53 +00:00
|
|
|
#!/bin/ash
|
2017-04-12 10:57:58 +00:00
|
|
|
# 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.
|
|
|
|
|
2016-08-01 02:39:07 +00:00
|
|
|
# First thing it is vital to mount the /dev and other system directories
|
2017-04-02 03:02:00 +00:00
|
|
|
mkdir /proc /sys /dev /tmp /boot /media 2>&- 1>&-
|
2017-04-10 17:11:19 +00:00
|
|
|
mount /dev
|
|
|
|
mount /proc
|
|
|
|
mount /sys
|
2016-08-01 02:39:07 +00:00
|
|
|
|
2017-04-12 10:57:58 +00:00
|
|
|
# Recovery shells will erase anything from here
|
|
|
|
mkdir -p /tmp/secret
|
|
|
|
|
2017-03-31 15:18:46 +00:00
|
|
|
# Setup our path
|
|
|
|
export PATH=/sbin:/bin
|
|
|
|
|
2016-08-01 02:39:07 +00:00
|
|
|
# Now it is safe to print a banner
|
2017-03-31 15:18:46 +00:00
|
|
|
if [ -r /etc/motd ]; then
|
|
|
|
cat /etc/motd
|
|
|
|
fi
|
2016-07-25 14:08:53 +00:00
|
|
|
|
2016-08-01 02:39:07 +00:00
|
|
|
# Load the date from the hardware clock, setting it in local time
|
|
|
|
hwclock -l -s
|
|
|
|
|
2017-03-31 15:18:46 +00:00
|
|
|
# Read the system configuration parameters
|
2017-04-12 10:57:58 +00:00
|
|
|
. /etc/functions
|
|
|
|
. /etc/config
|
|
|
|
|
2017-07-17 16:22:48 +00:00
|
|
|
# Add our boot devices into the /etc/fstab, if they are defined
|
|
|
|
# in the configuration file.
|
|
|
|
if [ ! -z "$CONFIG_BOOT_DEV" ]; then
|
|
|
|
echo >> /etc/fstab "$CONFIG_BOOT_DEV /boot auto defaults,ro 0 0"
|
|
|
|
fi
|
|
|
|
if [ ! -z "$CONFIG_USB_BOOT_DEV" ]; then
|
|
|
|
echo >> /etc/fstab "$CONFIG_USB_BOOT_DEV /media auto defaults,ro 0 0"
|
|
|
|
fi
|
|
|
|
|
2017-04-12 10:57:58 +00:00
|
|
|
if [ ! -x "$CONFIG_BOOTSCRIPT" ]; then
|
|
|
|
recovery 'Boot script missing? Entering recovery shell'
|
|
|
|
# just in case...
|
2017-04-23 20:12:08 +00:00
|
|
|
tpm extend -ix 4 -ic recovery
|
2017-04-12 10:57:58 +00:00
|
|
|
exec /bin/ash
|
2016-08-01 02:39:07 +00:00
|
|
|
fi
|
2017-03-27 22:03:09 +00:00
|
|
|
|
2017-07-18 17:44:02 +00:00
|
|
|
# If the user has been holding down r, enter a recovery shell
|
|
|
|
# otherwise immediately start the configured boot script.
|
|
|
|
# We don't print a prompt, since this is a near instant timeout.
|
2017-04-12 10:57:58 +00:00
|
|
|
read \
|
2017-07-18 17:44:02 +00:00
|
|
|
-t 0.1 \
|
2017-04-12 10:57:58 +00:00
|
|
|
-n 1 \
|
|
|
|
boot_option
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ "$boot_option" = "r" ]; then
|
|
|
|
# Start an interactive shell
|
|
|
|
recovery 'User requested recovery shell'
|
|
|
|
# just in case...
|
2017-04-23 20:12:08 +00:00
|
|
|
tpm extend -ix 4 -ic recovery
|
2017-04-12 10:57:58 +00:00
|
|
|
exec /bin/ash
|
|
|
|
fi
|
2017-03-31 15:18:46 +00:00
|
|
|
|
2017-07-18 17:44:02 +00:00
|
|
|
echo '***** Normal boot:' $CONFIG_BOOTSCRIPT
|
2017-04-12 10:57:58 +00:00
|
|
|
exec "$CONFIG_BOOTSCRIPT"
|
2017-03-31 15:18:46 +00:00
|
|
|
|
2017-04-12 10:57:58 +00:00
|
|
|
# We should never reach here, but just in case...
|
|
|
|
recovery 'Boot script failure? Entering recovery shell'
|
|
|
|
# belts and suspenders, just in case...
|
2017-04-23 20:12:08 +00:00
|
|
|
tpm extend -ix 4 -ic recovery
|
2017-04-12 10:57:58 +00:00
|
|
|
exec /bin/ash
|