Full Disk Encryption Using Ubuntu In Most Secure Mode With AES-XTS-PLAIN64

Full Disk Encryption (FDE) is one of the best ways you can ensure all of the private information on your laptop stays private in case it’s lost, seized, stolen, or if you choose to sell or give away your computer in the future. This feature has been built-in to many GNU/Linux distributions, including Ubuntu, for many years. But until the recent release of Ubuntu 12.10, it was hidden away in the “alternate” text-mode installer of Ubuntu that many non-technical users don’t even know exists.
Unlike passwords, full disk encryption can make the contents of a drive inaccessible to a powerful attacker who has possession of your computer. FDE provides the opportunity to protect your data with military-grade encryption that can’t be compromised on a reasonable timeframe. At least, not by any currently-known means. The only way to access the files protected by full disk encryption is to obtain the encryption key.
AES-XTS provides the most secure mode of full disk encryption. Unfortunately, it’s not available by default in many Linux installation packages. Ubuntu’s “alternate” installation image provides other implementations like AES-CBC, but not aes-xts-plain or aes-xts-plain64. If aes-cbc is good enough for you, it’s been available in the Ubuntu alternate installer for quite some time. A thorough but dated guide outlining the process is available here.
By downloading an Ubuntu desktop installation image and doing a little initial setup, you can use aes-xts-plain64 on your system. Aes-xts-plain and aes-xts-plain64 both provide the same mode of operation, but you’ll need to use aes-xts-plain64 if you want to format a partition larger than 2TB. Also, it’s important to note that using very large block sizes for XTS mode could lead to security issues. Using 512 byte block sizes mitigates this issue.

How to install Ubuntu with aes-xts-plain64 (summary here)

  1. Download the Ubuntu desktop installation image and boot into a live desktop.
  2. Install a few necessary packages.
  3. Encrypt your destination disk with aes-xts-plain64 and mount it with LUKS
  4. Install ubuntu onto the encrypted disk
  5. Set up an encrypted swap partition
  6. Initialize the system so it can boot to the encrypted disk
  7. Reboot into your new installation

This process can be applied to other flavors of Linux with minimal modification. The same basic method should work on most systems.

Expert instructions/Quickstart summary

If you feel confident using an abbreviated guide, this contains an outline with all the commands.

Download the Ubuntu Desktop installer and boot into live mode

Get the current desktop installation image from Ubuntu and instead of going straight into installation, select the “try without installing” option to boot into a live desktop. After Canonical’s Gnome 3/Unity disaster, I switched to xfce (so did Linus Torvalds), so this guide describes the process of installing Xubuntu.
Once in the live desktop, open gparted and set up your partitions. I set up mine like this:
In my case, I created a 200 megabyte ext4 partition for /boot. /boot needs to be unencrypted in order for your computer to start! I will use the second, 2GB partition as swap space. The remainder of the disk will hold the root partition. You don’t need to format anything but the /boot partition right now.
I was installing to a blank (virtual) disk, so I went to Device > create partition table to set up the disk.

Install necessary packages for aes-xts-plain64

Once the disk layout is complete, close gparted, open a terminal and install lvm2. Other guides to full disk encryption in Linux use LVM on top of physical partitions. For me, this would only add extra overhead. I prefer to use plain partitions.
Install lvm2 for aes-xts-plain

$ sudo -i
# apt-get install lvm2

Encrypt the destination disk with aes-xts-plain and mount it

Use cryptsetup luksFormat to encrypt your disk and mount it with luksOpen:
cryptsetup aes-xts-plain64

# cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 /dev/sda3
# cryptsetup luksOpen /dev/sda3/ crypt
# mkfs.ext4 /dev/mapper/crypt
# mkswap /dev/sda2
#cryptsetup luksOpen /dev/sda3/ crypt will mount the newly-created container to /dev/mapper/crypt. You can choose whatever name you prefer. This will be the location of the root partition.

# mkfs.ext4 /dev/mapper/crypt will format the drive to ext4, while  #mkswap /dev/sda2 creates a temporary, unencrypted swap space.

Install Ubuntu on to the disk

