|
|
Log in / Subscribe / Register

Block-device encryption without reinstallation

Block-device encryption without reinstallation

Posted Sep 30, 2025 12:08 UTC (Tue) by geert (subscriber, #98403)
Parent article: Managing encrypted filesystems with dirlock

I think it would be possible to convert from an unencrypted to an encrypted block-device without reinstallation, by teaching dm-crypt to handle partially-encrypted block devices. The conversion procedure would be:
1. Unmount file system,
2. Shrink/modify file system to cater for space for the LUKS header and dm-crypt,
3. Add a LUKS header, and a counter that is initialized at zero (nothing encrypted yet),
4. Setup dm-crypt and remount file system,
5. Dm-crypt background task encrypts blocks, and updates the stored counter accordingly, until everything is encrypted.


to post comments

Block-device encryption without reinstallation

Posted Sep 30, 2025 21:13 UTC (Tue) by berto (subscriber, #58604) [Link]

I believe that BitLocker does something like that, it would certainly be a nice feature to have.

But I'm not sure how that would work in practice: the LUKS header alone takes several MBs, so apart from shrinking the filesystem you would have to either move all the data or put the superblock and the first few MBs at the end of the partition, and then use the device mapper to make those appear at the beginning.

Block-device encryption without reinstallation

Posted Sep 30, 2025 21:30 UTC (Tue) by muase (subscriber, #178466) [Link] (3 responses)

Something like that would definitely be possible; BitLocker (Windows) and FileVault (macOS) have been offering similar functionality for years now; speaking from a technical pov, it's a solved problem.

Going further down that road: As LUKS2 supports detached headers, you could even do interesting shenanigans like simply storing luks-<partuuid>.bin in the boot or EFI partitions itself, and simply add another JSON key dmcrypt-progress to the header file. As AES-XTS is zero-size overhead, now you wouldn't even need to touch and shrink the existing partitions/filesystems anymore and could transparently encrypt block by block.

Block-device encryption without reinstallation

Posted Sep 30, 2025 22:34 UTC (Tue) by berto (subscriber, #58604) [Link] (2 responses)

Indeed, with detached headers it should be possible.

I'm not familiar with the internals of the device mapper but I can imagine that this would need changes in dm-crypt: you would need to have a device that is only encrypted up to a certain offset, and that offset would change in real time while the device is being used.

Block-device encryption without reinstallation

Posted Oct 1, 2025 15:20 UTC (Wed) by muase (subscriber, #178466) [Link] (1 responses)

I'm not familiar with the internals of the device mapper but I can imagine that this would need changes in dm-crypt: you would need to have a device that is only encrypted up to a certain offset, and that offset would change in real time while the device is being used.
As far as I know, there is cryptsetup-reencrypt, which already has an online-mode for reencryption but it seems that this also supports initial encryption. I'm not sure if you can use it to online-encrypt the currently booted volume; but if I understand the manpage correctly, it should be possible to boot into a minimal environment, start the encryption, convert everything to device-mapper volumes, and then reboot and continue the encryption online.

Block-device encryption without reinstallation

Posted Oct 1, 2025 20:43 UTC (Wed) by berto (subscriber, #58604) [Link]

You're right, and they don't actually had to change the device mapper, they do everything in userspace remapping the device on the fly.

Block-device encryption without reinstallation - luksipc

Posted Oct 4, 2025 12:46 UTC (Sat) by tajyrink (subscriber, #2750) [Link]

I have used luksipc multiple times and it has worked fine. https://github.com/johndoe31415/luksipc/


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds