LVM

From Segfault
Jump to: navigation, search

Introduction

Quoting from the LVM2 Resource Page:

LVM2 refers to the userspace toolset that provide logical volume management facilities on linux. 
It is reasonably backwards-compatible with the original LVM toolset.
To use LVM2 you need 3 things: device-mapper in your kernel, the userspace device-mapper support
library (libdevmapper) and the userspace LVM2 tools.

Usage

Create a volume group and a logical volume:

pvcreate /dev/sdz
vgcreate vgtest /dev/sdz
lvcreate -L 100M -n foobar vgtest

We could have omitted the -L parameter to create the LV using all space left in the VG. Or we can use the --extents parameter to specify percentages:

lvcreate -l 50%FREE -n half vgtest                                                       # Or use 50%VG to allocate half the VG size instead.

Resize logical volumes:

lvresize -L +100M vgtest/half                                                            # Add --resizefs to resize the file system in one go via fsadm

Create a snapshot, e.g. to process backups:

lvcreate -l 20%ORIGIN -s -n foobar_snap vgtest/foobar

Activate all LVs in a VG, which can be necessary if these LVs have not been activated by the boot scripts:

vgscan
vgchange -ay

Links