The Sysadmin Notebook  

Sitemap

LVM2

Logical Volume Manager

Contents

LVM2 allows you to create a Volume Group from one or more physical volumes or disks. The volume group can then be divided into logical volumes by assigning space from the physical volumes. Logical volumes equate to partitions and can be used to contain filesystems

The 'lvm' command can be run to begin an interactive lvm session where commands can be issued to manage a logical volume

Resizing a logical volume results in a change to the partition size, but the filesystem must be changed using resize2fs to match the logical volume. When reducing a logical volume, resize the filesystem first. When increasing a logical volume, resize the filesystem afterwards

Gathering Information

Top Bottom

Three commands can be used to display information about Volume Groups, Physical Volumes and Logical Volumes:

Create a New Logical Volume

Top Bottom

Use lvcreate to create a new logical volume 'test' in VG 'system' of 10GB:

 lvcreate -L 10G -n /dev/system/test system

The new logical volume can then be formatted and mounted:

mke2fs -text4 /dev/system/test
mount /dev/system/test /media/test -text4

Reducing the Size of a Logical Volume

Top Bottom
unmount /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test 8G
lvreduce -L 8G /dev/system/test
mount /dev/system/test /media/test

Extending the Size of a Logical Volume

Top Bottom

Increase LV to 12G:

lvm lvextend -L 12G /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test 

Increase LV by 2G:

lvm lvextend -L +2G /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test

Increase a volume by 20 physical extents:

lvm lvextend -l +20 /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test

Creating a Snapshot Logical Volume

Top Bottom

A snapshot logical volume allows you to create an exact copy of a volumes data at the time it was created:

lvcreate -L 5G -s -n homebackup /dev/system/home