Unlike increasing the LVM volume size, to shrink the volume we need to umount the filesystem. Shrinking LVM volume can not be done online.
1. In the example for this post we have a volume /dev/data_vg/lv_data01 mounted on the mount point /data01 :
# df -hP | grep data01 /dev/mapper/data_vg-lv_data01 976M 2.6M 907M 1% /data01
# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert root centos -wi-ao---- 17.51g swap centos -wi-ao---- 2.00g lv_data01 data_vg -wi-ao---- 1.00g
2. Before shrinking the volume, umount the mount point and run fsck on it.
# umount /data01 # e2fsck -f /dev/data_vg/lv_data01 e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/data_vg/lv_data01: 11/65536 files (0.0% non-contiguous), 12955/262144 blocks
3. Shrink the file system to the desired size. In our case we will reduce the volume from 1G to 800MB.
# lvreduce -r -L 500M /dev/data_vg/lv_data01 fsck from util-linux 2.23.2 /dev/mapper/data_vg-lv_data01: clean, 11/65536 files, 12955/262144 blocks resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/mapper/data_vg-lv_data01 to 128000 (4k) blocks. The filesystem on /dev/mapper/data_vg-lv_data01 is now 128000 blocks long. Reducing logical volume lv_data01 to 500.00 MiB Logical volume lv_data01 successfully resized
4. Mount the filesystem again and verify the new size.
# mount -t ext4 /dev/data_vg/lv_data01 /data01
# df -hP | grep data01 /dev/mapper/data_vg-lv_data01 460M 1.6M 424M 1% /data01
# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert root centos -wi-ao---- 17.51g swap centos -wi-ao---- 2.00g lv_data01 data_vg -wi-ao---- 500.00m