This article provides a step-by-step guide on how to install an Ubuntu Linux system with full disk encryption (new installation). However, you should take a relaxed day as topical newbie for further reading. You don't have to keep everything in mind but it is never an error to acquaint oneself with something new.

The described setup was tested with the following versions (32bit and 64bit):

This how-to does not use the (IMHO inflexible) Alternate-CD crypto setup.

There will be a separate /home partition within the encrypted volume, making backups and fresh installations easier.

Despite the fact that there is more than one single encrypted partition, you only have to enter one single password during boot time. The Logical Volume Manager (LVM) is used to make this possible. LVM will be used as “crypto container”, containing the different partitions /, /home and swap.

You don't loose any comfort – apart from the password question when the system boots, you don't have to expect any changes during daily usage. This is also true regarding kernel and/or distribution updates, there is nothing special to keep in mind. Therefore it is really worth it to tough it out.

Suspend-to-disk (S4)/hibernation works (if it also would work on an unencrypted installation, for sure).

Creation of a LVM group on the unformatted, unlocked crypto partition, containing the root, home and swap partition.

Start of the graphical Ubuntu installation wizard, telling it to use the root, home and swap partition within the encrypted LVM group plus the small, unencrypted partition as /boot.

Do not reboot directly after the installation wizard finished its work. Change into the freshly installed system with chroot instead. This is needed to install the required software (LVM, LUKS/cryptsetup) on it (you won't be able to boot it otherwise).

However, you can still install and use the crypto system, even if you are not interested in this additional information.

Necessary preparations

A Ubuntu installation CD (not the Alternate-CD) to be able to start a live session: download

Working Internet connection. You have to install some additional software packages during the live session (for which Internet connection is necessary). It is probably most convenient to connect your system to a Internet router or something similar to prevent needless configuration at the live session. If your network card does not work out-of-the-box, you may want to temporarily install a cheap Realtek NIC or something like that.

Before you paralyze your real system, it is a good idea to try everything out in a virtual machine.

Semi-automatic installation by script (recommended)

I provide a crypt-setup bash script, making the system installation faster and easier. The scripts prompts the user to enter the needed data (target device, partition sizes, key length etc.) and processes the installation as described at “Manual installation” afterwards. This saves much typing and prevents errors. Using the script, a full disk encryption setup should only take a few minutes longer than a default installation.

Start the live session. Boot from the installation CD and start a live session (not the installer). The fitting menu item should be “Try Ubuntu” or something similar (the notation may vary a little bit, depending on the Ubuntu version and when/if a key was pressed). Please choose the language you are going to use on the installed system right from the start. This prevents problems regarding the keyboard layout and the password setup.1)

Run the script. Open a terminal and run the following commands to download and start the script (copy and paste recommended):

Manual installation

You have to replace sdX by your own target decive (e.g. sda or hda). Pay attention to this if you are going to copy & paste the commands.

Start the live session

Boot from the installation CD and start a live session (not the installer). The fitting menu item should be “Try Ubuntu” or something similar (the notation may vary a little bit, depending on the Ubuntu version and when/if a key was pressed). Please choose the language you are going to use on the installed system right from the start. This prevents problems regarding the keyboard layout and the password setup.2)

Install needed packages

Because the full disk encryption will be prepared by using a live session (which brings no more than what is absolutely necessary), you have to install some additional packages plus their dependencies for the running session (lvm2 and cryptsetup). Open a terminal and execute the following command:

sudo apt-get install lvm2 cryptsetup

You can't reboot for understandable reasons (→live session, your changes would be gone after a reboot). This is why you have to load a needed kernel module manually (provided by the packages you installed) using the termimal:

sudo modprobe dm-crypt

Now the current live session does provide everything you need to install the encrypted system.

Create needed partitions

You have to subdivide the target hard disk into two partitions. This will be done with GParted.3) Start it via terminal (→ gksudo gparted) or by clicking “System→Administration→GParted”

The following partitions are needed:

dev/sdX1, ext3, 200MB at the beginning
You can use up to 17 chars for the description. I chose “boot (no crypt)”.

dev/sdX2, unformatted, at least 8GB (the root, home and swap partitions need to find room).
You can use up to 17 chars for the description. I chose “sys (lvm,crypt)”. Normally, you should simply use all remaining space (how it was done in the following).

You can close GParted after all operations were applied (→ green check mark).

Prepare the device

If the target device stored unencrypted data until now, you may want to overwrite the partitions with random data first. This securely prevents all (theoretical!) risks to restore data fragments:

sudo shred -vn 1 /dev/sdX1
sudo shred -vn 1 /dev/sdX2

The whole process is also a good stress test of your hard disk but may needs several hours or even days (depending on the disk size and your CPU).

