Kahibaro
Discord Login Register

4.4.4 Full disk encryption (LUKS)

Why Full Disk Encryption Matters

Full disk encryption protects all data on a storage device by converting it into unreadable ciphertext. Without the correct decryption key, the data remains inaccessible, even if someone removes the disk and connects it to another computer.

On Linux, the de facto standard for full disk encryption is LUKS, which stands for Linux Unified Key Setup. LUKS works on top of block devices, such as physical disks or partitions, and integrates well with common filesystems and boot setups.

Full disk encryption is especially important when a device can be lost, stolen, or accessed without supervision. It protects user data, system configuration, logs, and temporary files that may contain sensitive information. It does not, however, protect data while the system is powered on and unlocked, which is why disk encryption is only one part of an overall security strategy.

Full disk encryption protects data at rest. Once the disk is unlocked and the system is running, data is accessible to anyone who gains sufficient access to the running system.

Core Concepts of LUKS

LUKS separates the idea of encrypting data from the idea of authenticating users. At the lowest level, there is a master key, often called the volume key, that is used to encrypt and decrypt the actual data blocks. That master key is stored on disk, but it is itself encrypted by one or more passphrases or key files.

LUKS introduces the idea of keyslots. Each keyslot contains a copy of the master key encrypted with a different user key. A user key is typically a passphrase or a key file. When you unlock a LUKS volume, the system attempts to decrypt one of the keyslots using the passphrase or key file you provide. If that succeeds, the master key is revealed and kept in memory so that normal read and write operations can proceed.

One important feature of LUKS is that you can add and remove user keys without re-encrypting the entire device. Only the encrypted master key stored in the keyslots is updated. This makes key rotation practical and efficient.

LUKS uses well studied cryptographic algorithms. At its core it uses symmetric ciphers, such as AES in XTS mode, along with a key derivation function, such as PBKDF2 or Argon2, to transform a human passphrase into a strong cryptographic key.

LUKS stores a single master key for the volume and multiple encrypted copies of that key in keyslots. Changing user passphrases does not re-encrypt your data, it only re-encrypts the master key in the keyslots.

LUKS1 vs LUKS2

Modern systems use LUKS in one of two on-disk formats: LUKS1 or LUKS2. Both provide full disk encryption, but they differ in capabilities and metadata layout.

LUKS1 is the older format. It supports up to 8 keyslots and is widely compatible, including with some older bootloaders and tools. Its metadata format is fixed in size and less flexible, which makes it harder to add advanced features. Many distributions used LUKS1 for years, and some still use it for boot volumes where compatibility is important.

LUKS2 is the newer and more flexible format. Its metadata is stored in a more extensible way, which allows additional features such as advanced integrity protection, more keyslots, and improved redundancy for the header. LUKS2 is now the default in many distributions for new encrypted volumes, especially for non-boot data volumes.

If you have an existing LUKS1 volume, it is often possible to convert it to LUKS2 in place, as long as the tools on your system are recent. However, for boot volumes, you must ensure that your boot loader and initramfs support LUKS2 before converting, otherwise the system will not boot.

Before converting a LUKS1 volume to LUKS2, always make a verified backup. If the conversion fails or is interrupted, data may become inaccessible.

Encryption Algorithms and Modes

LUKS uses symmetric ciphers to encrypt data on the disk. The most commonly used cipher is AES, and for disk encryption it is typically used in XTS mode. Disk encryption modes, such as XTS, are designed to handle data arranged in sectors and to reduce the risk of certain structural attacks compared to simple block modes.

A typical cipher specification for LUKS looks like aes-xts-plain64. In that example, aes is the cipher, xts is the mode, and plain64 describes how initialization vectors or tweaks are generated based on sector numbers.

AES-XTS usually uses keys of 256 or 512 bits in total, which are effectively treated as two 128-bit or two 256-bit keys internally. This is sometimes expressed as AES-256-XTS or AES-512-XTS. When you select a key size, you are configuring the strength of the master key used by the cipher.

The security of disk encryption also depends on the key derivation function that turns a passphrase into a key. Functions such as PBKDF2 and Argon2 apply repeated hashing and sometimes memory-hard operations so that offline brute force attacks are slower and more costly.

For LUKS, a strong cipher and mode such as aes-xts-plain64 and a strong key derivation function such as Argon2 or PBKDF2 with high iteration counts are essential to resisting offline brute force attacks.

LUKS Headers and Backup

The LUKS header is a critical structure stored at the beginning of the encrypted device. It contains:

The information about the LUKS version and format.

The cipher and mode used for encryption.

The keyslots, each containing an encrypted copy of the master key.

Without a valid header, the encrypted data is essentially unrecoverable, even if you remember the passphrase. This makes header protection and backup extremely important.

Tools such as cryptsetup allow you to create a backup of the header. The backup includes the metadata and keyslots, not the actual encrypted data. If the header on the disk is corrupted by hardware errors, buggy tools, or mistakes while re-partitioning, you can restore it from the backup and regain access, assuming the data blocks themselves are intact.

When you store a header backup, treat it with the same care as the device itself. Anyone who gains access to both the backup and your passphrase has all the information needed to decrypt the volume.

If a LUKS header is lost or corrupted and no header backup exists, there is no practical way to recover the encrypted data, even with the correct passphrase.

Keyslots, Passphrases, and Key Files

A single LUKS volume can have multiple keyslots, each with its own user key. This makes it possible for different users to have different passphrases, or for one passphrase and one key file to coexist.

A passphrase is a string that a user types at unlock time. Its security depends on both length and unpredictability. Long, random passphrases offer much better protection than short, memorable ones. A key file is a file that contains random data and is used as a key instead of a passphrase. Key files are useful for automated unlocks, where the system can access the key file from a secure location during boot or service start.

