
Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 2, 2025
Keeping our data safe is a big deal these days. Whether it’s personal stuff or important work files, we don’t want anyone snooping where they shouldn’t. That’s where disk encryption comes in, and on Linux, LUKS is a popular choice.
LUKS, or Linux Unified Key Setup, offers us a way to encrypt our partitions and keep our data safe. But here’s the thing: LUKS comes in two versions—LUKS1 and LUKS2. Each has its quirks, so picking the right one is important for getting the best security and ensuring everything works smoothly with our system.
In this tutorial, we’ll take a closer look at LUKS1 and LUKS2, see how they differ, and figure out which one suits us best.
LUKS is a disk encryption specification that provides a standardized method for encrypting partitions on Linux systems. We can think of it as a security measure for our hard drive or SSD. It prevents unauthorized access to our valuable data.
Furthermore, LUKS encrypts the entire partition, encompassing the data itself, the file system structure, and any unused space. This is achieved by creating a specialized header at the beginning of the partition.
This header contains essential metadata, such as the encryption algorithm used (e.g., AES, DES) and the size of the encryption key. Moreover, it includes a set of keyslots that can store different keys, such as passwords or key files, allowing for flexible access control.
When we need to access our encrypted partition, we use the cryptsetup tool. We specify the target partition and provide the correct key, which can be a password or a key file. LUKS then employs this key to decrypt the master encryption key, which ultimately unlocks the entire partition.
Once unlocked, we can access our data. After we’re finished, we can use cryptsetup again to “close” the partition, effectively re-encrypting it and safeguarding our data.
For instance, to initialize a partition with LUKS2, we can use the cryptsetup command:
$ sudo cryptsetup luksFormat --type luks2 /dev/sdX
In the above command:
Additionally, LUKS separates the encryption layer from the file system itself. This separation facilitates data backup and recovery.
Now that we’ve got a good handle on LUKS, let’s dig into the details of its two versions: LUKS1 and LUKS2. While both aim to encrypt our partitions, they have some key differences that can sway our decision depending on what we’re looking for.
LUKS1 keeps things pretty straightforward with a fixed header layout. All the important metadata gets stored in one block at the beginning of the partition. It’s like a neat little label with essential info like the encryption algorithm (e.g., AES), key size, and where the keyslots are located.
A typical LUKS1 header looks something like this:
Magic: "LUKS\xba\xbe"
Version: 1
Cipher Name: aes
Cipher Mode: xts-plain64
Hash Spec: sha1
Payload Offset: 4096
Key Slots: 8 fixed entries with set offsets.
LUKS2, on the other hand, shakes things up with a more flexible JSON-based header. It splits the metadata into different sections, giving us more wiggle room for future upgrades and fancy features:
cryptsetup luksFormat \
--type luks2 \
--cipher aes-xts-plain64 \
--key-size 512 \
--hash sha256 \
--iter-time 2000 \
--label "Encrypted_Archive" \
/dev/sdX
This design also allows for redundant copies of the metadata, which is great news because if one copy gets messed up, we have backups.
LUKS1 relies on PBKDF2 to transform our passphrases into strong encryption keys. PBKDF2 repeatedly hashes the passphrase, making it tough for attackers to crack. While it’s a solid choice, it’s not as resistant to brute-force attacks as some newer methods.
Furthermore, LUKS2 steps up the game by using Argon21 (or Argon2id) by default. Argon2 is a beast when it comes to security. It uses a lot of memory and parallel processing, which really slows down attackers trying to brute-force their way in.
Remember how LUKS2 has those backup copies of metadata? This is important for data recovery. With LUKS1, if the header gets corrupted, we might be in trouble. However, with LUKS2, even if part of the metadata goes bad, we have a good chance of recovering our data.
We can even peek at the LUKS2 metadata with:
$ cryptsetup luksDump /dev/sdx
LUKS header information
Version: 2
Epoch: 3
Metadata area: 16384 [bytes]
Keyslots area: 16744448 [bytes]
...
Data segments:
0: crypt
offset: 16777216 [bytes]
length: (whole device)
cipher: aes-xts-plain64
sector: 512 [bytes]
Keyslots:
0: luks2
Key: 512 bits
Priority: normal
Cipher: aes-xts-plain64
Cipher key: 512 bits
PBKDF: argon2i
Time cost: 4
Memory: 1048576
Threads: 4
Salt: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AF stripes: 4000
AF hash: sha256
Area offset:32768 [bytes]
Area length:258048 [bytes]
Digest ID: 0
This shows all the keyslots and extra fields, confirming that LUKS2 has our back when it comes to recovery.
While LUKS2 is pretty awesome, we need to keep compatibility in mind. Older bootloaders like GRUB might not play nicely with LUKS2, especially when it comes to unlocking encrypted partitions like /boot. Although newer GRUB versions have some LUKS2 support, they usually prefer the older PBKDF2 algorithm.
If we need to use LUKS2 with an older GRUB, we can add a new keyslot specifically with PBKDF2:
$ cryptsetup luksAddKey --pbkdf pbkdf2 /dev/sdx
Enter any existing passphrase: **************
Enter new passphrase for key slot: **************
Verify passphrase: **************
Key slot 1 unlocked.
Command successful.
Then, we can configure the system to use that keyslot during boot (which is beyond the scope of this tutorial). This ensures a smooth startup while still enjoying the benefits of LUKS2 on other partitions.
Additionally, some older systems or tools might not understand all the fancy LUKS2 features. In such cases, sticking with LUKS1 might be the safer bet.
Now that we’ve explored the technical differences between LUKS1 and LUKS2, let’s consider how these differences translate into practical use cases and decision criteria. Choosing the right LUKS version depends on our specific needs and priorities, so let’s weigh the pros and cons for different scenarios.
While LUKS2 offers numerous advancements, there are still situations where LUKS1 remains a viable and even preferable choice:
LUKS2 is generally preferred when security, flexibility, and modern features are essential:
Therefore, the decision between LUKS1 and LUKS2 depends on our specific needs.
In this article, we explored the key differences between LUKS1 and LUKS2. We explored their architecture, key derivation functions, metadata handling, and compatibility considerations. We also provided practical examples and guidance on choosing the appropriate version for different use cases.
Ultimately, the decision between LUKS1 and LUKS2 depends on our specific needs and priorities. LUKS2 offers enhanced security and features, making it suitable for modern systems, while LUKS1 remains relevant for compatibility with older systems and resource-constrained environments.