There are plenty of exceptions where hardware and software abstractions are used to create modular and flexible designs in a modern OS. Examples can be seen from Microsoft’s .Net Framework to Virtualization.
Logical Volume Management or LVM is no exception. It allows the separation of physical disk storage devices to a software layer allowing for partitions to span across multiple disks to only appear as one drive to the user.
LVM allows a volume to be resized with less dependency no physical hard disks. In LVM, physical hard disks are referred to as physical volumes of PV. Each hard disk may contain more than one volume just like a hard disk can be partitioned many times.
A Logical Volume (LV) is a software managed volume. This allows the LV to extend or contract in size as and when needed. As time goes on more disks can be added and the LV can expand to take advantage of the disk without referring to each new additional drive as a separate drive e.g in Windows world E:\ currently exists with 100GB with a new drive added, it must be mounted on another drive letter e.g F:\ with 200GB. Using LVM E:\ will remain as a drive but the second drive will be added to E:\ making it appear as though drive E:\ has 300 GB, 100 GB from the original drive and 200 GB from the new drive.
Similarly the drives can be removed from the LVM if the drive is to be removed or used for another purpose. Reducing the size is more dangerous than expanding one and also all the existing data needs to fit onto the remaining drive space.
LVM should be used from the start as it requires the disk to be formatted / partitioned. LVM can consist of one disk and more can be added later.
I have encountered LVMs when Fedora first came out but never really understood / utilized them. It did not help that Ubuntu never had any user friendly way to configure them and Gparted, my preferred disk partition manager did not support LVM.
Fedora / Redhat had always supported LVM very well and now Ubuntu is starting to catch up. The GUI still has some way to go but it’s improving all the time.
LVM has also moved to version 2 with the Linux 2.6 kernel and is the version this article will document.
The remainder of the article will document setting up and configuring LVM on a Ubuntu 10.04 system. LVM is used in other Linux distributions and the commands may be common across all platforms but some may be Ubuntu specific.
sudo apt-get install lvm2 system-config-lvm
sudo apt-get install gparted
System > Administration > Gparted
Device > Create partition table...
Right click on the disk allocation > New
sudo pvcreate /dev/sdb1
sudo vgcreate lvm1 /dev/sdb1
sudo lvcreate -L931.5G -nhome lvm1
Although Gparted now shows the partition as being formated to lvm2, it is actually not formatted. Just like creating a partition it does not format the drive for use, creating a volume so far has only created the space for the LV.
mount -t ext4 -j /dev/lvm1/home
/dev/[volume group]/[volume]for example
/dev/lvm1/homeThe full command to mount the drive would be
sudo mount /media/home /dev/lvm1/home
A new drive or partition would be needed to extend the volume group size. How the spare space is allocated to each volume can be managed separately.
sudo vgextend lvm1 /dev/sdd1
sudo lvextend -L+931.51G /dev/lvm1/home
Ensure the data currently on the LVM can fit onto any disks that remain attached to a LVM group. It is advised that a backup is taken before continuing.
sudo umount /dev/lvm1/home
sudo e2fsck -f /dev/lvm1/home
lvreduce /dev/lvm1/home -L931.5G
sudo resize2fs /dev/lvm1/home
sudo pvmove /dev/sdd1
If you need to format and reinstall your OS or move your LVM storage to a new machine it needs to be prepared for that prior to moving it.
sudo umount /dev/lvm1/home
vgchange -an lvm1
sudo vgexport lvm1
sudo vgimport lvm1
sudo vgchange -ay lvm1
LVM is a very clean way to allow for volumes to be expanded without impacting current software or setups. It helps to alleviate problems when disk drives run out of space and is a bonus to allow drives to be kept rather than replaced. It is advised that the process is done at the beginning of an install to avoid migrating the data from a non-LVM disk to a LVM space. It took several hours to copy just under 1TB from one system to the other.