Check "/boot/firmware/config.txt", it should load the created initramfs since it mentiones the "initrd.img-6.1.0-18-arm64" image
Replace the content of "/boot/firmware/cmdline.txt" with the copied content from before
Reboot
Verify dropbear configuration by logging in from another system via ssh: ssh root@192.168.188.247 -p 2222 -i ares_luks
Fail the unlock since "/etc/unlock.sh" can not be found:
$ ssh root@192.168.188.247 -p 2222 -i ares_luks
The authenticity of host '[192.168.188.247]:2222 ([192.168.188.247]:2222)' can't be established.
ED25519 key fingerprint is SHA256:lLYugILqU7OqgXlQ9JX3B2woKFNEay71SZ27KjP7+v0.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[192.168.188.247]:2222' (ED25519) to the list of known hosts.
Enter passphrase for key 'ares_luks':
sh: /etc/unlock.sh: not found
Connection to 192.168.188.247 closed.
Fix
Manually decrypt the filesystem in the initramfs by pressing "Enter" once and providing the correct decryption password
Connect to the RaspberryPi as root via ssh: ssh root@192.168.188.247 -i ares_luks
Make a copy/note down content of "/boot/firmware/cmdline.txt", as it can get replaced during the update process
Create an initramfs hook for copying the missing file:
nano /etc/initramfs-tools/hooks/luks_unlock
#!/bin/sh -e
PREREQS=""
case $1 in
prereqs) echo "${PREREQS}"; exit 0;;
esac
. /usr/share/initramfs-tools/hook-functions
copy_file config /etc/initramfs-tools/unlock.sh /etc/unlock.sh
Make it executable chmod 755 /etc/initramfs-tools/hooks/luks_unlock
Create a new initramfs mkinitramfs -o /boot/initramfs.gz 6.1.0-18-arm64
Check the created initramfs via lsinitramfs /boot/initramfs.gz | grep -P "(crypttab|fstab|unlock.sh)"-> this will include the previously missing unlock.sh:
cryptroot/crypttab
etc/fstab
etc/unlock.sh
Do the same as the scripts by moving the created initramfs around to make it load on boot:
Check "/boot/firmware/config.txt", it should load the created initramfs since it mentiones the "initrd.img-6.1.0-18-arm64" image
Replace the content of "/boot/firmware/cmdline.txt" with the copied content from before
Reboot
Verify dropbear configuration by logging in from another system via ssh: ssh root@192.168.188.247 -p 2222 -i ares_luks
Dropbear works and the filesystem is decrypted
As far as I can tell removing this single line of code allows for updating the initramfs as long as you also adjust the "/boot/firmware/cmdline.txt" as well. I am not sure if the "{DESTDIR}" parts of the hook interfere with anything though.
As promised, here is a list of all steps including the configuration for how I managed to get an updated Debian instance running on the RaspberryPi.
Setup:
Configuration
Steps to Reproduce
Initial setup
su -
./cryptmypi.sh examples/debian-encrypted-basic-dropbear
stage 1 and stage 2lsinitramfs examples/debian-encrypted-basic-dropbear/build/root/boot/initramfs.gz | grep -P "(crypttab|fstab|unlock.sh)"
-> reference initramfs imagelsinitramfs examples/debian-encrypted-basic-dropbear/build/root/boot/initrd.img-6.1.0-13-arm64 | grep -P "(crypttab|fstab|unlock.sh)"
lsinitramfs examples/debian-encrypted-basic-dropbear/build/root/boot/firmware/initrd.img-6.1.0-13-arm64 | grep -P "(crypttab|fstab|unlock.sh)"
ssh root@192.168.188.247 -p 2222 -i ares_luks
nano /etc/ssh/sshd_config
-> PermitRootLogin yessystemctl restart ssh.service
Updating (fails by default)
ssh root@192.168.188.247 -i ares_luks
apt update && apt upgrade -y
-> keep the local ssh configuration if askedls /lib/modules
-> In my case this returns6.1.0-13-arm64 6.1.0-18-arm64
mkinitramfs -o /boot/initramfs.gz 6.1.0-18-arm64
lsinitramfs /boot/initramfs.gz | grep -P "(crypttab|fstab|unlock.sh)"
-> this will only include the following:mv /boot/firmware/initrd.img-6.1.0-18-arm64 /boot/firmware/initrd.img-6.1.0-18-arm64-oos
mv /boot/initrd.img-6.1.0-18-arm64 /boot/initrd.img-6.1.0-18-arm64-oos
mv /boot/initramfs.gz /boot/firmware/initrd.img-6.1.0-18-arm64
ssh root@192.168.188.247 -p 2222 -i ares_luks
Fix
ssh root@192.168.188.247 -i ares_luks
nano /etc/initramfs-tools/hooks/luks_unlock
chmod 755 /etc/initramfs-tools/hooks/luks_unlock
mkinitramfs -o /boot/initramfs.gz 6.1.0-18-arm64
lsinitramfs /boot/initramfs.gz | grep -P "(crypttab|fstab|unlock.sh)"
-> this will include the previously missing unlock.sh:mv /boot/firmware/initrd.img-6.1.0-18-arm64 /boot/firmware/initrd.img-6.1.0-18-arm64-oos
mv /boot/initramfs.gz /boot/firmware/initrd.img-6.1.0-18-arm64
ssh root@192.168.188.247 -p 2222 -i ares_luks
Test whether keeping hook in script fixes problem
A possible solution for this problem would be the removal of the previously mentioned https://github.com/unixabg/cryptmypi/blob/52227dfaf905ace65fa8555fb3999e9a75b299f5/hooks/7500-stage2-chroot-final.hook#L6
nano hooks/7500-stage2-chroot-final.hook
./cryptmypi.sh examples/debian-encrypted-basic-dropbear
stage 1 and stage 2ls -l /etc/initramfs-tools/hooks/
-> zz-cryptsetupapt update && apt upgrade -y
-> keep the local ssh configuration if askedls /lib/modules
-> In my case this returns6.1.0-13-arm64 6.1.0-18-arm64
mkinitramfs -o /boot/initramfs.gz 6.1.0-18-arm64
lsinitramfs /boot/initramfs.gz | grep -P "(crypttab|fstab|unlock.sh)"
-> "/etc/unlock.sh" should be in the listmv /boot/firmware/initrd.img-6.1.0-18-arm64 /boot/firmware/initrd.img-6.1.0-18-arm64-oos
mv /boot/initrd.img-6.1.0-18-arm64 /boot/initrd.img-6.1.0-18-arm64-oos
mv /boot/initramfs.gz /boot/firmware/initrd.img-6.1.0-18-arm64
ssh root@192.168.188.247 -p 2222 -i ares_luks
As far as I can tell removing this single line of code allows for updating the initramfs as long as you also adjust the "/boot/firmware/cmdline.txt" as well. I am not sure if the "{DESTDIR}" parts of the hook interfere with anything though.