If your device was already encrypted (or you aren't a security fanatic) you may ignore this. You also should skip this if you are using a SSD.

The partition sdX2 will be prepared to act as crypto device by using the cryptsetup luksFormat command. This is also the moment to decide which encryption algorithm, chaining mode and initialization vector should be used. aes-xts-plain is recommended because it brings protection against so called “watermarking” and other known attacks plus encrypts your data securely by using AES:

sudo cryptsetup --cipher aes-xts-plain --key-size 512 --verify-passphrase luksFormat /dev/sdX2
[define the password. Attention: there will be no feedback like * or something similar]

Choose a long, secure password or pass phrase. Even the best encryption is nearly useless if your password is weak.

After formatting, the crypto device needs a name and has to be unlocked to make it possible for the installer to access it. The device is accessible via /dev/mapper/<chosen name> if everything works. I chose the name lvm_crypt:4)

sudo cryptsetup luksOpen /dev/sdX2 lvm_crypt

XTS supports 128 or 256 bit keys. In this case, the keysize of 512 means that both AES and XTS are using the maximum keysize of 256 bit. For slower systems, --key-size 256 comes into question which equates to a 128 bit encryption.

XTS is available since Ubuntu 8.04 (Hardy Heron) and is more secure than CBC. Therefore aes-xts-plain is preferable to the frequently-used aes-cbc-essiv:sha256 (however, it is still secure and there is no real alternative if an old kernel has to be used). aes-cbc-plain has to be considered as vulnerable, ESSIV instead of PLAIN as initialization vector is strongly recommended in combination with CBC.

The Logical Volume Manager (LVM) won't be used to connect multiple drives here. It is used to prevent the management of different keys respectively the need to type multiple passwords when booting the system. Because /home gets its own partition and swap is also encrypted, you normally would have to type a separate password for each partition. To bypass this annoyance, a LVM volume incl. LVM volume group will be generated within the opened crypto partition you created earlier by using the cryptsetup command. pvcreate is used to initialize the LVM volume, vgcreate creates the LVM volume group within the LVM volume:

Now you are able to create the needed partitions within the LVM volume respectively the LVM volume group ubuntu. Swap should be ~1.3 times greater as your installed RAM (at least if you want a solid suspend-to-disk (S4)/hibernation). If space is rare (e.g. when using a SSD), you certainly want to use less. But opinions about a sane swap size differ as much as the ones about the size of the root partition. This is why you should look at the following values as an example (but they can be adopted without any problems). The PC I used to write this article got 4GB RAM (→ multiplied by 1.3 = 5200MB swap) and I created a 25GB root partition:

If you need additional/other partitions, you can create them by using the same schema. If you have problems with the syntax, man lvcreate may be helpful.

You should format the created partitions to prevent problems with some versions of the graphical Ubuntu-installer ubiquity (during the graphical installation of the real system, the partitions will be formatted again. So don't worry if you want to choose another file system than EXT4: you can choose it there):

The needed preparations of the encrypted device are finished now. All needed partitions are existing and the installation of the real system can begin.

Installation of the system

Start the graphical Ubuntu installation wizard by clicking the “Install Ubuntu <version>” icon on the desktop:

After choosing language, time zone etc. you have to choose “specify partitions manually” at the “Prepare disk space” window (the notation may vary a little bit, depending on the used Ubuntu version). There you have to assign the partitions you created before:5)

Complete the setup by following the instructions of the installation wizard. You may activate the “Log in automatically” option (without bad conscience) to prevent the need for typing an additional password before logging in. The encryption password should be enough in single-user environments. Do NOT reboot the system after the installer finished. There is still some work to do.

If you would reboot your system now, the installed system couldn't boot. It still needs the software to access the encrypted drive and has to prompt the user for the password. Therefore we use chroot to change into the freshly installed system to install the needed packages lvm2 und cryptsetup (Attention: all following commands have to be executed within the same terminal window. And don't forget to replace sdX1 with your own partition, e.g. sda1):

