Dm-Crypt/encrypting An Entire System: Dm-Crypt. They Explain All The Adaptations That Need To Be Done To The Normal
Dm-Crypt/encrypting An Entire System: Dm-Crypt. They Explain All The Adaptations That Need To Be Done To The Normal
dm-crypt/Encrypting an entire
system
From ArchWiki
Back to dm-crypt.
The following are examples of common scenarios of full system encryption with
dm-crypt. They explain all the adaptations that need to be done to the normal
installation procedure. All the necessary tools are on the installation image
(https://www.archlinux.org/download/).
Contents
1 Overview
2 Simple partition layout with LUKS
2.1 Preparing the disk
2.2 Preparing non-boot partitions
2.3 Preparing the boot partition
2.4 Mounting the devices
2.5 Conguring mkinitcpio
2.6 Conguring the boot loader
3 LVM on LUKS
3.1 Preparing the disk
3.2 Preparing the logical volumes
3.3 Preparing the boot partition
3.4 Conguring mkinitcpio
3.5 Conguring the boot loader
4 LUKS on LVM
4.1 Preparing the disk
4.2 Preparing the logical volumes
4.3 Preparing the boot partition
4.4 Conguring mkinitcpio
4.5 Conguring the boot loader
4.6 Conguring fstab and crypttab
4.7 Encrypting logical volume /home
5 LUKS on software RAID
6 Plain dm-crypt
6.1 Preparing the disk
6.2 Preparing the non-boot partitions
6.3 Preparing the boot partition
1 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Overview
Securing a root lesystem is where dm-crypt excels, feature and
performance-wise. Unlike selectively encrypting non-root lesystems, an
encrypted root lesystem can conceal information such as which programs are
installed, the usernames of all user accounts, and common data-leakage vectors
such as mlocate and /var/log/ . Furthermore, an encrypted root lesystem makes
tampering with the system far more dicult, as everything except the boot loader
and (usually) the kernel is encrypted.
All scenarios illustrated in the following share these advantages, other pros and
cons dierentiating them are summarized below:
2 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Simple partitioning
with knowledge of
LVM
#LVM on LUKS Only one key required
LVM adds an additional
to unlock all volumes
achieves partitioning mapping layer and
(e.g. easy resume-
exiblity by using hook
from-disk setup)
LVM inside a single Less useful, if a
Volume layout not
LUKS encrypted singular volume should
transparent when
partition. receive a separate key
locked
Easiest method to
allow suspension to
disk
Complex; changing
LVM can be used to volumes requires
#LUKS on LVM have encrypted changing encryption
volumes span multiple mappers too
uses dm-crypt only
disks Volumes require
after the LVM is
Easy mix of individual keys
setup.
un-/encrypted volume LVM layout is
groups transparent when
locked
#Plain dm-crypt
3 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
#Encrypted boot
partition (GRUB)
Same advantages as
Same disadvantages as
shows how to encrypt the scenario the
the scenario the
the boot partition installation is based on
installation is based on
(LVM on LUKS for this
using the GRUB (LVM on LUKS for this
particular example)
bootloader. particular example)
Less data is left
This scenario also More complicated
unencrypted, i.e. the
employs an ESP conguration
boot loader and the
partition, which may Not supported by other
ESP partition, if
be applied to the boot loaders
present
other scenarios.
While all above scenarios provide much greater protection from outside threats
than encrypted secondary lesystems, they also share a common disadvantage:
any user in possession of the encryption key is able to decrypt the entire drive,
and therefore can access other users' data. If that is of concern, it is possible to
use a combination of blockdevice and stacked lesystem encryption and reap the
advantages of both. See Disk encryption to plan ahead.
If you anticipate to protect the system's data not only against physical theft, but
also have a requirement of precautions against logical tampering, see
Dm-crypt/Specialties#Securing the unencrypted boot partition for further
possibilities after following one of the scenarios.
+--------------------+--------------------------+--------------------------+
|Boot partition |LUKS encrypted system |Optional free space |
| |partition |for additional partitions |
|/dev/sdaY |/dev/sdaX |or swap to be setup later |
+--------------------+--------------------------+--------------------------+
4 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
The rst steps can be performed directly after booting the Arch Linux install
image.
Prior to creating any partitions, you should inform yourself about the importance
and methods to securely erase the disk, described in Dm-crypt/Drive preparation.
Then create the needed partitions, at least one for / (e.g. /dev/sdaX ) and /boot (
/dev/sdaY ), see Partitioning.
The following commands create and mount the encrypted root partition. They
correspond to the procedure described in detail in Dm-crypt/Encrypting a
non-root le system#Partition (which, despite the title, can be applied to root
partitions, as long as mkinitcpio and the boot loader are correctly congured). If
you want to use particular non-default encryption options (e.g. cipher, key length),
see the encryption options before executing the rst command:
# umount /mnt
# cryptsetup close cryptroot
# cryptsetup open /dev/sdaX cryptroot
# mount -t ext4 /dev/mapper/cryptroot /mnt
If you created separate partitions (e.g. /home ), these steps have to be adapted and
repeated for all of them, except for /boot . See Dm-crypt/Encrypting a non-root le
system#Automated unlocking and mounting on how to handle additional
partitions at boot.
Note that each blockdevice requires its own passphrase. This may be
inconvenient, because it results in a separate passphrase to be input during boot.
An alternative is to use a keyle stored in the system partition to unlock the
separate partition via crypttab . See Dm-crypt/Device encryption#Using LUKS to
Format Partitions with a Keyle for instructions.
What you do have to setup is a non-encrypted /boot partition, which is needed for
5 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
a crypted root. For a standard MBR/non-EFI /boot partition, for example, execute:
At Installation guide#Mount the partitions you will have to mount the mapped
devices, not the actual partitions. Of course /boot , which is not encrypted, will
still have to be mounted directly.
Conguring mkinitcpio
etc/mkinitcpio.conf
Depending on which other hooks are used, the order may be relevant. See
dm-crypt/System conguration#mkinitcpio for details and other hooks that you
may need.
In order to unlock the encrypted root partition at boot, the following kernel
parameters need to be set by the boot loader:
cryptdevice=UUID=<device-UUID>:cryptroot root=/dev/mapper/cryptroot
The <device-UUID> refers to the UUID of /dev/sdaX , see Persistent block device
naming for details.
LVM on LUKS
The straight-forward method is to set up LVM on top of the encrypted partition
instead of the other way round. Technically the LVM is setup inside one big
encrypted blockdevice. Hence, the LVM is not transparent until the blockdevice is
6 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
unlocked and the underlying volume structure is scanned and mounted during
boot.
+-----------------------------------------------------------------------+ +----------------+
| Logical volume1 | Logical volume2 | Logical volume3 | | |
|/dev/mapper/MyVol-swap |/dev/mapper/MyVol-root |/dev/mapper/MyVol-home | | Boot partition |
|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _| | (may be on |
| | | other device) |
| LUKS encrypted partition | | |
| /dev/sdaX | | /dev/sdbY |
+-----------------------------------------------------------------------+ +----------------+
This method does not allow you to span the logical volumes over multiple disks,
even in the future. The #LUKS on LVM method does not have this limitation.
Prior to creating any partitions, you should inform yourself about the importance
and methods to securely erase the disk, described in Dm-crypt/Drive preparation.
When using the GRUB bootloader together with GPT, create a BIOS Boot Partition
as explained in GRUB#BIOS systems.
Create a partition of type 8E00 , which will later contain the encrypted container.
Create the LUKS encrypted container at the "system" partition. Enter the chosen
password twice.
For more information about the available cryptsetup options see the LUKS
7 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
# pvcreate /dev/mapper/lvm
Create the volume group named MyVol (or whatever you want), adding the
previously created physical volume to it:
# mkfs.ext4 /dev/mapper/MyVol-root
# mkfs.ext4 /dev/mapper/MyVol-home
# mkswap /dev/mapper/MyVol-swap
The bootloader loads the kernel, initramfs, and its own conguration les from
the /boot directory. This directory must be located on a separate unencrypted
lesystem.
8 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Create an Ext2 lesystem on the partition intended for /boot . Any lesystem that
can be read by the bootloader is eligible.
# mkfs.ext2 /dev/sdbY
# mkdir /mnt/boot
Conguring mkinitcpio
/etc/mkinitcpio.conf
Note: The order of both hooks no longer matters with the current
implementation of lvm2 .
In order to unlock the encrypted root partition at boot, the following kernel
parameters need to be set by the boot loader:
cryptdevice=UUID=device-UUID:lvm root=/dev/mapper/MyVol-root
The <device-UUID> refers to the UUID of /dev/sdaX , see Persistent block device
naming for details.
LUKS on LVM
9 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
To use encryption on top of LVM, the LVM volumes are set up rst and then used
as the base for the encrypted partitions. This way, a mixture of encrypted and
non-encrypted volumes/partitions is possible as well. Unlike #LVM on LUKS, this
method allows normally spanning the logical volumes over multiple disks.
The following short example creates a LUKS on LVM setup and mixes in the use of
a key-le for the /home partition and temporary crypt volumes for /tmp and /swap .
The latter is considered desirable from a security perspective, because no
potentially sensitive temporary data survives the reboot, when the encryption is
re-initialised. If you are experienced with LVM, you will be able to ignore/replace
LVM and other specics according to your plan. If you want to span a logical
volume over multiple disks during setup already, a procedure to do so is described
in Dm-crypt/Specialties#Expanding LVM on multiple disks.
Partitioning scheme:
10 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Now after setup of the encrypted LVM partitioning, it would be time to install:
Arch Install Scripts.
Conguring mkinitcpio
etc/mkinitcpio.conf
In order to unlock the encrypted root partition at boot, the following kernel
parameters need to be set by the boot loader:
cryptdevice=/dev/lvm/lvroot:cryptoroot root=/dev/mapper/cryptoroot
/etc/fstab
The following crypttab options will re-encrypt the temporary lesystems each
reboot:
/etc/crypttab
11 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Since this scenario uses LVM as the primary and dm-crypt as secondary mapper,
each encrypted logical volume requires its own encryption. Yet, unlike the
temporary lesystems congured with volatile encryption above, the logical
volume for /home should be persistent, of course. The following assumes you have
rebooted into the installed system, otherwise you have to adjust paths. To safe on
entering a second passphrase at boot for it, a keyle is created:
/etc/crypttab
/etc/fstab
If you want to expand the logical volume for /home (or any other volume) at a later
point, it is important to note that the LUKS encrypted part has to be resized as
well. For a procedure see Dm-crypt/Specialties#Expanding LVM on multiple
disks.
Plain dm-crypt
This scenario sets up a system on a dm-crypt a full disk with plain mode
encryption. Note that for most use cases, the methods using LUKS described
above are the better options for both system encryption and encrypted partitions.
LUKS features like key management with multiple pass-phrases/key-les are
12 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
dm-crypt plain mode does not require a header on the encrypted disk: this means
that an unpartitioned, encrypted disk will be indistinguishable from a disk lled
with random data, which is the desired attribute for this scenario, see also
Wikipedia:Deniable encryption.
Plain dm-crypt encrypted disks can be more resilient to damage than LUKS
encrypted disks, because it does not rely on an encryption master-key which can
be a single-point of failure if damaged. However, using plain mode also requires
more manual conguration of encryption options to achieve the same
cryptographic strength. See also Disk encryption#Cryptographic metadata.
Tip: If headerless encryption is your goal but you are unsure about the lack of
key-derivation with plain mode, then two alternatives are:
tcplay which oers headerless encryption but with the PBKDF2 function, or
dm-crypt LUKS mode by using the cryptsetup --header option. It cannot be
used with the standard encrypt hook, but the hook may be modied.
The scenario uses a USB stick for the boot device and another one to store the
encryption key. The disk layout is:
/bootand the boot loader cannot be kept on the encrypted drive, or it will defeat
the purpose of using plain mode for deniable encryption. This also allows storing
the options required to open/unlock the plain encrypted device in the boot loader
conguration, since typing them on each boot would be error prone.
This scenario also uses a key le, assuming it stored as raw bits on a second USB
stick, so that to the eyes of an unaware attacker who might get the usbkey the
encryption key will appear as random data instead of being visible as a normal
le. See also Wikipedia:Security through obscurity, follow Dm-crypt/Device
encryption#Keyles to prepare the keyle.
Tip:
It is also possible to use a single usb key by copying the keyle to the
13 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
It is vital that the mapped device is lled with data. In particular this applies to
the scenario usecase we apply here.
Using the device /dev/sdX , with the twosh-xts cipher with a 512 bit key size and
using a keyle we have the following options for this scenario:
Unlike encrypting with LUKS, the above command must be executed in full
whenever the mapping needs to be re-established, so it is important to remember
the cipher, hash and key le details.
We can now check a mapping entry has been made for /dev/mapper/enc :
# fdisk -l
Next, we setup LVM logical volumes on the mapped device, see LVM#Installing
Arch Linux on LVM for further details:
# pvcreate /dev/mapper/enc
# vgcreate store /dev/mapper/enc
# lvcreate -L 20G store -n root
# lvcreate -L 10G store -n swap
# lvcreate -l 100%FREE store -n home
We format and mount them and activate swap, see File systems#Format a device
for further details:
# mkfs.ext4 /dev/store/root
14 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
# mkfs.ext4 /dev/store/home
# mount /dev/store/root /mnt
# mkdir /mnt/home
# mount /dev/store/home /mnt/home
# mkswap /dev/store/swap
# swapon /dev/store/swap
The /boot partition can be installed on the standard vfat partition of a USB stick,
if required. But if manual partitioning is needed, then a small 200MB partition is
all that is required. Create the partition using a partitioning tool of your choice.
# mkfs.ext2 /dev/sdY1
# mkdir /mnt/boot
# mount /dev/sdY1 /mnt/boot
Conguring mkinitcpio
etc/mkinitcpio.conf
In order to boot the encrypted root partition, the following kernel parameters
need to be set by the boot loader:
15 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Tip: If using GRUB, you can install it on the same USB as the /boot partition
with:
Post-installation
You may wish to remove the USB sticks after booting. Since the /boot partition is
not usually needed, the noauto option can be added to the relevant line in
/etc/fstab :
/etc/fstab
# /dev/sdYn
/dev/sdYn /boot ext2 noauto,rw,noatime 0 2
# mount /boot
+---------------+----------------+----------------+----------------+----------------+
|ESP partition: |Boot partition: |Volume 1: |Volume 2: |Volume 3: |
| | | | | |
|/boot/efi |/boot |root |swap |home |
| | | | | |
| | |/dev/store/root |/dev/store/swap |/dev/store/home |
|/dev/sdaX |/dev/sdaY +----------------+----------------+----------------+
|unencrypted |LUKS encrypted |/dev/sdaZ encrypted using LVM on LUKS |
+---------------+----------------+--------------------------------------------------+
16 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Tip: All scenarios are intended as examples. It is, of course, possible to apply
both of the two above distinct installation steps with the other scenarios as well.
See also the variants linked in #LVM on LUKS.
Prior to creating any partitions, you should inform yourself about the importance
and methods to securely erase the disk, described in Dm-crypt/Drive preparation.
Create an EFI System Partition (ESP) with an appropriate size, it will later be
mounted at /boot/efi .
Tip: When using the GRUB bootloader together with a BIOS/GPT, create a BIOS
Boot Partition as explained in GRUB#BIOS systems instead of the ESP.
Create a partition of type 8E00 , which will later contain the encrypted container.
For more information about the available cryptsetup options see the LUKS
encryption options prior to above command.
gdisk /dev/sda
17 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
The LVM logical volumes of this example follow the exact layout as the previous
scenario. Therefore, please follow Preparing the logical volumes above or adjust
as required.
The bootloader loads the kernel, initramfs, and its own conguration les from
the /boot directory.
First, create the LUKS container where the les will be located and installed into:
Create a lesystem on the partition intended for /boot . Any lesystem that can be
read by the bootloader is eligible:
# mkfs.ext2 /dev/mapper/cryptboot
# mkdir /mnt/boot
Create a mountpoint for the ESP at /boot/efi for compatibility with grub-install
and mount it:
# mkdir /mnt/boot/efi
# mount /dev/sdaX /mnt/boot/efi
At this point, you should have the following partitions and logical volumes inside
of /mnt :
lsblk
18 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
Conguring mkinitcpio
/etc/mkinitcpio.conf
In order to unlock the encrypted root partition at boot, the following kernel
parameters need to be set by the boot loader:
cryptdevice=UUID=<device-UUID>:lvm root=/dev/mapper/MyStorage-rootvol
The <device-UUID> refers to the UUID of /dev/sdaX , see Persistent block device
naming for details.
GRUB_ENABLE_CRYPTODISK=y
# grub-mkconfig -o /boot/grub/grub.cfg
19 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
If this nished without errors, GRUB should prompt for the passphrase to unlock
the /boot partition after the next reboot.
This section deals with extra conguration to let the system mount the encrypted
/boot .
While GRUB asks for a passphrase to unlock the encrypted /boot after above
instructions, the partition unlock is not passed on to the initramfs. Hence, /boot
will not be available after the system has re-/booted, because the encrypt hook
only unlocks the system's root.
If you used the genfstab script during installation, it will have generated
/etc/fstab entries for the /boot and /boot/efi mount points already, but the system
will fail to nd the generated device mapper for the boot partition. To make it
available, add it to crypttab. For example:
/etc/crypttab
will make the system ask for the passphrase again (i.e. you have to enter it twice
at boot: once for GRUB and once for systemd init). To avoid the double entry for
unlocking /boot , follow the instructions at Dm-crypt/Device encryption#Keyles
to:
If for some reason the keyle fails to unlock the boot partition, systemd will
fallback to ask for a passphrase to unlock and, in case that is correct, continue
booting.
It may be worth considering to add the GRUB bootloader to the ignore list
of /etc/pacman.conf in order to take particular control of when the bootloader
(which includes its own encryption modules) is updated.
20 of 21 03/14/2016 02:27 PM
dm-crypt/Encrypting an entire system - ArchWiki https://wiki.archlinux.org/index.php/Dm-crypt/En...
21 of 21 03/14/2016 02:27 PM