How to reduce a LVM partition in linux
Here is the short tutorial, which explains how to reduce a LVM partition in linux. Before we proceed, please check the configuration of my server.
Harddisk Partition /dev/sda1 & /dev/sdb1 both partitions are 2GB each.
Volume group jg_sda
Logical volume media – size 2 GiB
Address of the logical volume is /dev/jg_sda/media
Reducing a logical volume
Task : Reduce the logical volume /dev/jg_sda/media from 2GB to 1 GB size.
Reducing a logical volume involves following 3 steps namely –
01. Unmount the logical volume (if it is mounted)
02. Reduce the file system residing on the logical volume. And finally,
03. Reduce the logical volume.
Step 1 – Unmount the logical volume
If the logical volume is not mounted anywhere, you can skip this step.
Since our logical volume has been mounted at /mnt/volume, we have to unmount it.
[root@24x7serversolutions ~]# umount /mnt/volume
Step 2 – Reduce the file system residing on the logical volume
First run e2fsck to check the file system as follows –
[root@24x7serversolutions ~]# e2fsck -f /dev/jg_sda/media
Next resize the filesystem on the logical volume to 1 GB size using the resize2fs command.
[root@24x7serversolutions ~]# resize2fs /dev/jg_sda/media 1G Resizing the filesystem on /dev/jg_sda/media to 262144 (4k) blocks. The filesystem on /dev/jg_sda/media is now 262144 blocks long.
Step 3 – Reduce the logical volume
To reduce the size of a logical volume, we use the lvreduce LVM command.
Now lets reduce the logical volume /dev/jg_sda/media from 2 GB to 1 GB.
[root@24x7serversolutions ~]# lvreduce --size 1G /dev/jg_sda/media WARNING: Reducing active logical volume to 1.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce media? [y/n]: y Reducing logical volume media to 1.00 GiB Logical volume media successfully resized.
Re-size the file-system back, In this step if there is any error that means we have messed-up our file-system.
[root@24x7serversolutions ~]# resize2fs /dev/jg_sda/media
Mount the file-system back to same point.
[root@24x7serversolutions ~]#mount /dev/jg_sda/media /mnt/volume