Reducing Logical Volume

Reducing Logical Volume

Reducing the size of an logical volume(LVs) is a bit complicated thing, there are few things which you need to keep in mind before reducing the size of LV.

  • Before starting, it is always good to take the backup of data.
  • Logical Volume(LV) size cannot be reduced online, it requires a down time(i.e unmounting the file system).
  • Organized the data.
  • Update the file system about the reduction of size.
  • Reduce the size of logical volume(LV).

If any of the above things are missed then it will be a mess, you may corrupt the file systems and Logical Volume(LV).

Previously article we have seen how to create, removing and extended logical volume groups, refer below links.

Managing Logical Volumes in Linux

Extending Logical Volume

Let’s take the Example, I have already created separate volume group (itcare-vg) and logical volume(itcare-lv2). Here, I’m going to reduce the logical volume. Now the size of logical volume(LV) is 3.7GB in size. We need to reduce it to 2.7GB without data-loss.
That means we need to reduce 1GB out of 3.7GB.

Reducing a Logical Group

There are few steps needed to reduce a logical group.

1.) Umount the Logical Volume.

First check the size of LV using lvs command and umount the LV using umount command.

[root@server1 ~]# lvs
  LV         VG        Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home       centos    -wi-ao---- 2.00g                                                    
  root       centos    -wi-ao---- 7.00g                                                    
  var        centos    -wi-ao---- 1.86g                                                    
  itcare-lv1 itcare-vg -wi-ao---- 2.88g                                                    
  itcare-lv2 itcare-vg -wi-ao---- 3.71g     
[root@server1 ~]# umount /storage/
[root@server1 ~]#

2.) Organize the data in the file system.

Organize the data in LV by using e2fsck command.

#e2fsck -f <Logical Device> Used for check for the file-system error(Where, “f” is used to force checking the file system).

[root@server1 ~]# e2fsck -f /dev/itcare-vg/itcare-lv2 
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/itcare-vg/itcare-lv2: 12/242400 files (0.0% non-contiguous), 597713/972800 blocks
[root@server1 ~]#

3.) Update the file system by using resize2fs command.

#resize2fs <Logical Device> <Total size of LV after reduction>

[root@server1 ~]# resize2fs /dev/itcare-vg/itcare-lv2 2662M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/itcare-vg/itcare-lv2 to 681472 (4k) blocks.
The filesystem on /dev/itcare-vg/itcare-lv2 is now 681472 blocks long.

[root@server1 ~]#

4.) Reduce the Logical Volume size than Current size.

Finally reduce the size of the LV using lvreduce command.

#lvreduce -L <Reduce size of LV> <Logical Device>

[root@server1 ~]# lvreduce -L -1G /dev/itcare-vg/itcare-lv2
  WARNING: Reducing active logical volume to 2.71 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce itcare-lv2? [y/n]: y
  Size of logical volume itcare-vg/itcare-lv2 changed from 3.71 GiB (950 extents) to 2.71 GiB (694 extents).
  Logical volume itcare-lv2 successfully resized.
[root@server1 ~]#

5.) Re-mount the file system.

[root@server1 ~]# lvs
  LV         VG        Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home       centos    -wi-ao---- 2.00g                                                    
  root       centos    -wi-ao---- 7.00g                                                    
  var        centos    -wi-ao---- 1.86g                                                    
  itcare-lv1 itcare-vg -wi-ao---- 2.88g                                                    
  itcare-lv2 itcare-vg -wi-ao---- 2.71g
[root@server1 ~]# mount /dev/itcare-vg/itcare-lv2 /storage/
[root@server1 ~]#

Note: You can use #mount -a command if an entry is passed in /etc/fstab.!!!

Read Also:

Migrating the Logical Volume Data
Creating Striped Volumes

Leave a Reply

2 Comments on "Reducing Logical Volume"

Notify of
avatar
Sort by:   newest | oldest | most voted
saugata goswami
Guest

The lvreduce command syntax is wrong. In case of lvreduce the reduced size is set . Likewise if I want to reduce 10 GB partition by 1 GB then we have to put the command as
#lvreduce -L 9G /(LV name).

wpDiscuz