How to install Linux Mint on an encrypted system
How to install Linux Mint on an encrypted volume
One of the few things I miss about Fedora when using Ubuntu and related GNU/Linux distributions is the ease of setting up fairly complex disk partitioning schemes. I’m a big believer in disk mirroring (to protect against hard drive failure) and in encryption (to protect against data loss due to hardware theft), and Ubuntu requires use of an alternate, text-based installer while Linux Mint doesn’t even do that much.
Fortunately, this is Linux, which means I have all the tools I need to get this to work. Many thanks to this guide from 2008, which provided the base instructions.
Note that I do not set up software RAID (mirroring) in this case, as
these instructions are for a laptop. If you want mirroring, my advice
is to build two partitions on each mirror, one for /boot
and one for
the mirror volume, then build an encrypted volume atop the mirrored
volume; add that encrypted volume to a volume group; and finally build
logical volumes in that volume group.
A note about naming: throughout these instructions I refer to rootvg
as the root volume group. This is fine for small installations;
however, if you ever move disks between computers that also have
their own group called rootvg
, this causes trouble (generally,
failure to recognise the new physical and logical volumes). For that
reason, in practice I usually name my volume group with some unique
name, perhaps related to the hostname.
-
Boot from Linux Mint Katya DVD
-
Open the terminal from the menu (lower left-hand corner). Install the Logical Volume Manager with
sudo apt-get install lvm2
. -
If this drive has previously held unencrypted data:
- Open a web browser and visit some site to generate some entropy; install and play some games too.
sudo dd if=/dev/urandom of=/dev/sda bs=1M & sleep 5; while sudo pkill -USR1 dd; do sleep 60; done
(make sure to continue web browsing and playing games — when unattended, leave some music or videos playing)
-
Format the hard drive:
sudo fdisk /dev/sda
. Create a 512M primary partition 1 for/boot
(no BIOS that I’m aware of supports booting from an encrypted disk, so your boot partition must be plaintext) and then an extended partition 2 for the rest of the disk, with a logical partition 5 filling it. I’m sure there’s a GUI to do this too, but the command-line is easier and quicker. -
Create an encrypted volume:
sudo cryptsetup luksFormat -c aes-cbc-essiv:sha256 -s 256 /dev/sda5
(if you get an error, runsudo modprobe dm-crypt; sudo modprobe aes-i586
to install the crypto modules) -
Activate the new volume:
sudo cryptsetup luksOpen /dev/sda5 cryptpv
-
Create an LVM physical volume on the encrypted volume:
sudo pvcreate /dev/mapper/cryptpv
-
Create a LVM volume group:
sudo vgcreate rootvg /dev/mapper/cryptpv
-
Create a logical volume for your swap (virtual memory):
sudo lvcreate -L 4G -n swaplv perique
(where 4G is twice your RAM). -
Create a logical volume for your root filesystem:
sudo lvcreate -l 100%FREE -n rootlv rootvg
-
Format your boot partition:
sudo mkfs.ext2 /dev/sda1
-
Format your root partition:
sudo mkfs.ext4 -j /dev/mapper/rootvg-rootlv
-
Install Linux Mint as usual; the installer should detect the partition and logical volumes. Make sure to use the advanced partitioning tool. Format
/boot
as ext2; format/
as ext4 (the reason for formatting them earlier is so that the installer doesn’t get confused; I reformat in case the installer uses any special options). Do not use the swap as swap; the installer will be confused and believe that it is a physical volume. If others will have unsupervised login access, consider encrypting your home directory as well. -
Mount the new root on
/mnt
:sudo mount /dev/mapper/rootvg-rootlv /mnt
-
Mount the new /boot:
sudo mount /dev/sda1 /mnt/boot
-
Change root (this makes the current process think that
/mnt
is/
— which is another way of saying that it makes it appear that you’re working inside the freshly-installed system):sudo chroot /mnt
-
Mount special filesystems:
mount -t proc proc /proc; mount -t sysfs sys /sys; mount -t devpts devpts /dev/pts
-
Update the list of available software:
apt-get update
-
Install LVM2 on the freshly-installed system:
apt-get install lvm2
-
Update the cryptography table:
vi /etc/crypttab
:cryptpv /dev/sda5 none luks
-
Update the filesystem table:
vi /etc/fstab
:/dev/mapper/rootvg-swaplv none swap 0 0
-
Updated the list of modules installed in the boot-initialisation ramdisk (this may actually be overkill nowadays):
vi /etc/initramfs-tools/modules
:dm_mod dm_crypt sha256_generic aes-i586
-
Build the new initramfs:
update-initramfs -k all -c
-
Unmount the special filesystem:
umount /dev/pts; umount /sys; umount /proc
-
Exit the chroot jail:
exit
-
Unmount the boot filesystem:
sudo umount /mnt/boot
-
Unmount the freshly-installed root filesystem:
sudo umount /mnt
-
Format the swap logical volume:
sudo mkswap -L swap -f /dev/mapper/rootvg-swaplv
-
Reboot:
sudo shutdown -r now
After following these instructions, you should have a fully-encrypted root volume running Linux Mint.