A logical volume provides storage virtualization so you are not restricted to physical disks sizes. The hardware storage configuration is hidden and the logical volume can be resized and moved on the fly.
An LVM Logical Volume has three components:
- Physical Volumes (PV)
- Volume Groups (VG)
- Logical Volumes (LV)
First of all, you have to initialize a new PV using the pvcreate
command:
pvcreate /dev/sdc*
You can create a PV from a whole disk rather than partitions.
Physical volumes are combined into VGs; this creates a pool of disk space available for allocation. This space is divided into fixed-size units called physical extents, the smallest unit of space that can be allocated. By default, this size is set to 4MB.
To create a VG from one or more PV, use the vgcreate
command:
vgcreate vgname /dev/sdc*
Finally, to create an LV use the lvcreate
command, specifying the size of the LV.
To create an LV of a specified name and size:
lvcreate -L 20G -n lvname vgname
To specify the size in extents, use the -l
argument; you can also specify the size in percentage rather than units:
lvcreate -l 40%VG -n lvname vgname
To use all of the unallocated space in the VG:
lvcreate -l 100%FREE -n lvname vgname
To check your LVM configuration in short and verbose form, you can use respectively:
pvs
–pvdisplay
vgs
–vgdisplay
lvs
–lvdisplay
Don’t forget to build a file system on your LV or you’ll be not be able to mount it!
This could sound stupid, I know, but I’ve seen a lot of people completely forget about it…