written by: Tolga BALCI•edited by: Lamar Stonecypher•updated: 5/23/2011
Logical Volumes give the system administrator virtually infinite possibilities to play with the storage sizes. They can be shrunk, extended ,and arranged to fit any need- given there is enough space on the physical disks.
slide 1 of 7
We have discussed the partitions and logical volumes in our previous article (I suggest you read our “An Introduction to Partitions and Logical Volumes" article if you do not feel comfortable with these terms). Now we will build top of that and will see how we can change the logical volume sizes.
If you are setting up logical volumes when installing a Linux distribution from scratch, make sure that the /boot directory is on a separate partition. If you place /boot in a logical volume, you will end up with an unbootable system because the Linux bootloader cannot read /boot from a logical volume.
As far as the logical volumes are concerned, note that a logical volume can contain more than one physical volume, but a physical volume cannot be contained by more than one logical volume.
Given that we have touched the logical volume configuration basics, we can now go on with changing their sizes.
slide 2 of 7
How to Extend Logical Volume Size
When you will increase the logical volume size, you will either set the size of the logical volume or extend it with the size you want. In any case, we will use the command lvextend for systems other than Red Hat.
Before using lvextend with an example, let's see our notation:
The volume group is named logvol01 and is mounted under /dev and in volgrp01 (the mountpoint is /dev/volgrp01/logvol01)
We will increase the logical volume to the space available in /dev/sdb1, assuming we have installed another disk on the system
The present size of the logvol01 is 200 Gigabytes and we want to extend it to 500 Gigabytes by adding the 300 Gigabytes on /dev/sdb1
Of course, /dev/sdb1 must have at least 300 Gigabytes of free space, and
We have already made /dev/sdb1 a member of volgrp01.
When we have completed all above, we can use the lvextend command as follows to:
Set size to 500 GB:lvextend -L500G /dev/volgrp01/logvol01 /dev/sdb1
Increase size by 300 GB:lvextend -L+300G /dev/volgrp01/logvol01 /dev/sdb1
To use all available space in /dev/sdb1: lvextend /dev/volgrp01/logvol01 /dev/sdb1 (note that there is no option set for the lvextend command)
To make the command run in verbose mode, you can use the additional -v option.
For the users running Red Hat systems, it will be better to utilize Red Hat's Disk Druid tool, which is a graphical tool to group and ungroup logical volumes and change their sizes.
slide 3 of 7
How to Increase the File System Size
When you have reconfigured, or have grown, your logical volume, it is also necessary to extend the file system to match the logical volume size. Thanks to most modern distributions, the file system resizing tools can “understand"the size of the logical volume and extend the file system without specifying the exact size.
slide 4 of 7
ext2 & ext3 File Systems
Although you can extend the file system system when the drives/volumes are mounted (called online resizing) this is never recommended since you can end up with a corrupt file system. Some system administrators think that they cannot handle the downtime risk of a couple of minutes and take the risks with online resizing. To avoid any risks, I will go with the classic umount/mount process, which will cost you a couple of minutes of downtime. Now let's see how we can do this, following our example in the previous page:
Unmount the logical volume:umount /dev/volgrp01/logvol01
Extend the filesystem: resize2fs /dev/volgrp01/logvol01
Mount back the logical volume: mount /dev/volgroup/logvol01 /home
slide 5 of 7
reiserfs File System
The process is the same, we will unmount the logical volume, but instead resize2fs, we will use resize_reiserfs /dev/volgrp01/logvol01 and then we will mount it back. The commands are the same as above.
slide 6 of 7
xfs File System
xfs filesystems, due to their properties, have to be mounted to resize. In addition, the mount points should be used instead of the absolute paths. So, in order to increase an xfs file system, we will issue xfs_growfs /home, considering that /dev/volgrp01/logvol01 is mounted to /home.
slide 7 of 7
As you have noticed, the logical volume concept may sound complex at first, but given that you have a solid understanding of the partitions and logical volumes, it is a very flexible tool for your hard disk management purposes. The best part is that you can make all the operations with just one command. And the best part is that you do everything without any downtime.