Ubuntu Installation – Manual Full-Disk Encryption “LVM on Luks”

Tested on Ubuntu 14.04 – 14.10 – 15.04 – 15.10.

In this presentation, we start from a clean disk. We’re going to create this structure :

Step by step

  1. Boot from an Ubuntu live DVD or USB stick, and select “Try Ubuntu”.
  2. Create two partitions using GParted included in the live disk. The first partition should be unformatted and should be large enough for root and swap, in my example, this is /dev/sda3. The second partition should be several hundred megabytes big and formatted in ext2 or ext3, it will be unencrypted and mounted to /boot (in my example this is /dev/sda4).In this screenshot, I have an existing unencrypted Ubuntu installation in two partitions: /dev/sda1 and /dev/sda5, highlight in the circle to the left. I have created an unformatted partition in /dev/sda3 and an ext3 partition in /dev/sda4, intended for the encrypted Ubuntu installation, higlighted in the circle to the right:
  3. Create a LUKS container using these commands. Replace /dev/sda3 with the unformatted partition created earlier, and CryptDisk with a name of your choice.
  4. Inside the mounted LUKS container, create an LVM physical volume, a volume group and two logical volumes. The first logical volume will be mounted at /, and the second one will be used as swap. lvm-vg is the name of the volume group, and ubuntu-root and swap are the names of the logical volumes, you can choose your own.
  5. Create filesystems for the two logical volumes: (You can also do this step directly from the installer.)
  6. Install Ubuntu using the graphical installer, choosing manual partitioning. Assign / to /dev/mapper/lvm-vg-ubuntu-root and /boot to the unencrypted partition created in step 2 (in this example,/dev/sda4).
  7. Once the graphical installer is finished, select “continue testing” and open a terminal.
  8. Find the UUID of the LUKS partitions (/dev/sda3 in this case), you will need it later:
  9. Mount the appropriate devices to the appropriate locations in /mnt, and chroot into it:
  10. Create a file named /etc/crypttab in the chrooted environment to contain this line, replacing the UUID value with the UUID of the LUKS partition, and lvm-vg with the name of the volume group:
  11. Create a file named /etc/initramfs-tools/conf.d/cryptroot in the chrooted environment to contain this line, replacing CryptDisk with the name used to open the LUKS container, and the UUID value with the UUID of the LUKS partition:
  12. Run the following command in the chrooted environment:
  13. Edit the file named /etc/default/grub in the chrooted envirnoment, find the line that looks like this:

    Change it to look like this, replacing CryptDisk, lvm-vg and the UUID value with the appropriate values:
  14. Run the following command in the chrooted environment:
  15. Reboot and boot into the encrypted Ubuntu. You should be prompted for a password.
  16. Check that you’re using the encrypted partition for / by running mount:
  17. Check that you’re using the encrypted swap partition (not any unencrypted swap partitions from any other installations) by running this command:
  18. Check that you can boot into recovery mode, you don’t want to find out later during an emergency that recovery mode doesn’t work :)
  19. Install any updates, which are likely to rebuild the ramdisk and update the grub configuration. Reboot and test both normal mode and recovery mode.

Fix Ubuntu