Chapter 9. Encrypting block devices using LUKS (2024)

download

PDF

By using the disk encryption, you can protect the data on a block device by encrypting it. To access the device’s decrypted contents, enter a passphrase or key as authentication. This is important for mobile computers and removable media because it helps to protect the device’s contents even if it has been physically removed from the system. The LUKS format is a default implementation of block device encryption in RedHat EnterpriseLinux.

9.1.LUKS disk encryption

Linux Unified Key Setup-on-disk-format (LUKS) provides a set of tools that simplifies managing the encrypted devices. With LUKS, you can encrypt block devices and enable multiple user keys to decrypt a master key. For bulk encryption of the partition, use this master key.

RedHat EnterpriseLinux uses LUKS to perform block device encryption. By default, the option to encrypt the block device is unchecked during the installation. If you select the option to encrypt your disk, the system prompts you for a passphrase every time you boot the computer. This passphrase unlocks the bulk encryption key that decrypts your partition. If you want to modify the default partition table, you can select the partitions that you want to encrypt. This is set in the partition table settings.

Ciphers

The default cipher used for LUKS is aes-xts-plain64. The default key size for LUKS is 512 bits. The default key size for LUKS with Anaconda XTS mode is 512 bits. The following are the available ciphers:

  • Advanced Encryption Standard (AES)
  • Twofish
  • Serpent

Operations performed by LUKS

  • LUKS encrypts entire block devices and is therefore well-suited for protecting contents of mobile devices such as removable storage media or laptop disk drives.
  • The underlying contents of the encrypted block device are arbitrary, which makes it useful for encrypting swap devices. This can also be useful with certain databases that use specially formatted block devices for data storage.
  • LUKS uses the existing device mapper kernel subsystem.
  • LUKS provides passphrase strengthening, which protects against dictionary attacks.
  • LUKS devices contain multiple key slots, which means you can add backup keys or passphrases.

Important

LUKS is not recommended for the following scenarios:

  • Disk-encryption solutions such as LUKS protect the data only when your system is off. After the system is on and LUKS has decrypted the disk, the files on that disk are available to anyone who have access to them.
  • Scenarios that require multiple users to have distinct access keys to the same device. The LUKS1 format provides eight key slots and LUKS2 provides up to 32 key slots.
  • Applications that require file-level encryption.

9.2.LUKS versions in RHEL

In RedHat EnterpriseLinux, the default format for LUKS encryption is LUKS2. The old LUKS1 format remains fully supported and it is provided as a format compatible with earlier RedHat EnterpriseLinux releases. LUKS2 re-encryption is considered more robust and safe to use as compared to LUKS1 re-encryption.

The LUKS2 format enables future updates of various parts without a need to modify binary structures. Internally it uses JSON text format for metadata, provides redundancy of metadata, detects metadata corruption, and automatically repairs from a metadata copy.

Important

Do not use LUKS2 in systems that support only LUKS1 because LUKS2 and LUKS1 use different commands to encrypt the disk. Using the wrong command for a LUKS version might cause data loss.

Table9.1.Encryption commands depending on the LUKS version
LUKS versionEncryption command

LUKS2

cryptsetup reencrypt

LUKS1

cryptsetup-reencrypt

Online re-encryption

The LUKS2 format supports re-encrypting encrypted devices while the devices are in use. For example, you do not have to unmount the file system on the device to perform the following tasks:

  • Changing the volume key
  • Changing the encryption algorithm

    When encrypting a non-encrypted device, you must still unmount the file system. You can remount the file system after a short initialization of the encryption.

    The LUKS1 format does not support online re-encryption.

Conversion

In certain situations, you can convert LUKS1 to LUKS2. The conversion is not possible specifically in the following scenarios:

  • A LUKS1 device is marked as being used by a Policy-Based Decryption (PBD) Clevis solution. The cryptsetup tool does not convert the device when some luksmeta metadata are detected.
  • A device is active. The device must be in an inactive state before any conversion is possible.

9.3.Options for data protection during LUKS2 re-encryption

