I'm working on a script to create a fully encrypted washable system from debootstrap. It's doing some good, but the initramfs image that comes out does not pick up the cryptroot properly. After booting the image with qemu, I'm dropped to a busybox shell and I have to unlock the luks encryption manually with cryptsetup:

cryptsetup luksOpen /dev/sda1 system

(flashback does some btrfs snapshoting magic to forget changes made on every boot)

After this, boot in qemu continues normally and I am then able to generate a good initramfs image. I copy this to the btrfs @root.base subvolume and all is well from then on.

I need help with figuring out why the cryptsetup/cryptroot part is not being picked up in the chroot environment by update-initramfs:

echo "CRYPTSETUP=y" >> /usr/share/initramfs-tools/conf-hooks.d/cryptsetup
echo "export CRYPTSETUP=y" >> /usr/share/initramfs-tools/conf-hooks.d/cryptsetup
update-initramfs -ut

I have tried many things, I write a good fstab and crypttab and even tried to explicitly set cryptdevice in grub.cfg. Refer to the specific version of the script.

Here's how I create the fstab and crypttab:

export partuuid=$(blkid $partition | sed -re 's/.*: UUID="([^"]+)".*/\1/')
export decruuid=$(blkid /dev/mapper/$decrypted | sed -re 's/.*: UUID="([^"]+)".*/\1/')
echo "Adding flashback with uuid $partuuid"
echo "system UUID=$partuuid none luks" >> "$rootmount/etc/crypttab"
echo "UUID=$decruuid / btrfs subvol=@root.curr 0 0" >> "$rootmount/etc/fstab"
echo "UUID=$decruuid /home btrfs subvol=@home 0 0" >> "$rootmount/etc/fstab"

The question in principle is: How do you generate a functioning initramfs image in an encrypted chroot of a debootstrapped debian?

Thanks a bunch

  • 1
    I don't know stretch, but under jessie you definitely need a good crypttab in place before initramfs generation. – Ferenc Wágner Mar 4 '16 at 10:43
  • Thanks Ferenc, I figured crypttab was important. I've updated the question with the part that generates the file. The confusing thing is that update-initramfs doesn't pick cryptroot up in chroot and yet, without any modification, it works fine once booted. I wonder if debian installer does some more magic. – Rbjz Mar 4 '16 at 15:16
  • 1
    Your setup seems reasonable, although I don't get the point of modifying /usr/share/initramfs-tools/conf-hooks.d/cryptsetup. However, you could add set -x at the beginning of /usr/share/initramfs-tools/scripts/local-top/cryptroot and get some debug info (actually, lots, so a logged serial console is recommended) after regenerating the initramfs. Appending debug to your kernel command line might also help. – Ferenc Wágner Mar 5 '16 at 21:20
  • @FerencWágner, re modifying /usr/share/initramfs-tools/conf-hooks.d/cryptsetup - pure desperation :o) or else cryptsetup would not be included in initramfs at all. I'll try your debugging tips and update if I find something curious later. – Rbjz Mar 7 '16 at 19:49
  • 1
    You'd better echo CRYPTSETUP=y >/etc/initramfs-tools/conf.d/force-cryptsetup, otherwise your modifications will be lost on upgrade. Also, try using the dm-crypt device name (/dev/mapper/system) in your fstab and the kernel root= argument. – Ferenc Wágner Mar 8 '16 at 10:23

This will always work, even with an empty crypttab:

echo 'export CRYPTSETUP=y' > /etc/initramfs-tools/conf.d/cryptsetup

Alternatively, you can add this to /etc/environment:


Using /etc/initramfs-tools/conf.d/cryptsetup is deprecated in stretch.

The new preferred method is to set "CRYPTSETUP=y" in /etc/cryptsetup-initramfs/conf-hook.

  • Do not forget to install cryptsetup if you are bootstrapping. – ceremcem Dec 24 '19 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.