swap:create_an_encrypted_swap_area
Differences
This shows you the differences between two versions of the page.
swap:create_an_encrypted_swap_area [2016/07/07 11:03] – created peter | swap:create_an_encrypted_swap_area [2019/12/04 21:43] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Swap - Create an encrypted swap area ====== | ||
- | |||
- | To create an encrypted swap area. | ||
- | |||
- | The current recommended method for encrypting a Linux block device is to use the **dm-crypt** module. | ||
- | |||
- | **NOTE**: | ||
- | |||
- | A small complication is that the formatting performed by **mkswap** is lost whenever the key changes. | ||
- | |||
- | |||
- | ===== Install cryptsetup ===== | ||
- | |||
- | First install the **cryptsetup** package if it is not already present. | ||
- | |||
- | <code bash> | ||
- | apt-get install cryptsetup | ||
- | </ | ||
- | |||
- | |||
- | ===== Deactivate the swap area ===== | ||
- | |||
- | If the swap area is currently in use then you must deactivate it before proceeding: | ||
- | |||
- | <code bash> | ||
- | swapoff -a | ||
- | </ | ||
- | |||
- | The **-a** option specifies that the command should act on all swap areas listed in **/ | ||
- | |||
- | <code bash> | ||
- | swapoff /dev/sda2 | ||
- | </ | ||
- | |||
- | To confirm that all swap areas have been deactivated, | ||
- | |||
- | <code bash> | ||
- | cat / | ||
- | </ | ||
- | |||
- | Look for an entry labelled **SwapTotal**, | ||
- | |||
- | < | ||
- | SwapTotal: | ||
- | </ | ||
- | |||
- | |||
- | ===== Remove the swap area from /etc/fstab ===== | ||
- | |||
- | If the swap area is listed in **/ | ||
- | |||
- | <file bash / | ||
- | /dev/sda2 none swap defaults 0 0 | ||
- | </ | ||
- | |||
- | or it may identify the swap area by UUID as opposed to its device name: | ||
- | |||
- | <file bash / | ||
- | UUID=b74898a2-7324-4336-8556-92d82edf8999 none swap defaults 0 0 | ||
- | </ | ||
- | |||
- | In either case you are looking for an entry in which the third field (the **filesystem** type) is listed as swap. | ||
- | |||
- | |||
- | ===== Optionally, wipe the swap area ===== | ||
- | |||
- | If the swap area has previously held un-encrypted data then you may wish to wipe it before proceeding further. | ||
- | |||
- | <code bash> | ||
- | dd if=/ | ||
- | </ | ||
- | |||
- | or you can use a more aggressive method if you prefer. | ||
- | |||
- | |||
- | ===== Add the swap area to / | ||
- | |||
- | Mappings created using the cryptsetup command are non-persistent. | ||
- | |||
- | <file bash / | ||
- | swap /dev/sda2 / | ||
- | </ | ||
- | |||
- | The first field is the name of the block device that will be created in **/ | ||
- | |||
- | The second field is the pathname of an existing block device or file that will be used to store the ciphertext. | ||
- | |||
- | The third field specifies where the encryption key should be obtained from. In this case a new random key is chosen each time the machine restarts. | ||
- | |||
- | The fourth field is a comma-separated list of options. | ||
- | |||
- | The reason for obtaining the key from / | ||
- | |||
- | |||
- | ===== Activate the mapping ===== | ||
- | |||
- | Mappings described in **/ | ||
- | |||
- | <code bash> | ||
- | cryptdisks_start swap | ||
- | </ | ||
- | |||
- | If that command is not available then an alternative method is to restart the cryptdisks service: | ||
- | |||
- | <code bash> | ||
- | / | ||
- | </ | ||
- | |||
- | If you now list the content of / | ||
- | |||
- | <code bash> | ||
- | ls -l /dev/mapper | ||
- | </ | ||
- | |||
- | you should be able to see the newly-created block device (/ | ||
- | |||
- | < | ||
- | total 0 | ||
- | crw-rw---- 1 root root 10, 59 2010-12-22 20:26 control | ||
- | brw-rw---- 1 root disk 254, 0 2011-01-01 11:56 swap | ||
- | </ | ||
- | |||
- | |||
- | ===== Add the encrypted swap area to /etc/fstab ===== | ||
- | |||
- | Arrange for the encrypted swap area to be activated on reboot by listing it in **/ | ||
- | |||
- | <file bash / | ||
- | / | ||
- | </ | ||
- | |||
- | |||
- | ===== Activate the encryped swap area ===== | ||
- | |||
- | Activate the encrypted swap area. This can be done without rebooting the machine using the **swapon** command: | ||
- | |||
- | <code bash> | ||
- | swapon -a | ||
- | </ | ||
- | |||
- | As with **swapoff**, | ||
- | |||
- | To confirm that all swap area has been activated, inspect the content of / | ||
- | |||
- | <code bash> | ||
- | cat / | ||
- | </ | ||
- | |||
- | The entry labelled **SwapTotal**, | ||
- | |||
- | < | ||
- | SwapTotal: | ||
- | </ | ||
- | |||
swap/create_an_encrypted_swap_area.1467889397.txt.gz · Last modified: 2020/07/15 09:30 (external edit)