LUKS2 provides several options that prioritize performance or data protection during the re-encryption process. It provides the following modes for the resilience option, and you can select any of these modes by using the cryptsetup reencrypt --resilience resilience-mode /dev/sdx command:

checksum

The default mode. It balances data protection and performance.

This mode stores individual checksums of the sectors in the re-encryption area, which the recovery process can detect for the sectors that were re-encrypted by LUKS2. The mode requires that the block device sector write is atomic.

journal
The safest mode but also the slowest. Since this mode journals the re-encryption area in the binary area, the LUKS2 writes the data twice.
none
The none mode prioritizes performance and provides no data protection. It protects the data only against safe process termination, such as the SIGTERM signal or the user pressing Ctrl+C key. Any unexpected system failure or application failure might result in data corruption.

If a LUKS2 re-encryption process terminates unexpectedly by force, LUKS2 can perform the recovery in one of the following ways:

Automatically

By performing any one of the following actions triggers the automatic recovery action during the next LUKS2 device open action:

  • Executing the cryptsetup open command.
  • Attaching the device with the systemd-cryptsetup command.
Manually
By using the cryptsetup repair /dev/sdx command on the LUKS2 device.

Additional resources

  • cryptsetup-reencrypt(8) and cryptsetup-repair(8) man pages

9.4.Encrypting existing data on a block device using LUKS2

You can encrypt the existing data on a not yet encrypted device by using the LUKS2 format. A new LUKS header is stored in the head of the device.

Prerequisites

  • The block device has a file system.
  • You have backed up your data.

    Warning

    You might lose your data during the encryption process due to a hardware, kernel, or human failure. Ensure that you have a reliable backup before you start encrypting the data.

Procedure

  1. Unmount all file systems on the device that you plan to encrypt, for example:

    # umount /dev/mapper/vg00-lv00
  2. Make free space for storing a LUKS header. Use one of the following options that suits your scenario:

    • In the case of encrypting a logical volume, you can extend the logical volume without resizing the file system. For example:

      # lvextend -L+32M /dev/mapper/vg00-lv00
    • Extend the partition by using partition management tools, such as parted.
    • Shrink the file system on the device. You can use the resize2fs utility for the ext2, ext3, or ext4 file systems. Note that you cannot shrink the XFS file system.
  3. Initialize the encryption:

    # cryptsetup reencrypt --encrypt --init-only --reduce-device-size 32M /dev/mapper/vg00-lv00 lv00_encrypted/dev/mapper/lv00_encrypted is now active and ready for online encryption.
  4. Mount the device:

    # mount /dev/mapper/lv00_encrypted /mnt/lv00_encrypted
  5. Add an entry for a persistent mapping to the /etc/crypttab file:

    1. Find the luksUUID:

      # cryptsetup luksUUID /dev/mapper/vg00-lv00a52e2cc9-a5be-47b8-a95d-6bdf4f2d9325
    2. Open /etc/crypttab in a text editor of your choice and add a device in this file:

      $ vi /etc/crypttablv00_encrypted UUID=a52e2cc9-a5be-47b8-a95d-6bdf4f2d9325 none

      Replace a52e2cc9-a5be-47b8-a95d-6bdf4f2d9325 with your device’s luksUUID.

    3. Refresh initramfs with dracut:

      $ dracut -f --regenerate-all
  6. Add an entry for a persistent mounting to the /etc/fstab file:

    1. Find the file system’s UUID of the active LUKS block device:

      $ blkid -p /dev/mapper/lv00_encrypted/dev/mapper/lv00-encrypted: UUID="37bc2492-d8fa-4969-9d9b-bb64d3685aa9" BLOCK_SIZE="4096" TYPE="xfs" USAGE="filesystem"
    2. Open /etc/fstab in a text editor of your choice and add a device in this file, for example:

      $ vi /etc/fstabUUID=37bc2492-d8fa-4969-9d9b-bb64d3685aa9 /home auto rw,user,auto 0

      Replace 37bc2492-d8fa-4969-9d9b-bb64d3685aa9 with your file system’s UUID.

  7. Resume the online encryption:

    # cryptsetup reencrypt --resume-only /dev/mapper/vg00-lv00Enter passphrase for /dev/mapper/vg00-lv00:Auto-detected active dm device 'lv00_encrypted' for data device /dev/mapper/vg00-lv00.Finished, time 00:31.130, 10272 MiB written, speed 330.0 MiB/s

