Back to Dm-crypt with LUKS/draft.
- 1 Secure erasure of the hard disk drive
- 2 Partitioning
Secure erasure of the hard disk drive
Before encrypting a drive, you should perform a secure erase of the disk by overwriting the entire drive with random data. To prevent cryptographic attacks or unwanted File Recovery, this data should be completely indistinguishable from all data later written by dm-crypt.
In deciding which method to use for secure erasure of a hard disk drive, remember that this needs only to be performed once for as long as the drive is used as an encrypted drive.
For detailed instructions on how to erase and prepare a drive consult Securely wipe disk.
The following methods are specific for dm-crypt/LUKS and are mentioned complementarily, because they can be performed after a partition setup too.
Use LUKS container as pseudorandom number generator
The cryptsetup FAQ mentions a very simple procedure to use an existing dm-crypt-volume to wipe all free space accessible on the underlying block device with random data by acting as a simple pseudorandom number generator. It is also claimed to protect against disclosure of usage patterns.
# dd if=/dev/zero of=/dev/mapper/luks-container
Wipe free space with encrypted file after Installation
The same effect can be achieved if a file is created on each encrypted partition that fills the partition completely after the system is installed, booted and filesystems mounted. That is because encrypted data is indistinguishable from random.
# dd if=/dev/zero of=/file/in/luks-container # rm /file/in/luks-container
The above process has to be repeated for every container created.
Wipe LUKS keyslots
#cryptsetup luksKillSlot <device> <key slot number>
This will only wipe a single keyslot.
Wipe LUKS header
The partitions formatted with dm-crypt/LUKS contain a header with the cipher and crypt-options used, which is referred to
dm-mod when opening the blockdevice. After the header the actual random data partition starts. Hence, when de-commissioning a drive (e.g. sale of PC, switch of drives, etc.) it may be just enough to wipe the header of the partition, rather than overwriting the whole drive - which can be a lengthy process.
Wiping the LUKS header will delete the PBKDF2-encrypted (AES) master key, salts and so on.
A header with one single default 256 bit size keyslot is 1024KB in size. It is advised to also overwrite the first 4KB written by dm-crypt, so 1028KB have to be wiped. That is
For zero offset use:
#head -c 1052672 /dev/zero > /dev/sda1; sync
For 512 bit key length (e.g. for aes-xts-plain with 512 bit key) the header is 2MB.
If in doubt, just be generous and overwrite the first 10MB or so.
#dd if=/dev/zero of=/dev/sda1 bs=512 count=20480
When wiping the header with random data everything left on the device is encrypted data. An exception to this may occur for an SSD, because of cache blocks SSDs employ. In theory it may happen that the header was cached in these some time before and that copy may consequently be still available after wiping the original header. For strong security concerns, a secure ATA erase of the SSD should be done (procedure please see the cryptsetup FAQ 5.19).
After the drive has been securely overwritten, it is time to create partitions and begin setting up an encrypted system.
There are multiple ways to create disk partitions:
LUKS can be used with systems that require LVM and/or RAID and is compatible with all regular partitioning standards in Linux.
Creating Disk Partitions
There are two required partitions for a basic encrypted system setup:
- root file system
/Will be encrypted and store all system and user files (
- initial boot partition
/bootWill not be encrypted; the bootloader needs to access the
/bootdirectory where it will load the initramfs/encryption modules needed to load the rest of the system which is encrypted (see Mkinitcpio for details). For this reason,
/bootneeds to reside on its own, unencrypted partition.
This partition layout is encrypted in this example and can be refined according to needs, e.g. by separating partitions or adding an encrypted swap-partition.
Single Disk Systems
If there are additional partitions desired, these can be individually created by defining separate primary or extended/logical partitions. It is possible to encrypt separate partitions (e.g. /home, /var) while leaving others (e.g. /usr) unencrypted as required. However, a standard install would also require separate passphrases or keys to open each encrypted partition during boot.
Multiple Disk Systems
In systems with multiple hard disk drives, the same options exist as a single disk system. After the creation of the
/boot partition, the remaining free space on the physical disks can be divided up into their respective partitions at this level. For encrypted partitions that span multiple disks, LUKS must be used with RAID or LVM.