From 11bde902893847943ab4cf8340de1be849c716e5 Mon Sep 17 00:00:00 2001 From: SolidHal Date: Tue, 15 Oct 2019 07:22:01 -0700 Subject: [PATCH] Add label based initramfs debugging --- DOCUMENTATION.md | 11 ++++++----- resources/BuildResources/initramfs-init | 11 ++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 812c0f1..a1e724d 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -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. diff --git a/resources/BuildResources/initramfs-init b/resources/BuildResources/initramfs-init index 6f8461e..5680eac 100644 --- a/resources/BuildResources/initramfs-init +++ b/resources/BuildResources/initramfs-init @@ -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 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}