Verification

  1. Verify if the existing data was encrypted:

    # cryptsetup luksDump /dev/mapper/vg00-lv00LUKS header informationVersion: 2Epoch: 4Metadata area: 16384 [bytes]Keyslots area: 16744448 [bytes]UUID: a52e2cc9-a5be-47b8-a95d-6bdf4f2d9325Label: (no label)Subsystem: (no subsystem)Flags: (no flags)Data segments: 0: cryptoffset: 33554432 [bytes]length: (whole device)cipher: aes-xts-plain64[...]
  2. View the status of the encrypted blank block device:

    # cryptsetup status lv00_encrypted/dev/mapper/lv00_encrypted is active and is in use. type: LUKS2 cipher: aes-xts-plain64 keysize: 512 bits key location: keyring device: /dev/mapper/vg00-lv00

Additional resources

  • cryptsetup(8), cryptsetup-reencrypt(8), lvextend(8), resize2fs(8), and parted(8) man pages

9.5.Encrypting existing data on a block device using LUKS2 with a detached header

You can encrypt existing data on a block device without creating free space for storing a LUKS header. The header is stored in a detached location, which also serves as an additional layer of security. The procedure uses the LUKS2 encryption format.

Prerequisites

  • The block device has a file system.
  • You have backed up your data.

    Warning

    You might lose your data during the encryption process due to a hardware, kernel, or human failure. Ensure that you have a reliable backup before you start encrypting the data.

Procedure

  1. Unmount all file systems on the device, for example:

    # umount /dev/nvme0n1p1
  2. Initialize the encryption:

    # cryptsetup reencrypt --encrypt --init-only --header /home/header /dev/nvme0n1p1 nvme_encryptedWARNING!========Header file does not exist, do you want to create it?Are you sure? (Type 'yes' in capital letters): YESEnter passphrase for /home/header:Verify passphrase:/dev/mapper/nvme_encrypted is now active and ready for online encryption.

    Replace /home/header with a path to the file with a detached LUKS header. The detached LUKS header has to be accessible to unlock the encrypted device later.

  3. Mount the device:

    # mount /dev/mapper/nvme_encrypted /mnt/nvme_encrypted
  4. Resume the online encryption:

    # cryptsetup reencrypt --resume-only --header /home/header /dev/nvme0n1p1Enter passphrase for /dev/nvme0n1p1:Auto-detected active dm device 'nvme_encrypted' for data device /dev/nvme0n1p1.Finished, time 00m51s, 10 GiB written, speed 198.2 MiB/s

Verification

  1. Verify if the existing data on a block device using LUKS2 with a detached header is encrypted:

    # cryptsetup luksDump /home/headerLUKS header informationVersion: 2Epoch: 88Metadata area: 16384 [bytes]Keyslots area: 16744448 [bytes]UUID: c4f5d274-f4c0-41e3-ac36-22a917ab0386Label: (no label)Subsystem: (no subsystem)Flags: (no flags)Data segments: 0: cryptoffset: 0 [bytes]length: (whole device)cipher: aes-xts-plain64sector: 512 [bytes][...]
  2. View the status of the encrypted blank block device:

    # cryptsetup status nvme_encrypted/dev/mapper/nvme_encrypted is active and is in use. type: LUKS2 cipher: aes-xts-plain64 keysize: 512 bits key location: keyring device: /dev/nvme0n1p1

Additional resources

  • cryptsetup(8) and cryptsetup-reencrypt(8) man pages

9.6.Encrypting a blank block device using LUKS2

You can encrypt a blank block device, which you can use for an encrypted storage by using the LUKS2 format.

Prerequisites

  • A blank block device. You can use commands such as lsblk to find if there is no real data on that device, for example, a file system.

