You are not logged in.

#1 2023-08-09 21:03:13

cloverskull
Member
Registered: 2018-09-30
Posts: 172

Is it possible to shrink luks partition with btrfs filesystem?

Hello,

I _think_ I already know the answer to this, but going to ask anyway tongue 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

#2 2023-08-09 22:03:11

mpan
Member
Registered: 2012-08-01
Posts: 1,208
Website

Re: Is it possible to shrink luks partition with btrfs filesystem?

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

#3 2023-08-10 05:02:49

cloverskull
Member
Registered: 2018-09-30
Posts: 172

Re: Is it possible to shrink luks partition with btrfs filesystem?

Thanks! This is great info. I'll give this a shot ... after mulling over the risks a bit more tongue

Offline

#4 2023-08-17 18:25:28

dulhaver
Member
Registered: 2023-08-17
Posts: 11

Re: Is it possible to shrink luks partition with btrfs filesystem?

cloverskull wrote:

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

Board footer

Powered by FluxBB