LUKS doesn’t actually store the size of the device — it simply discovers it when the volume is opened. It therefore only comes into play if the volume is not closed and reopened during the process (e.g. doing an online grow). In this case the size of the open volume needs to be rediscovered.
To shrink your volume, use the following process:
- Unmount the filesystem with
umount
- Resize the filesystem with
resize2fs
- Close the LUKS volume with
cryptsetup luksClose
- Resize the LV with
lvreduce
orlvresize
- Open the LUKS volume with
cryptsetup luksOpen
- Mount the filesystem with
mount
You could also omit the luksClose
and luksOpen
steps, and use cryptsetup resize
after resizing the LV. Also remember that LUKS uses some extra space to store metadata, so the LV needs to be slightly bigger than the filesystem. I usually resize the filesystem significantly smaller, and then grow it again after resizing the LV.
If you were growing the filesystem and wanted to do it online, you would use the following process:
- Resize the LV with
lvextend
orlvresize
- Update the size of the open LUKS volume with
cryptsetup resize
- Grow the filesystem with
resize2fs