Procedure

  1. Setup a partition as an encrypted LUKS partition:

    # cryptsetup luksFormat /dev/nvme0n1p1WARNING!========This will overwrite data on /dev/nvme0n1p1 irrevocably.Are you sure? (Type 'yes' in capital letters): YESEnter passphrase for /dev/nvme0n1p1:Verify passphrase:
  2. Open an encrypted LUKS partition:

    # cryptsetup open /dev/nvme0n1p1 nvme0n1p1_encryptedEnter passphrase for /dev/nvme0n1p1:

    This unlocks the partition and maps it to a new device by using the device mapper. To not overwrite the encrypted data, this command alerts the kernel that the device is an encrypted device and addressed through LUKS by using the /dev/mapper/device_mapped_name path.

  3. Create a file system to write encrypted data to the partition, which must be accessed through the device mapped name:

    # mkfs -t ext4 /dev/mapper/nvme0n1p1_encrypted
  4. Mount the device:

    # mount /dev/mapper/nvme0n1p1_encrypted mount-point

Verification

  1. Verify if the blank block device is encrypted:

    # cryptsetup luksDump /dev/nvme0n1p1LUKS header informationVersion: 2Epoch: 3Metadata area: 16384 [bytes]Keyslots area: 16744448 [bytes]UUID: 34ce4870-ffdf-467c-9a9e-345a53ed8a25Label: (no label)Subsystem: (no subsystem)Flags: (no flags)Data segments: 0: cryptoffset: 16777216 [bytes]length: (whole device)cipher: aes-xts-plain64sector: 512 [bytes][...]
  2. View the status of the encrypted blank block device:

    # cryptsetup status nvme0n1p1_encrypted/dev/mapper/nvme0n1p1_encrypted is active and is in use. type: LUKS2 cipher: aes-xts-plain64 keysize: 512 bits key location: keyring device: /dev/nvme0n1p1 sector size: 512 offset: 32768 sectors size: 20938752 sectors mode: read/write

Additional resources

  • cryptsetup(8), cryptsetup-open (8), and cryptsetup-lusFormat(8) man pages

9.7.Configuring the LUKS passphrase in the web console

If you want to add encryption to an existing logical volume on your system, you can only do so through formatting the volume.

Prerequisites

  • You have installed the RHEL8 web console.

    For instructions, see Installing and enabling the web console.

  • The co*ckpit-storaged package is installed on your system.
  • Available existing logical volume without encryption.

Procedure

  1. Log in to the RHEL8 web console.

    For details, see Logging in to the web console.

  2. Click Storage.
  3. In the Storage table, click the menu button, , next to the storage device you want to encrypt.
  4. From the drop-down menu, select Format.
  5. In the Encryption field, select the encryption specification, LUKS1 or LUKS2.
  6. Set and confirm your new passphrase.
  7. Optional: Modify further encryption options.
  8. Finalize formatting settings.
  9. Click Format.

9.8.Changing the LUKS passphrase in the web console

Change a LUKS passphrase on an encrypted disk or partition in the web console.

Prerequisites

  • You have installed the RHEL8 web console.

    For instructions, see Installing and enabling the web console.

  • The co*ckpit-storaged package is installed on your system.

Procedure

  1. Log in to the RHEL8 web console.

    For details, see Logging in to the web console.

  2. Click Storage
  3. In the Storage table, select the disk with encrypted data.
  4. On the disk page, scroll to the Keys section and click the edit button.

    Chapter9.Encrypting block devices using LUKS (1)

  5. In the Change passphrase dialog window:

    1. Enter your current passphrase.
    2. Enter your new passphrase.
    3. Confirm your new passphrase.

      Chapter9.Encrypting block devices using LUKS (2)

  6. Click Save

9.9.Creating a LUKS2 encrypted volume by using the storage RHELsystemrole

You can use the storage role to create and configure a volume encrypted with LUKS by running an Ansible playbook.

Prerequisites

  • You have prepared the control node and the managed nodes
  • You are logged in to the control node as a user who can run playbooks on the managed nodes.
  • The account you use to connect to the managed nodes has sudo permissions on them.