Now, you are almost done. Ubuntu was installed into a LVM group on a crypted drive and has the software necessary to decrypt the data. In order to ask the drive to decipher automatically when booting the system, you have to write a fitting UUID entry for the /dev/sdX2 partition into the /etc/crypttab file. The following command detects the UUID and writes the needed line into /etc/crypttab (don't forget to replace sdX2 with your own partition, e.g. sda2):

The system has to inherit the /etc/crypttab changes now (you can ignore “cryptsetup: WARNING: invalid line in /etc/crypttab” and “Cannot find /lib/modules/[…]-generic” warnings):

update-initramfs -u -k all

Done . You should be asked for the password when booting the system. Work with your securely encrypted system as usual. Simply close the chroot environment and reboot your computer:

exit
sudo reboot

Tips and tricks

Change/add/remove passwords: LUKS is able to manage up to eight passwords at the same time. Each password will be stored in a so-called slot (0-7). The currently used slots of the encrypted partition can be printed out by using luksDump (don't forget to replace sdX2 with your own partition, e.g. sda2):

Access an encrypted system from a Live CD: In the case of emergency, it may be useful to have access to the encrypted files of a system installed by using this manual (you need the password, for sure). Boot the Live CD and install the needed software:

sudo apt-get install lvm2 cryptsetup
sudo modprobe dm-crypt

Open/decrypt the device (replace sda2 with your device if needed):

sudo cryptsetup luksOpen /dev/sda2 lvm

Activate the LVM to get /dev/ubuntu/home, /dev/ubuntu/root and /dev/ubuntu/swap:

Now you can access your home partition via /mnt/home, the root partition is located at /mnt/root. So you can copy or edit all of your data. If you don't have enough permissions to copy needed files, try it with a filemanager started with gksudo nautilus.

E.g. if you are starting an English live session to install a German system, X and Z are interchanged outside of the graphical installation wizard (compared to an U.S. keyboard). If your password – which has to be typed at the terminal – contains a X/x or Z/z, you would have to type another password on the freshly installed German system during its first boot than you supposedly defined during the setup

I followed the tutorial, combining it with manual partition creation because my disk uses Advanced Format so I had to align the partitions manually myself using parted. I also added one EFI partition needed for booting my laptop.

Everything went really well until the end and at the final reboot I get to the grub menu, I pick the kernel and then I get thrown to initramfs command line.
No password is asked before that to decrypt the LVM.

I followed your instruction (& went with the manual steps as I wanted to see how it was done) with Oneiric. It worked precisely as documented. Thank you very very much. I had dual boot (Windows XP and Ubuntu) on my laptop. The only additional thing I did was that before shutting down (for restart post installation), apart from the steps you mentioned was that I modified my XP boot.ini file as documented here: http://bkpavan.wordpress.com/2008/04/02/how-to-boot-linux-using-windows-bootloader-xp/. My Windows partition is completely unaffected which is great as I had backed up my data to it!

Nice article, quite handy for people who are not into full disk encryption, yet.

What I'm missing is a discussion of the weaknesses of XTS. It is not safe for use on large crypto devices and there are thus actually situations where aes-cbc-essiv provides better resistance than aes-xts-plain.

With a petabyte the attack success probability rate
decreases to at most eight in a trillion.

AFAIK, cbc-essiv also got some theoretical issues (watermarking…). However: I'm not a mathematician or information scientist with crypto-background. Do you have more information about the weaknesses of XTS regarding large amounts of data regarding? I especially mean the type of attacks resulting out of the XTS issues (Just Watermarking or decryption of partial/small amounts of data? Or breaking the whole encryption? …).

My question is regarding dual boot with another Linux distro. What are the necessary steps to get that working? Would I simply create the necessary partition inside the LVM, and assume that the two would share the same /boot partition?

Thank you for the script. Tested successfully on Lubuntu 11.04 to USB flash drive. One small problem, not sure if it's grub or something else. First, I get a blinking cursor and I have to press CTRL+ALT+F3 to see the graphics prompt to enter the passphrase. Is there a way to go straight to the prompt and to skip having to enter CTRL+ALT+F3?

I'm trying to install Mint 14 (new, don't know if that might have anything to do with it) on my new laptop using this guide. Everything works great until the installer reaches “configuring hardware” (one of the later stages) at which point it hangs. There's a debug terminal output, but it's only one line tall so unfortunately I can't get anything useful out of it.

I have done several Linux Mint 13 'Maya“ installs with this script and they all have worked well with one exception that we resolved (sort of)in-house. The login for an installed FDE fails on one box. It's difference from the other boxes is that it has a wireless keyboard (Logitech K520). The keyboard works at the grub menu and will work in the booted install but it does not work at the prompt for the luks password to unlock the sda2 partition. I've yet to figure out why this failure occurs. Our fix has been to replace the wireless keyboard with a wired keyboard. Other than that quirk things are great when using this routine. Thank you!

All that gets rid of the old installer, updates the repos, installs a new installer (and some other stuff), and the last command starts the new install DO NOT start the installer from the icon on the desktop.

If things aren't working for you in Linux Mint 14, look carefully after updating your initramfs (the last step). If you see a message mentioning “en_US.utf8” or something like that, try this command (note that this still needs to be in the chroot environment), and then try the initramfs command again:

@Anon: It should also be noted that you can't copy and paste the command I just wrote, because the – is actually supposed to be “dash dash”. If it is pasted into the terminal as it is seen here, it won't actually do anything. You should get a generation complete message when it is done.