You are not logged in.
Hello,
I _think_ I already know the answer to this, but going to ask anyway In my neverending quest to get hibernate working, I’ve decided that the most reasonable way would be a regular swap partition. I can’t for the life of me get a swapfile in a btrfs on luks schema to work.
Anyway, I have two partitions now - an EFI boot partition and a luks encrypted partition. The luks partition contains a btrfs file system. This is essentially my root fs and has subvolumes for things like /home, /var/log, etc.
If I boot into installation media and mount the partition from there, is it possible to resize the luks encrypted partition so that I can create a swap partition with the newly freed space?
Thanks!
Offline
Hello.
Mandatory warning: backup your data before performing any operations of this kind.
dm-crypt is not interested in the device size. With or without LUKS, it will blindly encrypt/decrypt a block it is ordered to encrypt/decrypt. As long as the file system itself is shrunk successfully, so can be the enclosing partition. Neither dm-crypt nor LUKS care.
What you must remember is that LUKS header itself takes space and pushes the file system upwards.⁽¹⁾ So the partition must be at least as big as (header + file system) and not merely just of the file system size. After unlocking the encrypted volume, you may check the size of the header⁽²⁾ using:
cryptsetup status /dev/mapper/decrypted-device
The “offset” line is what you want: this is where the file system data starts. Note this is in sectors, not bytes!
Resizing a partition alone does not destroy data. So before continuing into creating a new partition and using it, you may wish to check if everything works as expected and your data is intact (in read-only mode). If it is not, go back to the old partition size.
____
⁽¹⁾ Unless it’s a detached header.
⁽²⁾ Strictly speaking: offset to the encrypted data. For this operation the distinction is of no importance.
Sometimes I seem a bit harsh — don’t get offended too easily!
Offline
Thanks! This is great info. I'll give this a shot ... after mulling over the risks a bit more
Offline
Hello,
I can’t for the life of me get a swapfile in a btrfs on luks schema to work.
I remember that (swapfile not working with btrfs) was one of the first things I noted when starting with btrfs.
So I guess you are on the right track with going for a swap partition. Would be great whether you can let us know how you succeeded (or failed) with this in detail.
Last edited by dulhaver (2023-08-17 18:26:41)
Offline