Friday 22 April 2005

Resizing Logical Volumes

This is a continuation of my earlier post Creating Logical Volumes in Linux . Here I will explain how to resize an existing logical volume. Logical volumes may be resized dynamically while preserving the data on the volume. Here is how:
Reducing a logical volume
  1. Reduce the filesystem residing on the logical volume.
  2. Reduce the logical volume.
For different file systems, it is achieved differently.

For ext2 file system

If you are using LVM 1, then both the above steps could be acomplished by executing a single utility called e2fsadm.
# umount /data
# e2fsadm -L -1G /dev/my_vol_grp/my_logical_vol
# mount /data
The above command first reduces the filesystem in the 'my_logical_vol' by 1 GB and then reduces the my_logical_vol itself by the same amount.

If you are using LVM 2 - more recent linux distributions like Fedora use LVM 2 - then you do not have the 'e2fsadm' utility. So you have to first reduce the filesystem using 'resize2fs' and then reduce the logical volume using 'lvreduce'.
# umount /data
# resize2fs /dev/my_vol_grp/my_logical_vol 1G
# lvreduce -L 1G /dev/my_vol_grp/my_logical_vol
# mount /data
In the above case, I have reduced my file system "to" 1 GB size ...

Note: I didn't use the minus (-) sign while using resize2fs

... And then used the lvreduce command to reduce the logical volume "to" 1 GB. If I want to reduce the logical volume "by" 1 GB, then I give the same command but with "-L -1G" instead of "-L 1G".

Reiserfs file system
If you have a reiserfs filesystem, then the commands are a bit different than ext2(3).
# umount /data
# resize_reiserfs -s -1G /dev/my_vol_grp/my_logical_vol
# lvreduce -L -1G /dev/my_vol_grp/my_logical_vol
# mount -t reiserfs /data
XFS and JFS filesystems
As of now, there is no way to shrink these filesystems residing on logical volumes.

Grow a Logical Volume
The steps for growing a logical volume are the exact opposite of those for shrinking the logical volume.
  1. Enlarge the logical volume first.
  2. Then resize the filesystem to the new size of your logical volume.
Update (July 22nd 2005) : I came across this very interesting article on LVM at RedHat Magazine which I found really informative.

No comments:

Post a Comment