Full Disk Encryption
DeprecatedThis guide has been deprecated and is no longer being maintained.
Full disk encryption protects the information stored on your Linode’s disks by converting it into unreadable code that can only be deciphered by authorized individuals. Nearly everything on the disk is encrypted, including the swap space and temporary files. This guide will help you implement full disk encryption on a Linode running Debian 7 (Wheezy). You’ll learn how to:
- Format and encrypt your disks
- Install a base Debian 7 (Wheezy) system with
- Configure services and networking
- Boot from the encrypted images
Full disk encryption does a great job of keeping your data secure, but there are a few caveats. To decrypt and mount the disk, you’ll need to enter the encryption passphrase in the console every time your Linode boots. And some Linode Manager tools may not work as expected if your disks are encrypted. You’ll need to manually resize your filesystem if you want to resize your disk. You’ll also need to implement your own backup solution since the Linode Backup Service can’t mount encrypted disks.
Ready to encrypt your Linode’s disks? Here’s how to prepare a Linode for full disk encryption:
- Create a new Linode in the data center of your choice.
Make at least three unformatted / raw disks for your Linode. You’ll probably want to use the rest of your disk quota for your main disk.
/bootimage, which will be unencrypted. In most cases, 128-256MB will be suitable for /boot.
- A swap image. You’ll need to choose an appropriate swap size based your particular needs.
rootimage to store the files in the root of your filesystem.
After you have created these disks, you’ll want to boot into Finnix from the Rescue tab. Ensure that your disks are attached as follows:
- /boot xvda
- swap xvdb
- / xvdc
You’ve successfully created the disks for your Linode.
Creating a Configuration Profile
Next, you’ll need to create a configuration profile for the new Linode. Here’s how to do it:
- Create a new configuration profile in the Linode Manager.
- Select the
pv-grub-x86_64kernel from the Kernel menu.
- In the Block Device Assignment section, select the disks you created in the previous section of this guide.
- Disable the Automount devtmpfs and Distro Helper settings.
- Save the configuration profile.
Congratulations! You’re now ready to set up full disk encryption on your Linode.
Enabling Full Disk Encryption
Now you’re ready to enable full disk encryption on your Linode running Debian 7 (Wheezy). Here’s how to do it:
- Reboot into Finnix from the Rescue tab in the Linode Manager.
- Connect to LISH, which will allow you to access the Linode’s virtual console.
Enter the following command to create an encrypted volume. You’ll be prompted for a passphrase. Make sure that you enter a very strong passphrase, and that you store the passphrase in a physically secure location. Or better yet, memorize the passphrase and don’t store it anywhere! :
cryptsetup luksFormat /dev/xvdc
CautionIf you lose this passphrase your data will be irretrievable!
NoteYou may receive a FATAL notice about loading a kernel module used for hardware crypto acceleration. This message can be safely ignored.
Open this encrypted device for access by entering the following command. Enter your passphrase when prompted.
cryptsetup luksOpen /dev/xvdc crypt-xvdc
Create the file systems by entering the following commands, one by one. Use
mke2fs /dev/xvda mke2fs -j /dev/mapper/crypt-xvdc
Create and activate your swap partition by entering the following commands, one by one:
cryptsetup -d /dev/urandom create crypt-swap /dev/xvdb mkswap /dev/mapper/crypt-swap swapon /dev/mapper/crypt-swap
NoteSwap will not persist through reboots, so a random key will be used to encrypt swap data.
Mount the encrypted volume to make it writable by entering the following commands, one by one:
mkdir mnt mount /dev/mapper/crypt-xvdc mnt/
You have successfully enabled full disk encryption, created the file systems, and mounted the encrypted volume.
Installing Debian and Mounting the Disks
Now it’s time to install Debian 7 (Wheezy) and mount the disks. Here’s how to do it:
debootstrapto install a minimal Debian installation by entering the following command:
debootstrap --arch=amd64 --include=openssh-server,vim,nano,cryptsetup wheezy mnt/
/dev/xvdaand a few other things in preparation for changing root into the newly created Debian system, then changing root into the new install. Enter the following commands, one by one:
mount /dev/xvda mnt/boot/ mount -o bind /dev mnt/dev/ mount -o bind /dev/pts/ mnt/dev/pts mount -t proc /proc/ mnt/proc/ mount -t sysfs /sys/ mnt/sys/ chroot mnt/ /bin/bash
You have successfully installed Debian and mounted the disks on your Linode.
Now that you’re “inside” the newly installed Debian system, you’ll need to make the following changes to create a system that boots and works correctly. Please follow these steps with care. Any error will mean your system will not boot! Here’s how to configure Debian:
/etc/crypttabto match the following:
crypt-xvdc /dev/xvdc none luks crypt-swap /dev/xvdb /dev/urandom swap
/etc/fstabto match the following:
/dev/xvda /boot ext2 defaults /dev/mapper/crypt-xvdc / ext4 noatime,errors=remount-ro /dev/mapper/crypt-swap none swap sw proc /proc proc defaults
/etc/mtabby entering the following command:
cat /proc/mounts > /etc/mtab
Configure console access. Note that your console must be configured correctly to boot. Edit
/etc/inittaband find the following line:
0:2345:respawn:/sbin/getty 38400 tty1
Change the line in
/etc/inittabto match the following:
0:2345:respawn:/sbin/getty 38400 hvc0
Install a kernel and a bootloader, and then configure the bootloader to boot your kernel by entering the following commands, one by one:
mkdir /boot/grub apt-get install grub-legacy apt-get install linux-image-amd64
Locate the following line in
# kopt=root=/dev/mapper/crypt-xvdc ro
Change the line in
/boot/grub/menu.lstto match the following. This will allow update-grub to properly generate a new menu.lst when you update your kernel.
# kopt=root=/dev/mapper/crypt-xvdc console=hvc0 ro
update-gruband generate a new
initramfsby entering the following commands, one by one:
update-grub update-initramfs -u
You have successfully configured Debian for full disk encryption.
You’re almost finished! Just a couple more steps and you’ll have a Linode with encrypted disks:
You’ll need to make some changes to the structure in
/bootdue to the way pvgrub expects to see your boot disk. Enter the following commands, one by one:
cd /boot mkdir boot/ mv grub boot/ ln -nfs boot/grub grub
Set the password for the root user by entering the following command:
Configure networking by editing
/etc/network/interfacesto match the following:
auto lo eth0 iface lo inet loopback iface eth0 inet dhcp
chroot, unmount your disks, and reboot. You can do this by detaching the screen session and entering the “reboot” command in LISH:
exit umount -l mnt/ ^a^d reboot 1
If everything is configured properly your Linode will boot and prompt you for the encryption passphrase. Enter the passphrase on your console to mount your encrypted disk and boot your Linode. Now you’ll want to follow the steps in our Getting Started guide.
Join our Community
Find answers, ask questions, and help others.
This guide is published under a CC BY-ND 4.0 license.
Leave a Reply