LVM: Commands

LVM Overview
Tech Articles
This article describes LVM commands and is intended for experienced LINUX users. For background information, see LVM overview
LVM Commands

Putting Disks Under LVM Control
To see which disks can be used with LVM:
lvmdiskscan

To see which LVM physical volumes are there:
pvscan

Note: /etc/lvm/lvm.conf can be used to control which devices can be scanned.

To provide details on each physical volume (output is multi-line per device):
pvdisplay

To provide details on each physical volume (output is multi-line per device to aid scripting):
pvs

To prepare a disk to be a physical volume:
pvcreate

For example, to prepare these 3 disks: /dev/sdd /dev/sde /dev/sdf
pvcreate /dev/sdd /dev/sde /dev/sdf

Creating Volume Groups
To create a Volume Group:
vgcreate

For example (volume group name vg1 using disks /dev/sdd1 /dev/sde1):
vgcreate vg1 /dev/sdd1 /dev/sde1

Files are created in /dev that correspond with the volume group. In this example, the files will be under:
/dev/vg1

To get details on your volume groups, use these commands:
vgs
vgdisplay
vgscan

Some notes on these commands:
vgs: one line per group to aid scripting
vgdisplay: multi-line output
vgscan: rebuilds the LVM cache file /etc/lvm/cache/.cache

If you want to add to the volume group, use the vgextend command. For example, to add disks /dev/sdf1 and /dev/sdg1 to volume group vg1:
vgextend vg1 /dev/sdf1 /dev/sdg1

Creating Logical Volumes

Creating Linear Logical Volumes

The lvcreate command is used for creating logical volumes.

lvcreate –L [optional

Examples: create a logical volume of 10 gigabytes in the Volume Group vg1 and then create the same with the name volume1:
lvcreate –L 10G vg1
lvcreate –L 10G volume1 vg1


Creating Striped Logical Volumes

The lvcreate command is also used to create striped logical volumes. The -i argument is used to specify the number of stripes. The command is:

lvcreate -L –i -I -n

lvcreate -L 50G –i3 -I64 -n volume2 vg1

Creating Mirrored Logical Volumes

The lvcreate command is also used to create mirrored logical volumes. The -m argument is used to specify the number of mirrors. The command is:

lvcreate -L –m -n

lvcreate -L 50G –m1 -n volume3 vg1



LVM Commands (continued)

Removing a Disk
To prevent allocation of a physical volume (for example, if disk has errors):
pvchange –x n 

For example, if disk is /dev/sde
pvchange –x n /dev/sde

To remove disks from volume group, use pvdisplay and then pvreduce
pvdisplay

For example, if disk is /dev/sde
pvdisplay /dev/sde1

Make sure that the physical volume is not used by any logical volumes. If not, use the pvmove command to move the migrate the data.
pvmove /dev/sde1

Use the vgreduce command to remove the physical volume from the volume group (for example sde1).

vgreduce
vgreduce vg1 /dev/sde1

Use the pvremove command to remove the physical volume from LVM:
pvremove

For example, if disk is /dev/sde
pvremove /dev/sde

Suggestions for Future Learning
RedHat has a nice document on LVM:



LVM Overview
Tech Articles