TL;DR
This guide shows you how to securely encrypt your entire disk using LUKS (Linux Unified Key Setup). It covers partitioning, formatting, unlocking, and basic maintenance. This is a robust method for protecting your data.
Partitioning the Disk
- Identify the Disk: Use
lsblkto find the disk you want to encrypt (e.g., /dev/sda). Be absolutely sure you select the correct disk, as this process will erase all data on it! - Partition with fdisk or parted: We’ll create a single partition for simplicity.
sudo fdisk /dev/sda- Type
gto create a new GPT partition table. - Type
nto add a new partition. Accept the defaults for partition number, first sector, and last sector (using the entire disk). - Type
tto change the partition type. Use code 8300 for Linux filesystem. - Type
wto write the changes to disk.
- Type
Formatting with LUKS
- Encrypt the Partition: This step creates the LUKS container.
sudo cryptsetup luksFormat /dev/sda1You will be prompted for a passphrase. Choose a strong, memorable one!
- Open the LUKS Container: This maps the encrypted partition to a device you can use.
sudo cryptsetup luksOpen /dev/sda1 myencryptedvolumeYou will be prompted for your passphrase again. ‘myencryptedvolume’ is an arbitrary name; choose something descriptive.
- Create a Filesystem: Format the mapped device with ext4 (or another filesystem of your choice).
sudo mkfs.ext4 /dev/mapper/myencryptedvolume
Mounting and Unlocking
- Create a Mount Point: This is where the filesystem will be accessible.
sudo mkdir /mnt/encrypted - Mount the Filesystem: Make the encrypted volume available.
sudo mount /dev/mapper/myencryptedvolume /mnt/encrypted - Unlock at Boot (fstab): To automatically unlock during boot, add an entry to /etc/fstab. This requires careful configuration and understanding of security implications! First get the UUID:
sudo blkid /dev/mapper/myencryptedvolumeThen edit /etc/fstab (using sudo) and add a line similar to this, replacing
with the actual UUID you obtained: UUID=/mnt/encrypted ext4 defaults 0 2 Important: Consider using systemd-cryptsetup for more secure automatic unlocking.
- Unlock Manually: To unlock after boot (if not configured in fstab):
sudo cryptsetup luksOpen /dev/sda1 myencryptedvolumeThen mount as described above.
Maintenance
- Backups: Regularly back up your data, even with encryption.
- Passphrase Security: Keep your passphrase safe and secure. Consider using a password manager.
- Update cryptsetup: Ensure you have the latest version of the
cryptsetuppackage for security fixes.sudo apt update && sudo apt upgrade cryptsetup

