I followed these steps to convert my normal swap on /dev/sda4
(UUID 5da9c956-e544-47e3-bb8e-fe18d9531b2f
) into an encrypted swap partition on 16.04:
Disable old swap partition and overwrite it with zeroes:
sudo swapoff -a sudo dd if=/dev/zero of=/dev/sda4 bs=4M
Install
cryptsetup
:sudo apt install cryptsetup
Edit
/etc/crypttab
to contain this:# <target name> <source device> <key file> <options> cryptswap UUID=5da9c956-e544-47e3-bb8e-fe18d9531b2f /dev/urandom swap
Edit
/etc/fstab
to remove the old swap line and replace it with this one:# cryptswap on /dev/sda4 configured in /etc/crypttab /dev/mapper/cryptswap none swap sw 0 0
Reload cryptdisks configuration:
sudo service cryptdisks reload sudo service cryptdisks-early reload
Enable the new encrypted swap:
sudo swapon -a
However, this last step gave me the following error message:
swapon: stat of /dev/mapper/cryptswap failed: No such file or directory
Indeed, the encrypted device file seems not to have been created:
$ ls -la /dev/mapper/
total 0
drwxr-xr-x 2 root root 60 Aug 10 18:50 .
drwxr-xr-x 20 root root 4780 Aug 10 20:16 ..
crw------- 1 root root 10, 236 Aug 10 18:50 control
What went wrong here and how do I get my encrypted swap partition to work?