We have already learnt how to increase the size of lvm using lvextend command in linux.But Now here in this tutorial we will learn the reverse process i.e how to Reduce the lvm size in linux and we will do this in few simple steps.So this is basically an example lab showing how to reduce size of lvm in linux.
STEP 1:Check the mounted file system using df -h
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 25G 2.1G 22G 9% / tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/vg00-lv1 1.5G 34M 1.4G 3% /lvmdata [root@localhost ~]#
STEP 2:Unmount the file system using umount command
[root@localhost ~]# umount /dev/mapper/vg00-lv1
STEP 3:Now run e2fsck command to check if any file system errors.
[root@localhost ~]# e2fsck -f /dev/mapper/vg00-lv1 e2fsck 1.39 (29-May-2006) 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/mapper/vg00-lv1: 11/196608 files (9.1% non-contiguous), 14766/390144 blocks [root@localhost ~]#
STEP 4:shrink size of /lvmdata to desire size whatever you want.
As you can see above i am going to reduce the size to 1G from 1.5 GB
[root@localhost ~]# resize2fs /dev/mapper/vg00-lv1 1G resize2fs 1.39 (29-May-2006) Resizing the filesystem on /dev/mapper/vg00-lv1 to 262144 (4k) blocks. The filesystem on /dev/mapper/vg00-lv1 is now 262144 blocks long.
STEP5: Now reduce the size using lvreduce command
root@localhost ~]# lvreduce -L 1G /dev/mapper/vg00-lv1 WARNING: Reducing active logical volume to 1.00 GB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv1? [y/n]: y Reducing logical volume lv1 to 1.00 GB Logical volume lv1 successfully resized
STEP 6: Now for safer side check the file system error again.
[root@localhost ~]# e2fsck -f /dev/mapper/vg00-lv1 e2fsck 1.39 (29-May-2006) 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/mapper/vg00-lv1: 11/131072 files (9.1% non-contiguous), 12805/262144 blocks
STEP 7: Now mount the file system and check the size.
[root@localhost ~]# mount /dev/mapper/vg00-lv1 /lvmdata/
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 25G 2.1G 22G 9% / tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/vg00-lv1 1008M 34M 934M 4% /lvmdata [root@localhost ~]#
Hence now you can see we have successfully reduced the size of LVM.
root@localhost ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv1 vg00 -wi-ao 1.00G
[root@localhost ~]# lvdisplay --- Logical volume --- LV Name /dev/vg00/lv1 VG Name vg00 LV UUID gx22Pn-9YAe-th6G-jGw7-vD2X-Qhov-bi05Ox LV Write Access read/write LV Status available # open 1 LV Size 1.00 GB Current LE 256 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@localhost ~]#