Translation(s): English - Français

(!) ?Discussion


LVM is a Logical Volume Manager for the Linux operating system.

Presentation

Logical volume management provides a higher-level view of the disk storage on a computer system than the traditional view of disks and partitions. This gives the system administrator much more flexibility in allocating storage to applications and users.

Storage volumes created under the control of the logical volume manager can be resized and moved around almost at will.

Definitions

An example:

||-------------------------------OS---------------------------------||
||-Non-LVM-||-------------------------LVM---------------------------||
||  /boot  ||   LV-1 (/)  | LV-2 (swap)|  LV 3 (/home) | LV-4 (/tmp)|| Logical Volumes(LV)
||         ||------------------------------------------|------------||
||         ||                  VG 1                    |    VG 2    || Volume Groups(VG)
||         ||------------------------------------------|------------||
||/dev/sda1|| /dev/sda2 |     /dev/sda3    | /dev/sdb2 | /dev/sdd4  || Physical Volumes(PV)
||---------||-------------------------------------------------------||

Good to know

Labels

Logical volumes should use label to be identified in /etc/fstab, instead of the UUIDs or the kernel namming rules (/dev/sda) in order to avoid conflict with the restore of volumes snapshots.

/boot

Grub and Lilo are not compatible with LVM, so /boot should be outside the storage disk managed by LVM.

LVM2 snapshots and udev on Debian

There are some caveats while creating lvm snapshots on debian with udev, see 343671

Installation

All tools to manage an LVM volume are available in lvm2 package

apt-get install lvm2

Then start the lvm service:

/etc/init.d/lvm start

If needed, you can install system-config-lvm, it's an utility for graphically configuring Logical Volumes.

apt-get install system-config-lvm

List of LVM commands

Physical Volumes (PV)

Create a PV

To declare the /dev/sda2 as physical volume available for LVM:

pvcreate /dev/sda2

PV commands list

Volume Groups (VG)

Create un group of physical volume

vgcreate myVirtualGroup1 /dev/sda2

Extend a volume group

Declare an other physical volume:

pvcreate /dev/sda3

Then add the new PV to the VG that already exist:

vgextend myVirtualGroup1 /dev/sda3

Verify VG configuration

Simply run this command:

vgdisplay 

VG commands list

Logical Volumes (LV)

Create an LV

<!> Don"t forget to check if you have enought space: an LV of 100Go don't fit in a 10Go VG.

Create a logical volume in a volume group:

lvcreate -n myLogicalVolume1 -L 10g myVirtualGroup1

Format logical volume in the filesystem you want (ext4,xfs...)

mkfs -t ext4 /dev/myVirtualGroup1/myLogicalVolume1

You can test if it's working:

mkdir /test
mount /dev/myVirtualGroup1/myLogicalVolume1 /test
df -h

You also can check your logical volumes with:

lvdisplay

LV commands

See also: