3

How can I resize an LUKS encrypted system partition?

Is it as simple as resizing (shrinking more specifically) using a tool such as Gparted?

I found some guides, but they all assumed a LVM layer, which I don't have. I want to free some space so I can install another OS on my disk.

Here is the output of lsblk --fs:

sda └─sda1 exfat 1.0 SP DS72 98E8-EFC2 327.8G 65% /media/unrestr1cted/SP DS72 sr0 nvme0n1 ├─nvme0n1p1 │ vfat FAT32 8E04-3240 781.5M 27% /boot/efi ├─nvme0n1p2 │ crypto 2 6177513c-ef48-48d3-ae04-f3c9a2a5dd65 │ └─cryptroot │ ext4 1.0 f89406fd-36e1-4199-a86c-521b4091d56a 176.3G 71% /var/snap/firefox/common/host-hunspell │ / ├─nvme0n1p3 │ vfat FAT32 A400-E762 ├─nvme0n1p4 │ ├─nvme0n1p5 │ ntfs AA1603B616038295 ├─nvme0n1p6 │ ntfs CE544B26544B109F └─nvme0n1p7 ext4 1.0 boot a037f3de-9fa2-4c4c-837f-4798e9d1d96b 87M 81% /boot 
3
  • 1
    Please edit your question to add output of lsblk --fs How to do this depends on a few factors: some file system types cannot be reduced, and how to deal with the encryption layer. Commented Nov 15 at 4:54
  • 2
    @JohnMahowald Done. I couldn't make the output look just like in the terminal, I hope it's readable. Let me know if I should edit something. Commented Nov 15 at 12:22
  • Almost all encrypted installs use LVM. I have one encrypted partition just for some data I consider more important. I believe in Pareto or the 80/20 rule. So do not encrypt install or most of my data. If dual booting do not share /boot, you should share /boot/efi or the ESP partition. May be better to encrypt data and not installs? Make sure ;you have good backups before any changes. Commented Nov 16 at 15:14

1 Answer 1

0

This solution looks at a convenient GUI option, using the KDE Partition Manager.

  1. Unlock the LUKS-encrypted partition.
  2. Resize the ext4 filesystem or another supported filesystem inside the partition. This also has the intended effect that it shrinks the encrypted partition.
  3. Finally, apply changes.

Here is a CLI solution derived from the commands KDE Partition Manager executes.

  1. Unlock the LUKS-encrypted partition: cryptsetup open --type luks2 /dev/[device_name] [device_name]_crypt. This will allow you to see the filesystem inside on /dev/mapper/[device_name]_crypt
  2. Check the filesystem for errors. For an ext4 filesystem, use e2fsck -v /dev/mapper/[device_name]_crypt to check for any errors. e2fsck -vf /dev/mapper/[device_name]_crypt can be used to repair those errors. For btrfs, use btrfs check instead and btrfs check --repair to repair errors. It is advised to backup data before repairing the filesystem.
  3. Execute resize2fs /dev/mapper/[device_name]_crypt [new_size] to shrink the filesystem. This will not shrink the LUKS partition. [new_size] should be 32768 512-bytes (16777216 bytes or 16 megabytes) smaller than [new_size] in the next step to allow for room for the LUKS header. For btrfs, mount /dev/mapper/[device_name]_crypt first and then run btrfs filesystem resize [new_size] [mounted_path].
  4. To shrink the LUKS partition, run cryptsetup --size [new_size] resize /dev/mapper/[device_name]_crypt. Note [new_size] is in 512-byte units (divide bytes by 512 or megabytes by 2 to obtain this)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.