When you add a new passphrase, LUKS derives a key from that passphrase using its key derivation function, then encrypts the existing master key and stores it in a free keyslot. Removing a passphrase simply removes the corresponding keyslot, while the master key and all other keyslots remain unchanged.

You can combine passphrases and key files in different ways, for example by using a passphrase for interactive unlocks and a key file for automated unlocks in a protected environment. However, storing key files on the same unencrypted disk as the encrypted volume undermines security.

Adding or removing a LUKS passphrase changes only the keyslots, not the underlying data. To revoke access for someone who knew a passphrase, you must remove that passphrase from the keyslots.

LUKS in the Boot Process

Using full disk encryption for a root filesystem introduces an extra step in the boot process. The system must unlock the encrypted root device before it can mount it and continue booting.

This is usually handled by the initramfs. During early boot, the initramfs runs a small userspace environment that prompts for a passphrase, or retrieves a key from a secure location or hardware token. Once the LUKS device is unlocked, the root filesystem becomes accessible and the normal boot sequence continues.

If you encrypt only data partitions, such as /home or dedicated data volumes, the root filesystem can remain unencrypted. In that case, the boot process is simpler, and the encrypted partitions may be unlocked later, either automatically or manually after login.

Because the bootloader and kernel must be read before any encrypted volumes are unlocked, they are usually stored unencrypted. Some advanced setups include secure boot, separate boot partitions, or additional integrity checks to protect this part of the boot chain. Those measures complement LUKS by preventing tampering with the early boot components.

Full disk encryption that includes the root filesystem requires correct initramfs and bootloader configuration. If the system cannot find or unlock the root LUKS device at boot, the operating system will fail to start.

LUKS with Logical Volume Management

LUKS and LVM are commonly used together. A typical layout encrypts a physical partition with LUKS, then places an LVM physical volume inside the unlocked device. Logical volumes within that LVM are then used for filesystems such as /, /home, or other mount points.

In such a setup, you unlock the encrypted container once, and all the logical volumes inside become usable. This combines the flexibility of LVM, such as resizing and adding logical volumes, with the confidentiality provided by LUKS.

An alternative layout places LUKS on top of logical volumes, where each logical volume can be independently encrypted. This layout offers per volume passphrases or different key policies per volume, but it requires more unlock operations and is more complex to manage.

The design you choose affects both convenience and security. Encrypting the physical layer and combining that with LVM inside is simpler and is a common default in many distributions.

When LUKS is used under LVM, unlocking a single encrypted container exposes all logical volumes within it. Design your volume layout with that trust boundary in mind.

Performance and Hardware Acceleration

Disk encryption introduces extra CPU work on every read and write, since data must be encrypted before it reaches the disk and decrypted when it is read back. The performance impact depends on your hardware, the cipher and mode, and the throughput of your storage.

Modern CPUs often include hardware acceleration for AES, such as AES-NI instructions on many x86 processors. When available and supported by the kernel, these instructions significantly reduce the overhead of encryption. In many cases the bottleneck becomes the disk itself, not the cipher.

Some systems support offloading encryption to specialized hardware, such as dedicated cryptographic accelerators. However, the integration of such devices with standard LUKS setups varies, and often requires specific drivers and configuration.

The choice of key derivation function and its parameters also affects the speed of unlock operations. Functions with a high number of iterations or memory requirements make brute force attacks more expensive, but they also slow down legitimate unlock operations. You must balance the unlock time that users can tolerate with the increased resistance to offline attacks.

When configuring LUKS, choose parameters that keep sustained I/O within acceptable range, but also use strong key derivation settings. Weak or low iteration settings can make offline brute forcing of passphrases much easier.

Security Considerations and Threat Model

Full disk encryption with LUKS protects data while the system is powered off and the volume is locked. It is designed to defend against attackers who gain physical access to the storage device but do not have access to the running system.

Once the system is booted and the volume is unlocked, the protection provided by full disk encryption no longer applies to data that is being actively accessed. An attacker who compromises the system remotely, or a person who gains access while it is already logged in, can read files and capture sensitive information.

Certain attacks focus on the period around boot or on the memory that contains the master key. For instance, cold boot attacks target RAM that still retains data shortly after power loss. Evil maid attacks involve tampering with the unencrypted boot components, such as the bootloader, in order to capture a passphrase at the next boot. LUKS does not directly defend against these, though combining it with secure boot, tamper evident seals, or hardware security modules can reduce risk.

Key management practices are also crucial. Strong passphrases and careful control of key files matter as much as the encryption algorithms. Recovery strategies, such as keyslots reserved for emergency keys, can provide a safe path if a main passphrase is lost.

LUKS protects against offline access to stored data, not against attackers who control the running system or who can tamper with the unencrypted boot environment. Combine disk encryption with secure boot, strong authentication, and physical security for a more complete defense.

Practical Usage Patterns with LUKS

In everyday Linux administration, LUKS is used in several common patterns. A popular approach during installation is to encrypt a single partition, place LVM inside it, and allocate volumes for root, home, and swap. Many distribution installers can create this layout automatically.

For servers that need unattended boots, administrators sometimes use remote key provisioning or hardware tokens so that systems can start without a local operator typing a passphrase. In such cases, the security of the network or token replaces the security of a passphrase typed at the console.

For removable media, such as external hard drives or USB disks, LUKS can provide portable encryption. These devices can be opened on any system with compatible tools and the correct passphrase. Since removable devices are at high risk of loss or theft, using strong passphrases and keeping header backups becomes especially important.

In all these patterns, LUKS offers a consistent interface that works at the block device layer. Filesystems, partitioning tools, and backup systems operate on top of unlocked devices without needing to be aware of the encryption details.

Views: 7

Comments

Please login to add a comment.

Don't have an account? Register now!