Sometimes
when we are facing issue with high space utilization of the disk in Linux
system, then we can make some space by reducing the lvm partition which have
unused space available if hard disk partitioned in lvm. Reducing the lvm volume
cannot be done online, the volume should be unmounted while reducing. Reducing
the logical volume is the risk of data lose and it is always recommended to
make a backup of data before reducing the volume.
This
article describes How to Reduce lvm partition in CentOS
7.
Here we
are using lv_home logical volume to reduce 5 GB of space out of 15 GB as shown
below:
[root@linuxcnf ~]# df
-hT /home/
Filesystem Type Size
Used Avail Use% Mounted on
/dev/mapper/vg_linuxcnf-lv_home ext4 15G
41M 14G 1% /home
[root@linuxcnf ~]#
|
Step 1. Unmount the File System: Run
the following command to unmount the file system:
[root@linuxcnf ~]# umount
/home/
[root@linuxcnf ~]#
|
Step 2. Check the File System: Run
the following command to check the file system error if any:
[root@linuxcnf ~]# e2fsck
-f /dev/mapper/vg_linuxcnf-lv_home
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/vg_linuxcnf-lv_home:
11/983040 files (0.0% non-contiguous), 104724/3932160 blocks
[root@linuxcnf ~]#
|
Step 3. Reduce the File System: Run
the following command to resize the file system before reducing lvm volume:
[root@linuxcnf ~]# resize2fs
/dev/mapper/vg_linuxcnf-lv_home 10G
resize2fs 1.42.9
(28-Dec-2013)
Resizing the
filesystem on /dev/mapper/vg_linuxcnf-lv_home to 2621440 (4k) blocks.
The
filesystem on /dev/mapper/vg_linuxcnf-lv_home is now 2621440 blocks long.
[root@linuxcnf ~]#
|
Step 4. Reduce the Volume: Run
the following command to reduce the lvm volume:
[root@linuxcnf ~]# lvreduce
-L 10G /dev/mapper/vg_linuxcnf-lv_home
WARNING: Reducing active logical volume to
10.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem
etc.)
Do you really want to
reduce vg_linuxcnf/lv_home? [y/n]: y
Size of logical volume vg_linuxcnf/lv_home
changed from 15.00 GiB (3840 extents) to 10.00 GiB (2560 extents).
Logical volume vg_linuxcnf/lv_home successfully
resized.
[root@linuxcnf ~]#
|
Step 5. Check the File System: Run
the following command to check the file system error if any:
[root@linuxcnf ~]# e2fsck
-f /dev/mapper/vg_linuxcnf-lv_home
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/vg_linuxcnf-lv_home:
11/655360 files (0.0% non-contiguous), 83137/2621440 blocks
[root@linuxcnf ~]#
|
Step 6. Mount the File System &
Validate: Run the following command to check the file system error if
any:
[root@linuxcnf ~]# mount
/home/
[root@linuxcnf ~]# df -h
/home/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_linuxcnf-lv_home 9.8G
37M 9.2G 1% /home
[root@linuxcnf ~]#
[root@linuxcnf ~]# vgs
VG
#PV #LV #SN Attr VSize VFree
vg_linuxcnf
1 4 0 wz--n- 38.99g 5.00g
[root@linuxcnf ~]#
|
Done!!! /home partition is
resized successfully and now 5GB free space available in volume group
vg_linuxcnf.
No comments:
Post a Comment