Scenario: Decrease Logical Volume /home to 1GB size in CentOS/RHEL 6
System: CentOS/RHEL 6
Steps:
– Check the drive and LV Path:
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolumeGroup-lv_root 9.9G 1.8G 7.6G 20% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolumeGroup-lv_home 2.5G 68M 2.3G 3% /home
/dev/mapper/VolumeGroup-lv_opt 2.5G 68M 2.3G 3% /opt
/dev/mapper/VolumeGroup-lv_var 9.9G 199M 9.2G 3% /var
[root@centos6 ~]# lvdisplay | grep Path
LV Path /dev/VolumeGroup/lv_root
LV Path /dev/VolumeGroup/lv_swap
LV Path /dev/VolumeGroup/lv_var
LV Path /dev/VolumeGroup/lv_opt
LV Path /dev/VolumeGroup/lv_home
[root@centos6 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolumeGroup 1 5 0 wz--n- 39.51g 10.51g
[root@centos6 ~]#
got the logical volume home path is /dev/VolumeGroup/lv_home with 2.5GB size.
– Unmount logical volume home and run fuser to kill process that using home directory
[root@centos6 ~]# umount -l /dev/VolumeGroup/lv_home
[root@centos6 ~]# fuser -v /dev/VolumeGroup/lv_home
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolumeGroup-lv_root 9.9G 1.8G 7.6G 20% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolumeGroup-lv_opt 2.5G 68M 2.3G 3% /opt
/dev/mapper/VolumeGroup-lv_var 9.9G 199M 9.2G 3% /var
[root@centos6 ~]#
– Run e2fsck to check logical volume
[root@centos6 ~]# e2fsck -ff /dev/VolumeGroup/lv_home
e2fsck 1.41.12 (17-May-2010)
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/VolumeGroup/lv_home: 11/163840 files (0.0% non-contiguous), 27636/655360 blocks
[root@centos6 ~]#
– Decrease logical volume home to 1GB size
[root@centos6 ~]# resize2fs /dev/VolumeGroup/lv_home 1G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/VolumeGroup/lv_home to 262144 (4k) blocks.
The filesystem on /dev/VolumeGroup/lv_home is now 262144 blocks long.
[root@centos6 ~]# lvreduce -L 1G /dev/VolumeGroup/lv_home
WARNING: Reducing active logical volume to 1.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Reducing logical volume lv_home to 1.00 GiB
Logical volume lv_home successfully resized
[root@centos6 ~]#
– Finish, mount the logical volume home then check the final result
[root@centos6 ~]# mount -a
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolumeGroup-lv_root 9.9G 1.8G 7.6G 20% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolumeGroup-lv_opt 2.5G 68M 2.3G 3% /opt
/dev/mapper/VolumeGroup-lv_var 9.9G 199M 9.2G 3% /var
/dev/mapper/VolumeGroup-lv_home 1008M 68M 890M 8% /home
[root@centos6 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolumeGroup 1 5 0 wz--n- 39.51g 12.01g
[root@centos6 ~]#