From LQWiki
LVM is an abbreviation for Logical Volume Manager which has been available under Linux for some time; the 2.4 kernel has the original LVM whilst 2.6 has LVM2 although both essentially do the same job. LVM allows one or more physical devices to be treated as a storage pool from which logical drives may be created whose size can altered dynamically. Assuming your file system supports dynamic resizing the upshot of this is you can grow/shrink logical drives (mount points) as your wish. In addition to combining drives in to logical devices you can also control the spread of data amongst devices through the use of striping, however this is often better left to a RAID implementation. LVM works on top of Software-RAID just fine by the way. :)
Contents |
Concept
- physical volume
- A physical volume (PV) can be created using any block device you choose, typically the block device would be a physical disk, RAID device, partition or even a file. PVs are sliced into logical allocation units knows as physical extents (PEs), the default PE size is 4MB. A single PE is the smallest storage area (Logical volume or LV) you can create, so if you have a 128MB PE size then you could create a 128MB storage area, or any size that is a multiple of 128MB.
- volume group
- In LVM a volume group (VG) is, a set of physical volumes. All physical volumes in a volume group should have the same extent size. It is from the volume group that you actually allocate extents to created your logical volumes (see below). If you have 2 VGs each holding two 250GB physical volumes (say 250GB hard disks) then you could create, at most, two logical volumes each 500GB in size. Alternatively if you had a single VG holding all four of your 250GB PVs you could create yourself a single 1TB logical volume. Note that you don't have to just create a single LV for each VG, in these examples you could create say eight 128GB LVs, or 16 64GB LVs.
- logical volume
- A logical volume is a set of extents allocated from a volume group and is a concept analogous of a disk partition. A logical volume can be resized as necessary without the need of reformatting and explicit copying of all its contents. Note that e.g. for ext3 you will need to unmount the file system in order to be resized, this cannot be done for the / file system without booting from a live CD for example. A filesystem can be created on a logical volume in the usual way, and can be mounted afterwards just as any other filesystem. Logical volumes are to seen as devices with names like /dev/VolGroup00/LogVolume00, or /dev/StudentVG/year1/
Commands
Quite a large set of commands can be used to manipulate LVM
| pysical volume | volume group | logical volume |
|---|---|---|
Using webmin it is possible to use and configure LVM from within a browser. Fedora has a utility system-config-lvm.
How to...
...add a logical volume
The first step for putting LVM on a disk is to pick an empty partition, and change its type to Linux LVM (8e).
For fdisk:
# fdisk /dev/sde Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 8e
For cfdisk:
# cfdisk /dev/sde
to select the hard drive. cfdisk displays lists of partitions and commands, and I selected sde5, Type. I typed in 8e. The type was changed, but cfdisk treats it as an unknown type. I told it to write the partition table, and exited.
To verify, I ran fdisk, which recognized the type as Linux LVM.
To create the physical volume I executed
# pvcreate /dev/sde5
Then to create a volume group called myGroup containing the physical volume on /dev/sde5 use:
# vgcreate vg-maxtor /dev/sde5
And finally to display the newly created volume group:
# vgdisplay
Now create a logical volume called myVol using extents from myGroup
# lvcreate -L 10G -nmyVol myGroup
Next create a file system in the usual way and mount the 10G LV
# mkfs -t ext3 /dev/myGroup/myVol # mount -o users /dev/myGroup/myVol /mnt
The myVol logical volume can now be accessed at /mnt
Like other mounts, logical volumes can be mounted using /etc/fstab
...extend a logical volume
In this example we want to increase the /tmp partition's size by 5GB.
- find out the logical volume's name
# lvdisplay --- Logical volume --- LV Name /dev/vg0/tmp VG Name vg0 LV UUID nqtEqA-GVKK-RUG4-HVcT-NfP4-N83O-faJ6u2 LV Write Access read/write LV Status available # open 1 LV Size 15.00 GB Current LE 3840 Segments 2 Allocation inherit Read ahead sectors 0 Block device 253:0 --- Logical volume --- LV Name /dev/vg0/swap VG Name vg0 LV UUID dbiYzB-56AM-O61X-XJLY-ZgzA-M4oS-LlPeoc LV Write Access read/write LV Status available # open 2 LV Size 2.00 GB Current LE 512 Segments 1 Allocation inherit Read ahead sectors 0 Block device 253:1
- extend the volume
We decide we want to extend /dev/vg0/tmp by 5GB:
# lvextend --size +5G /dev/vg0/tmp Extending logical volume root to 15.00 GB Logical volume root successfully resized
- find out the file system that is contained in the partition that is contained in the logical volume that is contained in the volume group
# mount /dev/mapper/vg0-tmp on /tmp type ext3 (rw)
In this case the file system on disk is ext3.
- extend the file system on disk
resize2fs /dev/vg0/tmp
External links
- LVM-HOWTO (www.tldp.org)

This page is available under a