Setting up an encrypted swap disk
You can use a volatile protected key generated by the pkey device driver to encrypt a swap disk.
Before you begin
About this task
Because swap disks are discarded on reboot, volatile encryption keys are an option. You can generate volatile protected keys or secure keys from random data.
- KVM guest migration
- z/VM live guest relocation in a single system image (SSI)
- Suspend and resume
Procedure
Results
The swap option causes that an mkswap is performed after the dm-crypt volume has been set up. The entry in /etc/fstab then causes the device-mapper device named swap_disk to be used as swap device.
Linux™ now runs with a swap device that is encrypted with a protected key.
What to do next
For reasons of security, you might consider to use a secure key instead of a protected key for encrypting swap disks. In such a case, you can generate a new random secure key from a cryptographic coprocessor using another set of sysfs attributes. You do not need to store and manage the secure key within the secure key repository, because you want to generate a new secure key at boot time, that is, each time you use a new swap disk.
A new random secure key is generated by a cryptographic coprocessor when reading from the ccadata_aes_256_xts attribute in the /sys/devices/virtual/misc/pkey/ccdata/ directory.
Add an entry to /etc/crypttab, similar to the one for protected keys, but now using a sysfs attribute from the .../ccadata/ directory.
# <name> <device> <password> <options>
swap_disk /dev/mapper/disk99 /sys/devices/virtual/misc/pkey/ccadata/ccadata_aes_256_xts swap,\
cipher=paes-xts-plain64,\
size=1024
The required entry to /etc/fstab is the same as for protected keys.