#!/bin/busybox sh rescue_shell() { printf '\e[1;31m' # bold red foreground printf "$1 Dropping you to a shell." printf "\e[00m\n" # normal colour foreground # load the keymap [ -f /keymap ] && loadkmap < /keymap exec setsid cttyhack /bin/sh } # initialise mount -t proc none /proc || rescue_shell "mount /proc failed." mount -t sysfs none /sys || rescue_shell "mount /sys failed." mount -t devtmpfs none /dev || rescue_shell "mount /dev failed." # set hardcoded default values crypt_root="" root="" resume="" mount_ro_rw='ro' # parse kernel command line for p in $(cat /proc/cmdline); do case "${p}" in # crypt_root=*) # crypt_root="${p#*=}" # ;; root=*) root="${p#*=}" ;; resume=*) resume="${p#*=}" ;; ro|rw) mount_ro_rw="${p}" ;; esac done # # decrypt # # convert UUID or LABEL to device node # crypt_root="$(findfs "${crypt_root}")" # # decryption is first tried using the key file /crypto_key.bin # # if this fails, prompt for a password # cryptsetup open "${crypt_root}" lvm --type luks --key-file /crypto_key.bin || \ # cryptsetup open "${crypt_root}" lvm --type luks || \ # rescue_shell "Decryption failed." # activate lvm # create /dev/mapper/control lvm vgscan --mknodes || rescue_shell "vgscan failed." # activate all LVM volumes lvm vgchange --sysinit -a ly || rescure_shell "vgchange failed." # create device nodes for the volumes lvm vgscan --mknodes || rescue_shell "vgscan failed." # mount the real root # convert UUID or LABEL to device node root="$(findfs "${root}")" mount -o "${mount_ro_rw}" "${root}" /mnt/root || rescue_shell "mount ${root} failed." # enable resume from hibernate if [ -n "${resume}" ]; then # copy the major:minor of the swap block device into /sys/power/resume printf '%u:%u\n' $(stat -L -c '0x%t 0x%T' "${resume}") > /sys/power/resume || \ rescue_shell "Activating resume failed." fi # clean up umount /proc umount /sys umount /dev # boot the real system exec switch_root /mnt/root /sbin/init