Add label based initramfs debugging

This commit is contained in:
SolidHal 2019-10-15 07:22:01 -07:00
parent 5d45521630
commit 11bde90289
2 changed files with 16 additions and 6 deletions

View File

@ -119,16 +119,17 @@ The initramfs is what runs initialy at boot, and allows us to enter a password a
In a normal system, when dmcrypt/LUKS is setup the initramfs image is modified to enable decrypting of the root partiton
Since we have to have a static initramfs image, and can't change it without recompiling the kernel, we have to be a little crafty to support unencrypted and encrypted root partitons with the same initramfs
Since we have to have a static initramfs image, and can't change it without recompiling the kernel, we detect whether encryption is in use by checking for the tag `crypto_LUKS` on the root device at boot.
This is achieved by placing flags in the /boot partition, aka `/dev/mmcblk2p2` or `/dev/sda2`. The /boot partiton is empty on an unencrypted system. When root encryption is set up, the file `root_encryption` is created, which the initramfs init script uses to determine that it should try and decrypt the root partiton
### debugging the init script
A rescue debug shell is entered when the init script encounters a problem, or if the `debug` flag is set
A rescue debug shell is entered when the init script encounters a problem, or if a device with the partition label `RESCUESHELL` is present
You can enable the debug flag by mounting /boot and creating a file named `debug`
Label any partition on the system with `RESCUESHELL` to enter the initramfs rescue shell before mount and root_switch.
To make the system boot normally, from the debug prompt, run `rm /boot/debug` and `exit` to reboot
You can do this with `cgpt add -i 1 -l RESCUESHELL /dev/sda` for example to label the first partiton of a usb drive.
This is the suggested method, as then debugging can be enabled/disabled by plugging in/removing the usb device.

View File

@ -21,6 +21,8 @@ echo In PrawnOS Init
#add this to start shell at desired point
rescue_shell() {
[ "{$1}" != "debug" ] && echo "Something went wrong. Dropping to a shell." > /dev/tty1
[ "{$1}" == "debug" ] && echo "Debug flag detected, entering debug shell" > /dev/tty1
echo "Something went wrong. Dropping to a shell." > /dev/tty1
exec setsid /bin/sh -c 'exec /bin/sh </dev/tty1 >/dev/tty1 2>&1'
}
@ -64,6 +66,13 @@ echo ${ROOT_DEV} > /dev/tty1
# the next boot stage
CMDLINE='cat /proc/cmdline'
# label any partition on the system with RESCUESHELL to enter the initramfs rescue shell before mount and root_switch.
# you can do this with "cgpt add -i 1 -l RESCUESHELL /dev/sda" for example to label the first partiton of a usb drive.
if [ -n "$(blkid | grep RESCUESHELL)" ]
then
rescue_shell debug
fi
if [ -n "$(blkid ${ROOT_DEV}2 | grep crypto_LUKS)" ]
then
#decrypt and mount the root filesystem
@ -79,5 +88,5 @@ fi
umount /sys
umount /proc
#swith to the new rootfs
#switch to the new rootfs
exec switch_root /newroot /sbin/init ${CMDLINE}