How to reduce LVM partition size in RHEL and CentOS


It's Most important blog because we install the OS by default install in LVM partition (some time)  in Aws and other Cloud service providers.

And Root partition is space is low like (50 GB) and we required 100 and More than space.
Than, We use LVM reduce partitions size.
/home space is 500 GB and Move then we reduce the size from /home partitions. but we are doing the practice  in /root partitions.

[root@bhandari ~]# df -h
Filesystem                             Size  Used Avail Use% Mounted on
/dev/xvda2                              10G  1.2G  8.9G  12% /
devtmpfs                               477M     0  477M   0% /dev
tmpfs                                  496M     0  496M   0% /dev/shm
tmpfs                                  496M   13M  483M   3% /run
tmpfs                                  496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/lvm_bhandari-bhandari_lvm   15G   41M   14G   1% /lvm_dir
tmpfs                                  100M     0  100M   0% /run/user/1000
[root@bhandari ~]# vgs
VG           #PV #LV #SN Attr   VSize  VFree
lvm_bhandari   3   1   0 wz--n- 29.99g 14.99g

Step:1 Umount the file system
[root@bhandari ~]# umount /lvm_dir/
[root@bhandari ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda2       10G  1.2G  8.9G  12% /
devtmpfs        477M     0  477M   0% /dev
tmpfs           496M     0  496M   0% /dev/shm
tmpfs           496M   13M  483M   3% /run
tmpfs           496M     0  496M   0% /sys/fs/cgroup
tmpfs           100M     0  100M   0% /run/user/1000

Step:2 check the file system for Errors using e2fsck command.
[root@bhandari ~]# e2fsck -f /dev/mapper/lvm_bhandari-bhandari_lvm
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/mapper/lvm_bhandari-bhandari_lvm: 13/983040 files (0.0% non-contiguous), 104726/3932160 blocks

Note: In the above command e2fsck , we use the option ‘-f’ to forcefully check the file system, even if the file system is clean.

Step:3 Reduce  the size of /root to desire size.
[root@bhandari~]# resize2fs /dev/mapper/lvm_bhandari-bhandari_lvm 10G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/lvm_bhandari-bhandari_lvm to 2621440 (4k) blocks.
The filesystem on /dev/mapper/lvm_bhandari-bhandari_lvm is now 2621440 blocks long.

NoteAbove Reduce command in /root partitions 10G (which is keep the partitions size you want to use in /root and some other /home give the size 10G,15G)
/root partitions size is 15G and we reduce 5G. we keep size of /root 10G so put the command in  with 10G
[root@bhandari ~]# resize2fs /dev/mapper/lvm_bhandari-bhandari_lvm 10G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/lvm_bhandari-bhandari_lvm to 2621440 (4k) blocks.
The filesystem on /dev/mapper/lvm_bhandari-bhandari_lvm is now 2621440 blocks long.

Step:4 Now reduce the size using lvreduce command.
[root@bhandari ~]# lvreduce -L 10G /dev/mapper/lvm_bhandari-bhandari_lvm
WARNING: Reducing active logical volume to 10.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvm_bhandari/bhandari_lvm? [y/n]: y
Size of logical volume lvm_bhandari/bhandari_lvm changed from 15.00 GiB (3840 extents) to 10.00 GiB (2560 extents).
Logical volume lvm_bhandari/bhandari_lvm successfully resized.

Step:5 (Optional) For the safer side, now check the reduced file system for errors
[root@bhandari ~]# e2fsck -f /dev/mapper/lvm_bhandari-bhandari_lvm
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/mapper/lvm_bhandari-bhandari_lvm: 13/655360 files (0.0% non-contiguous), 83139/2621440 blocks

Step:6 Mount the file system and verify its size.
[root@bhandari ~]# mount /lvm_dir/
[root@bhandari ~]# df -h
Filesystem                             Size  Used Avail Use% Mounted on
/dev/xvda2                              10G  1.2G  8.9G  12% /
devtmpfs                               477M     0  477M   0% /dev
tmpfs                                  496M     0  496M   0% /dev/shm
tmpfs                                  496M   13M  483M   3% /run
tmpfs                                  496M     0  496M   0% /sys/fs/cgroup
tmpfs                                  100M     0  100M   0% /run/user/1000
/dev/mapper/lvm_bhandari-bhandari_lvm  9.8G   37M  9.2G   1% /lvm_dir

Now Restart the Server and Check Again

How to reduce LVM partition size in RHEL and CentOS How to reduce LVM partition size in RHEL and CentOS Reviewed by Unknown on October 31, 2017 Rating: 5

No comments:

Scribe

http://feeds.feedburner.com/LinuxAndAws
Powered by Blogger.
X

Get Updates On

Linux Tutorial

AWS Tutorial

Devops Tutorial

We are going to send you our resources for free. To collect your copy at first, join our mailing list. So don't miss any updates, stay connected!