This note explain how to reduce a mounted filesystem on an LVM partition. It requires a reboot but most of the operations can be done online and the system can be used during the operations.
- Remount filesystem read-only
sudo mount -f -o remount,ro /home
- Snapshot the volume hosting the filesystem
sudo lvcreate -s data/home -L 30G -n home_resize
sudo lvdisplay data/home_resize
--- Logical volume ---
LV Path /dev/data/home_resize
LV Name home_resize
VG Name data
LV UUID F1yAeM-rkxx-9PfM-7Wrf-pzQ2-qR4I-wdMML6
LV Write Access read/write
LV Creation host, time tv, 2024-08-16 13:44:45 +0200
LV snapshot status active destination for home
LV Status available
# open 0
LV Size 60,00 GiB
Current LE 15360
COW-table size 30,00 GiB
COW-table LE 7680
Allocated to snapshot 0,01%
Snapshot chunk size 4,00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:6
- Reduce the filesystem on the snapshot
sudo e2fsck -f /dev/mapper/data-home_resize
# reduce to the minimal possible size
sudo resize2fs -p -M /dev/mapper/data-home_resize
# or specify target size
sudo resize2fs -p /dev/mapper/data-home_resize 35G
sudo lvdisplay data/home_resize iotop
--- Logical volume ---
LV Path /dev/data/home_resize
LV Name home_resize
VG Name data
LV UUID F1yAeM-rkxx-9PfM-7Wrf-pzQ2-qR4I-wdMML6
LV Write Access read/write
LV Creation host, time tv, 2024-08-16 13:44:45 +0200
LV snapshot status active destination for home
LV Status available
# open 0
LV Size 60,00 GiB
Current LE 15360
COW-table size 30,00 GiB
COW-table LE 7680
Allocated to snapshot 44,64%
Snapshot chunk size 4,00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:6
- Merge the snapshot with the reduced filesystem
sudo lvconvert --merge data/home_resize
Delaying merge since origin is open.
Merging of snapshot data/home_resize will occur on next activation of data/home.
# Here LVM cli warn this operation can't be done with an online volume
# but it can be deferred at next volume activation.
# We can reboot to trigger a re-activation.
- after restart, monitor snapshot merge process
sudo dmsetup status data-home
0 125829120 snapshot-merge 16/62914560 16
sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home data Owi-aos--- 60,00g 31,91 ← merge in progress
root data -wi-ao---- 50,00g
swap data -wi-ao---- 8,00g
- Reduce the volume to a size sligtly higher than the filesystem (NOT LESS)
# my filesystem size is 32G, I reduce the volume to 35Go
sudo lvreduce -L 35G data/home
# make the filesystem grow to use all available space on the volume by omitting the size argument
sudo resize2fs -p /dev/mapper/data-home