To resize a LUKS-encrypted partition and its underlying Btrfs filesystem, you need to follow a systematic approach. The process involves resizing the Btrfs filesystem, shrinking the LUKS container, and then adjusting the partition size. Below is a step-by-step guide:
1. Verify the Current Setup
Before making any changes, ensure you understand the current setup:
- The Btrfs filesystem resides inside a LUKS container.
- The LUKS container resides on a partition.
Run the following commands to gather information:
lsblk -f
cryptsetup status <luks-name>
btrfs filesystem show /mount/point
Replace <luks-name> with the name of your LUKS mapping (e.g., luks-<UUID>) and /mount/point with the mount point of your Btrfs filesystem.
2. Shrink the Btrfs Filesystem
You mentioned that the Btrfs filesystem has already been shrunk to 256G. If this step is complete, skip to the next section. Otherwise, shrink the Btrfs filesystem as follows:
Unmount the Filesystem
Ensure the Btrfs filesystem is unmounted:
sudo umount /mount/point
Resize the Btrfs Filesystem
Use the btrfs filesystem resize command to shrink the filesystem:
sudo btrfs filesystem resize 256G /dev/mapper/<luks-name>
Replace <luks-name> with the name of your LUKS mapping.
3. Resize the LUKS Container
After shrinking the Btrfs filesystem, you can shrink the LUKS container to match the new size.
Close the LUKS Container
First, close the LUKS container:
sudo cryptsetup close <luks-name>
Resize the LUKS Container
Use the cryptsetup resize command to adjust the LUKS container size. However, since the LUKS container resides on a partition, you must first resize the partition.
4. Resize the Partition
The partition containing the LUKS container must be resized to match the new size of the LUKS container.
Identify the Partition
Use lsblk or fdisk -l to identify the partition hosting the LUKS container (e.g., /dev/sdX1).
Resize the Partition
Use a tool like parted or fdisk to resize the partition. For example, with parted:
sudo parted /dev/sdX
(parted) resizepart <partition-number> <new-size>
(parted) quit
Replace <partition-number> with the number of the partition (e.g., 1) and <new-size> with the desired size (e.g., 256G).
5. Reopen the LUKS Container
After resizing the partition, reopen the LUKS container:
sudo cryptsetup open /dev/sdX1 <luks-name>
6. Resize the LUKS Container
Now that the partition is resized, resize the LUKS container to match:
sudo cryptsetup resize <luks-name>
7. Remount the Btrfs Filesystem
Finally, remount the Btrfs filesystem:
sudo mount /dev/mapper/<luks-name> /mount/point
Verify the new size:
df -h
Important Notes
- Backup Your Data: Resizing partitions and encrypted containers carries a risk of data loss. Always back up your data before proceeding.
- Alignment: Ensure proper alignment when resizing partitions to avoid performance issues.
- Minimum Size: The new size of the LUKS container and partition must be large enough to accommodate the Btrfs filesystem and any metadata overhead.
If you encounter any issues during the process, provide the error messages, and I can assist further.