Once formatting is complete, go to the desktop and click the installer icon. When it asks if you want to use the whole disk, click “do something else” and specify your partitions manually. Here is what mine looked like:
Right click the partitions to specify mount points. I put /boot into the 200 megabyte /dev/sda1 partition and / onto /dev/mapper/crypt.
Important: During some installations, Ubuntu will choose the USB as the device for boot loader installation. Be sure the correct hard disk is selected for bootloader installation!
Once the disk is set up, proceed with installation as normal. When installation is complete, don’t reboot! Click “continue testing!”

Initialize the system so it can boot to the encrypted drive

Open a terminal and mount your newly-installed root partition to a directory so we can make some changes:
Mount the aes-xts-plain64-encrypted root partition:

$ sudo -i
# cd /mnt
# mkdir root
# mount /dev/mapper/crypt root
# mount /dev/sda1 root/boot
This mounts the newly-created / and /boot partitions to /mnt/root and /mnt/root/boot respectively. Now, chroot into your root partition:
chroot cryptsetup:

# sudo chroot root
# mount -t proc proc /proc
# mount -t sysfs sys /sys
# mount -t devpts devpts /dev/pts
# apt-get update
# apt-get install lvm2 cryptsetup
 Now the new system has all the packages it needs to work with its encrypted partitions (Note: make sure you install cryptsetup! Otherwise you’ll get the “cryptsetup: evms_activate is not available” error). Open a new terminal and type  sudo blkid . This will list the system’s partitions, their UUIDs and their types.
Take the UUID of /dev/sda3 (or whatever drive you luksFormatted. It will have Type=”crypto_LUKS” next to it in the blkid output) and paste it into the bottom line of your new system’s /etc/crypttab in the following format: crypt UUID=[the UUID of /dev/sda3 from blkid] none luks.
When /etc/crypttab has been changed, update your initramfs so it can boot to the encrypted root partition:

$ sudo update-initramfs -u

Set up an encrypted swap partition

Turn off your swap and initialize it with cryptsetup by issuing the following commands:

$ sudo swapoff -a
$ sudo cryptsetup -d /dev/urandom create cryptswap /dev/sda2
$ sudo mkswap -f /dev/mapper/cryptswap -v1

When mkswap is complete, add the following line to /etc/crypttab: cryptswap /dev/sda2 /dev/urandom swap. This will encrypt your swap with a random key on each boot. Encrypting your swap like this will break hibernation, but I never use hibernation anyway. If you still want to use hibernation, check out this guide.
The completed /etc/crypttab on my new installation looked like this:

# <target name>    <source device>        <key file>    <options>
crypt UUID=bf102bf0-88f5-4b6d-b4f0-8893021e15fc none luks
cryptswap /dev/sda2 /dev/urandom swap

Now, open your new system’s /etc/fstab and change it to look like this:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
/dev/mapper/crypt /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=fc72c3e1-dee7-4776-b433-96ace3db4633 /boot           ext4    defaults        0       2
# swap was on /dev/sda2 during installation
/dev/mapper/cryptswap none            swap    sw              0       0

Verify that the root filesystem is /dev/mapper/crypt (or whatever you named your encrypted root partition). Alter the swap partition’s line to reflect the changes you made in /etc/crypttab. Before editing, the last line of my fstab read /dev/sda2 none swap sw 0 0  and I changed it to  /dev/mapper/cryptswap none swap sw 0 0 .
After you’ve double-checked that the values in /etc/fstab match the values in /etc/crypttab, your system is ready to reboot! If everything went well, you should be greeted with an “Enter passphrase” prompt after startup:
If you chose a secure passphrase and you can’t remember it now, you’ll need to reinstall the system. That’s the beauty of well-implemented encryption: there is no way around it (for now). Other than the passphrase prompt at boot, full disk encryption is completely transparent. It doesn’t feel any different from working on an unencrypted system. Once your system boots and you log in, verify that your swap is encrypted by viewing /proc/swaps:
If /proc/swaps shows that your swap is on a mapped drive, it’s encrypted. If it says your swap is on a physical partition like “/dev/sda2,” something is wrong.
Assuming everything worked, if your hard drive falls in to the wrong hands, wish them good luck with getting info from it.

No ratings yet.

Please rate this article

Spread the love

4 thoughts on “Full Disk Encryption Using Ubuntu In Most Secure Mode With AES-XTS-PLAIN64”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.