I'm trying to modify a Debian 11 Raspi image to boot from a LUKS device. When booting, the last lines being logged are HID (input device) detection, and after a couple of seconds:
kernel: random: crng init done
After that boot hangs. No prompt. No reaction to keypresses except Ctrl + Alt + Del (halt).
I followed the following answer's recipe to modify the Debian image to boot from a LUKS device:
What I made different:
Pre modification
- installed
cryptsetup-initramfs
- added
CRYPTSETUP=y
to/etc/cryptsetup-initramfs/conf-hook
andupdate-initramfs
- installed
From the recipe I deviated by
- Storing the root partition to a .tar
- Formatting a LUKS device on the root partition
- Using another cipher (aes-xts-plain64)
- Using LUKS type 1
- Opening the LUKS device
- Formatting EXT4 partition on the mapped device
- Fixed the
cryptdevice
name after:
to equal to the mapper name, not "sdcard"
Question
Apparently init
does not execute or crashes early. Adding debug
to cmdline.txt
does not show much more infos, except for this:
[5.12345] Run /init as init process
[5.12345] with arguments:
[5.12345] /init
[5.12345] with environment:
[5.12345] HOME=/
[5.12345] TERM=linux
[5.12345] cryptdevice=/dev/mmcblk1p2:rpirootfs
Are there any obvious errors? How can I further debug at what point / for what reason the start stop?
My scripts
Pre modification:
apt-get update -y
apt-get upgrade -y
cat <<-EOF >>/etc/initramfs-tools/modules
algif_skcipher
xchacha12
adiantum
aes_arm
sha256
nhpoly1305
dm-crypt
EOF
echo “CRYPTSETUP=y” >> /etc/cryptsetup-initramfs/conf-hook
apt-get install cryptsetup-initramfs
update-initramfs -c -u
Encryption script
LUKS_CIPHER="aes-xts-plain64"
LUKS_NAME="rpirootfs"
# Inside Raspberry Pi
RPI_ROOT_DISK_NAME="/dev/mmcblk1p2"
MOUNT_RPI="/mnt"
PACKED_RPI="/media/ramdisk/rpi.tar"
luks_mapper_device="/dev/mapper/${LUKS_NAME}"
mount ${disk} ${MOUNT_RPI}
tar -C ${MOUNT_RPI} -Pcf ${PACKED_RPI} .
umount ${disk}
cryptsetup luksFormat -c ${LUKS_CIPHER} -s 256 -h sha512 --use-urandom ${disk}
cryptsetup luksOpen ${disk} ${LUKS_NAME}
mkfs.ext4 ${luks_mapper_device}
mount ${luks_mapper_device} ${MOUNT_RPI}
tar -C ${MOUNT_RPI} -xf ${PACKED_RPI}
echo "${LUKS_NAME} ${RPI_ROOT_DISK_NAME} none luks" > ${MOUNT_RPI}/etc/crypttab
echo "${luks_mapper_device} / ext4 defaults,noatime 0 0" > ${MOUNT_RPI}/etc/fstab
umount ${luks_mapper_device}
cryptsetup close ${LUKS_NAME}
mount ${boot_disk} ${MOUNT_RPI}
sed -i -r "s;root=LABEL=[^ ]+ ;root=${luks_mapper_device} ;" ${MOUNT_RPI}/cmdline.txt
sed -i -r 's/splash//' ${MOUNT_RPI}/cmdline.txt
sed -i -r "s;cryptdevice=[^ ]+;;" ${MOUNT_RPI}/cmdline.txt
sed -i -r "s;$; cryptdevice=${RPI_ROOT_DISK_NAME}:${LUKS_NAME};" ${MOUNT_RPI}/cmdline.txt
umount ${boot_disk}
initramfs
option to/etc/crypttab
. That means, that this has to be configured during the pre-modification stage by creating the file withrpirootfs /dev/mmcblk1p2 none luks,initramfs
. Change the root partition in/etc/fstab
to/dev/mapper/rpirootfs / ext4 defaults,noatime 0 0
. Finally, the prompt was not visible because it was shown at the serial console. Ensure there's noconsole=ttyS1,115200
inconsole.txt
.