Procedure

  1. Create a playbook file, for example ~/playbook.yml, with the following content:

    ---- name: Create and configure a volume encrypted with LUKS hosts: managed-node-01.example.com roles: - rhel-system-roles.storage vars: storage_volumes: - name: barefs type: disk disks: - sdb fs_type: xfs fs_label: label-name mount_point: /mnt/data encryption: true encryption_password: <password>

    You can also add other encryption parameters, such as encryption_key, encryption_cipher, encryption_key_size, and encryption_luks, to the playbook file.

  2. Validate the playbook syntax:

    $ ansible-playbook --syntax-check ~/playbook.yml

    Note that this command only validates the syntax and does not protect against a wrong but valid configuration.

  3. Run the playbook:

    $ ansible-playbook ~/playbook.yml

Verification

  1. View the encryption status:

    # cryptsetup status sdb/dev/mapper/sdb is active and is in use.type: LUKS2cipher: aes-xts-plain64keysize: 512 bitskey location: keyringdevice: /dev/sdb...
  2. Verify the created LUKS encrypted volume:

    # cryptsetup luksDump /dev/sdbVersion: 2Epoch: 6Metadata area: 16384 [bytes]Keyslots area: 33521664 [bytes]UUID: a4c6be82-7347-4a91-a8ad-9479b72c9426Label: (no label)Subsystem: (no subsystem)Flags: allow-discardsData segments: 0: crypt offset: 33554432 [bytes] length: (whole device) cipher: aes-xts-plain64 sector: 4096 [bytes]...

Additional resources

  • /usr/share/ansible/roles/rhel-system-roles.storage/README.md file
  • /usr/share/doc/rhel-system-roles/storage/ directory
  • Encrypting block devices by using LUKS

Chapter 9. Encrypting block devices using LUKS (2024)

FAQs

How to encrypt using LUKS? ›

9.4. Encrypting existing data on a block device using LUKS2 Copy link
  1. Unmount all file systems on the device that you plan to encrypt, for example: ...
  2. Make free space for storing a LUKS header. ...
  3. Initialize the encryption: ...
  4. Mount the device: ...
  5. Add an entry for a persistent mapping to the /etc/crypttab file:

Can LUKS encryption be broken? ›

Depending on what you used to encrypt it, the answer is from trivial to impossible. If you used good encryption and a good password/code/phrase then it is near impossible. I would say give as many realistic brute force guesses as you can but be prepared to give up.

Does LUKS encryption slow down? ›

There will be some performance impact but less than with other disk encryption options. The question is if you'll notice it. That depends on your workload.

Is LUKS encryption strong? ›

Yes, it is secure. Ubuntu uses AES-256 to encrypt the disk volume and has a cypher feedback to help protect it from frequency attacks and others attacks that target statically encrypted data.

Is LUKS more secure than BitLocker? ›

Bitlocker is generally considered to be more secure than dm-crypt/luks, but it can be more difficult to set up and use.

Is LUKS full disk encryption? ›

LUKS encrypts entire block devices and is therefore suited for protecting the contents of mobile devices such as removable storage media or Notebook disk drives.

What is the strongest block encryption algorithm? ›

Strongest Data Encryption Algorithms
  • TripleDES.
  • Twofish encryption algorithm.
  • Blowfish encryption algorithm.
  • Advanced Encryption Standard (AES)
  • IDEA encryption algorithm.
  • MD5 encryption algorithm.
  • HMAC encryption algorithm.
  • RSA security.
Jan 17, 2020

What is the hardest encryption to break? ›

AES 256-bit encryption is the strongest and most robust encryption standard that is commercially available today. While it is theoretically true that AES 256-bit encryption is harder to crack than AES 128-bit encryption, AES 128-bit encryption has never been cracked.

Can LUKS be decrypted? ›

The decryption of a LUKS1 device is done in offline mode, i.e. it must not opened and mounted. If you want to decrypt the system drive, reboot into a USB live environment. Otherwise, use unmount followed by cryptsetup close dm-name .

Can LUKS be brute forced? ›

The purpose of this program is to try to find the password of a LUKS encrypted volume. It can be used in two ways: try all the possible passwords given a charset.

