Do not attempt to shrink a volume if the partition is mounted! Always unmount first! If it is the root volume you need to reduce in size, use a Live DVD/USB instead. You should also take a backup first too 😉
So here we can see I have one Physical Volume, /dev/md0, attached to my one volume group, RAIDVG.
[andy@home-pc ~]$ sudo pvs PV VG Fmt Attr PSize PFree /dev/md0 RAIDVG lvm2 a-- 1.91t 0
We can also see there is zero space left on the volume group. You can use sudo pvdisplay
to see a more detailed output.
As we can see, all this space is being used up by two Logical Volumes.
[andy@home-pc ~]$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert MediaLV RAIDVG -wi-ao---- 1.32t StorageLV RAIDVG -wi-ao---- 600.00g
I can see the filesystem reports I have 664G available. I am going to play it nice and safe and only attempt to reduce the size of my LV by 400G.
[andy@home-pc ~]$ sudo df -h /dev/RAIDVG/MediaLV Filesystem Size Used Avail Use% Mounted on /dev/mapper/RAIDVG-MediaLV 1.4T 603G 664G 48% /plex
Don’t forget to unmount!
[andy@home-pc ~]$ sudo umount -v /dev/RAIDVG/MediaLV umount: /plex (/dev/mapper/RAIDVG-MediaLV) unmounted
Check for potential issues.
[andy@home-pc ~]$ sudo e2fsck -f /dev/RAIDVG/MediaLV e2fsck 1.43.4 (31-Jan-2017) 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/RAIDVG/MediaLV: 35668/88866816 files (11.1% non-contiguous), 163854225/355446784 blocks
It is very important that you run the --reseizefs
operand at the same time.
[andy@home-pc ~]$ sudo lvreduce -L -400G /dev/RAIDVG/MediaLV --resizefs fsck from util-linux 2.29.2 /dev/mapper/RAIDVG-MediaLV: clean, 35668/88866816 files, 163854225/355446784 blocks resize2fs 1.43.4 (31-Jan-2017) Resizing the filesystem on /dev/mapper/RAIDVG-MediaLV to 250589184 (4k) blocks. The filesystem on /dev/mapper/RAIDVG-MediaLV is now 250589184 (4k) blocks long. Size of logical volume RAIDVG/MediaLV changed from 1.32 TiB (347116 extents) to 955.92 GiB (244716 extents). Logical volume RAIDVG/MediaLV successfully resized.
Note the (minus) -400G
. This means reduce by 400G. If I had used 400G
instead, LVM would have made the LV 400G, reducing it from 1.3T. I would have lost over 200G of actual data. Ouch!
And finally I now have 400G available in my VG.
[andy@home-pc ~]$ sudo pvs PV VG Fmt Attr PSize PFree /dev/md0 RAIDVG lvm2 a-- 1.91t 400.00g
Be careful and remember to take a backup!
Be the first to comment