Debugging initramfs-tools scripts on Debian

I was having a hard time trying to wrap my head around how initramfs-tools works. Basically, this is the infrastructure that a Debian system typically uses to generate the initramfs, the inital in-memory, read-only filesystem used while the Linux kernel is booting (after the bootloader, but before most of the kernel modules are loaded or your root filesystem is mounted). The idea is to take complexity out of the bootloader by putting the kernel and initramfs somewhere easy to access (like an EXT2 partition) and letting the kernel handle implementing more complicated features, like mounting a root filesystem backed by NFS or BTRFS.

Eventually it occurred to me that if I wanted to observe the state of my system at any of the stages documented in initramfs-tools(7), I could just call the provided panic helper in /usr/share/initramfs-tools/scripts/functions. It just drops you into a shell, and you can do stuff like env to get the environment variable.

I put this script in /etc/initramfs-tools/scripts/init-bottom/shell:

#!/bin/sh

PREREQ=""

prereqs()
{
    echo "${PREREQ}"
}

case ${1} in
    prereqs)
        prereqs
        exit 0
        ;;
esac

. /scripts/functions

panic "Let's exit to a shell!"

Then I did this:

sudo chmod u+x /etc/initramfs-tools/scripts/init-bottom/shell
sudo update-initramfs -u
sudo reboot

During the "init-bottom" stage, the real root filesystem is mounted at /root, about to be switched over to /.

When my system booted up, I could poke around in a shell, and do exit when I was ready to continue the boot process.