What are the advantages of LUKS? ›

Protects sensitive data: LUKS encryption prevents unauthorized access to your data even if your computer or hard drive falls into the wrong hands. Easy to use: LUKS provides a straightforward way to encrypt disks and partitions on Linux systems, with utilities like cryptsetup making the process relatively simple.

What does LUKS stand for? ›

Linux Unified Key Setup (LUKS) Disk Encryption is commonly used by Linux to encrypt storage media volumes.

How do I encrypt a USB drive with LUKS? ›

How to encrypt USB drives with LUKS
  1. See available filesystems. df -hl.
  2. Connect your USB.
  3. Find out the new connected device. df -hl # in my case it was /dev/sdb1.
  4. Unmount the USB. umount /dev/sdb1.
  5. Wipe filesystem from the USB. ...
  6. Create a LUKS partition. ...
  7. Open the encrypted drive. ...
  8. Create a filesystem.
Mar 6, 2019

Does LUKS use AES-256? ›

LUKS uses AES256, which isn't prone to be compromised by quantum supremacy. What are you talking about exactly when talking about a "copy of the disk"?

How do I encrypt an encrypted document? ›

To decrypt a file or folder:
  1. From the Start menu, select Programs or All Programs, then Accessories, and then Windows Explorer.
  2. Right-click the file or folder you want to decrypt, and then click Properties.
  3. On the General tab, click Advanced.
  4. Clear the Encrypt contents to secure data checkbox, and then click OK.
Jan 18, 2018

How do I encrypt a backup disk? ›

Method 1. Encrypt Backup Disk with Windows Built-in Tool
  1. Press "Win" + "S" to open the Start menu search bar. ...
  2. Locate the backup drive to protect your data, and tap on it to get the different options. ...
  3. To enable the same, you must enter a secure password and reconfirm it.

Top Articles
Why do interest rates matter?
You Can Buy Every Major Video Game Console for $1 Million on eBay
Oldgamesshelf
Lighthouse Diner Taylorsville Menu
South Park Season 26 Kisscartoon
Bucks County Job Requisitions
Erskine Plus Portal
41 annonces BMW Z3 occasion - ParuVendu.fr
Snarky Tea Net Worth 2022
Umn Biology
Large storage units
How Quickly Do I Lose My Bike Fitness?
Azeroth Pilot Reloaded - Addons - World of Warcraft
R Tiktoksweets
2016 Hyundai Sonata Price, Value, Depreciation & Reviews | Kelley Blue Book
8 Ways to Make a Friend Feel Special on Valentine's Day
Restaurants Near Paramount Theater Cedar Rapids
Price Of Gas At Sam's
Aucklanders brace for gales, hail, cold temperatures, possible blackouts; snow falls in Chch
Mzinchaleft
Violent Night Showtimes Near Amc Fashion Valley 18
Ups Access Point Lockers
Invert Clipping Mask Illustrator
Mahpeople Com Login
Hermitcraft Texture Pack
Lowes Undermount Kitchen Sinks
Https Paperlesspay Talx Com Boydgaming
Soulstone Survivors Igg
Aol News Weather Entertainment Local Lifestyle
Sec Baseball Tournament Score
Hellraiser 3 Parents Guide
8002905511
Tom Thumb Direct2Hr
Jazz Total Detox Reviews 2022
Meowiarty Puzzle
Willys Pickup For Sale Craigslist
Club Keno Drawings
Taktube Irani
Mta Bus Forums
Page 5662 – Christianity Today
Has any non-Muslim here who read the Quran and unironically ENJOYED it?
Mixer grinder buying guide: Everything you need to know before choosing between a traditional and bullet mixer grinder
Craigslist Ludington Michigan
Sabrina Scharf Net Worth
Great Clips Virginia Center Commons
Giovanna Ewbank Nua
2017 Ford F550 Rear Axle Nut Torque Spec
Motorcycles for Sale on Craigslist: The Ultimate Guide - First Republic Craigslist
116 Cubic Inches To Cc
French Linen krijtverf van Annie Sloan
Frank 26 Forum
Predator revo radial owners
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 5605

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.