5

Using the pre-installed Ubuntu Desktop 20.10 disk image for the Raspberry Pi 4 (64-bit ARM), you do not get an option to encrypt the disk using LUKS when you install the system, as you do with the x86 USB-based installers.

For reference, I followed the instructions here to get the system installed to an external SSD: https://ubuntu.com/tutorials/how-to-install-ubuntu-desktop-on-raspberry-pi-4#1-overview

In all, I am very satisfied with the install, but I would prefer if I was able to encrypt the whole drive. I don't want to bother figuring out how to just encrypt the home folder, so if anybody know hows to get a 20.10 install encrypted w/ LUKS at the time the OS is installed, I would appreciate hearing how you did it. Thanks!

3 Answers 3

7

EDIT: I misread the original question, but everything still applies. Using /dev/mmcblk0p2 below is for installing to the microSD card. To install to an external SSD/HD the device will likely be /dev/sda2. Use the appropriate device when editing cmdline.txt, crypttab, and booting for the first time via (initramfs).

The latest Ubuntu image includes cryptsetup, so you can convert the "writeable" (root) partition to LUKS using your desktop PC. I began with the 20.10 64-bit Server image.

  1. Prepare your SD card but do not install into the RPi. Keep it on your desktop PC.

  2. Unmount the SD card (/dev/sdc2 is my "writeable" (root) partition - yours may be different).

    sudo umount /dev/sdc2
    
  3. Check the partition: sudo e2fsck -f /dev/sdc2

  4. Shrink the partition: sudo resize2fs -M /dev/sdc2

  5. Encrypt the partition (RPi does not have hardware AES support, Adiantum seems to perform better)...

    sudo cryptsetup-reencrypt --new --reduce-device-size=16M --type=luks2 -c xchacha12,aes-adiantum-plain64 -s 256 -h sha512 --use-urandom /dev/sdc2
    
  6. Decrypt the LUKS partition: sudo cryptsetup luksOpen /dev/sdc2 rootfs

  7. Expand the partition: sudo resize2fs /dev/mapper/rootfs

  8. Mount the partition: sudo mkdir mnt; sudo mount /dev/mapper/rootfs mnt;

  9. Edit etc/crypttab... sudo vim mnt/etc/crypttab

    • Add rootfs /dev/mmcblk0p2 none luks
  10. Edit etc/fstab... sudo vim mnt/etc/fstab

    • Change the first line to /dev/mapper/rootfs / ext4 defaults,noatime 0 0
  11. On the system-boot partition, edit cmdline.txt...

    • change root=LABEL=writable to root=/dev/mapper/rootfs
    • remove splash (so it prompts for the passphrase on boot)
    • add cryptdevice=/dev/mmcblk0p2:sdcard to the end of the line
  12. It should look like this...

    dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mapper/rootfs rootfstype=ext4 elevator=deadline rootwait fixrtc quiet cryptdevice=/dev/mmcblk0p2:sdcard
    
  13. Unmount the microSD card and install into the Raspberry Pi. It will fail to boot and enter (initramfs) because initramfs hasn't been updated yet.

  14. Manually decrypt from initramfs: (initramfs) cryptsetup luksOpen /dev/mmcblk0p2 rootfs

  15. Continue booting: (initramfs) exit

  16. Login (ubuntu/ubuntu) and update initramfs: sudo update-initramfs -u

  17. Reboot: sudo reboot

It should reboot, prompt for the passphrase, then start the OS.

3
  • I am stuck with 2 things, (1) aes-adiantum-plain64 is not available on my machine, I wasted sometime on getting it but settled for aes-xts-plain64, it's much slower. (2) cryptsetup is not available in initramfs on debian 10 images for raspi 4, tried a couple of things to get it but nothing as worked so far! :-( Any further read ups would be appreciated. :-)
    – atb00ker
    Jan 10, 2021 at 14:45
  • If cryptsetup isn't already in the kernel, I'd think you'd have to chroot the image and emulate (arm) on your PC to install the needed packages, but that's above my level of expertise. This link might be helpful to get started.
    – Cameron
    Jan 12, 2021 at 20:18
  • 1
    any way to do this fully headless?
    – nisc
    Jul 5, 2021 at 6:52
3

Just adding to Cameron's answer, the Ubuntu 20.10 Desktop image for Pi 4 does not include cryptsetup in the initramfs. The easiest solution is to boot into unencrypted Ubuntu after writing it to SD card, connect to network, and then apt install cryptsetup-initramfs

After doing that, Cameron's steps worked perfectly for me. It also works for USB boot (after you have followed Ubuntu's instructions to update the eeprom and change the boot order) by replacing /dev/mmcblk0p2 with /dev/sda2

I thought it wasn't working at first and nearly gave up because the display was showing a single blinking underscore and not failing into the initramfs prompt. All I had to do was wait 7 minutes. I also had USB device read errors when trying to boot from USB, using an unpowered hub resolved that for some reason. I tried doing this on a Debian laptop first but it doesn't have Adiantum in cryptsetup. Then I tried a laptop booting Ubuntu from live USB and it failed to mount the Pi encrypted partition, I don't know why. I only had success after I installed Ubuntu 20.10 onto a laptop.

0

I have tried the above approach and this one https://github.com/ViRb3/pi-encrypted-boot-ssh/tree/8044e5036f2218146a6be443f480f289d860944a for 2 days and failed.

The solution was to use BerryBoot https://berryterminal.com/doku.php/berryboot that has luks encryption option at Ubuntu install time encrypt disk check

1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Pilot6
    Jun 30 at 18:10

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.