This is a LVM command reference for quick look up, if you want more detail info about each command, see Red hat Logical Volume administration



PV commands

Scanning available disk devices for PV

# lvmdiskscan
  /dev/sda                     [       1024.15 GB ]

Creating Physical Volumes

#pvcreate /dev/sdd1

Display attributes of a physical volume

  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               new_vg
  PV Size               17.14 GB / not usable 3.40 MB
  Allocatable           yes
  PE Size (KByte)       4096

Report information about physical volumes

  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda2  vg_desk lvm2 a--  931.02g    0
  /dev/sdb1  vg_desk lvm2 a--  931.51g    0

Scans all supported LVM block devices

  PV /dev/sda2   VG vg_desk   lvm2 [931.02 GiB / 0    free]
  PV /dev/sdb1   VG vg_desk   lvm2 [931.51 GiB / 0    free]
  Total: 2 [1.82 TiB] / in use: 2 [1.82 TiB] / in no VG: 0 [0   ]

Preventing Allocation on a Physical Volume

#pvchange -x n /dev/sdd1

Resizing a Physical Volume

#pvresize /dev/sdd1

Move content from a Physical Volume to another(s)

#pvmove /dev/sdd1

Removing Physical Volume

#pvremove /dev/sdd1


VG commands

Creating Volume Groups

#vgcreate vg1 /dev/sdd1 /dev/sde1

Adding Physical Volumes to a Volume Group

#vgextend vg1 /dev/sdf1

Display a Volume Group

#vgdisplay vg_desk
  --- Volume group ---
  VG Name               vg_xldesk
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable

Display Volume Groups

  VG        #PV #LV #SN Attr   VSize VFree
  vg_desk   2   3   0 wz--n- 1.82t    0

Scanning Disks for Volume Groups to Build the Cache File

This builds the LVM cache in the /etc/lvm/.cache file

  Reading all physical volumes.  This may take a while...
  Found volume group "vg_desk" using metadata type lvm2

Removing Physical Volumes from a Volume Group

#vgreduce my_volume_group /dev/hda1

Changing the Parameters of a Volume Group

#vgchange -l 128 /dev/vg00

Activating and Deactivating Volume Groups

#vgchange -a n my_volume_group
#vgchange -a y my_volume_group

Removing Volume Groups

#vgremove officevg
  Volume group "officevg" successfully removed

Splitting a Volume Group

vgsplit bigvg smallvg /dev/ram15
  Volume group "smallvg" successfully split from "bigvg"

Combining Volume Groups

vgmerge -v databases my_vg

Backing Up Volume Group Metadata

By default, the metadata backup is stored in the /etc/lvm/backup file and the metadata archives are stored in the /etc/lvm/archives file.

  Volume group "vg_desk" successfully backed up.

Recovery Volume Group Metadata


Renaming a Volume Group

vgrename /dev/vg02 /dev/my_volume_group

Export a Volume Group from system

#vgexport officevg

Import a Volume Group to system

#vgimport officevg

Recreating a Volume Group Directory



LV commands

Creating Linear Logical Volumes

lvcreate -L 10G vg1
lvcreate -L 50G -n gfslv vg0 lvcreate -l 60%VG -n mylv testvg
lvcreate -l 100%FREE -n yourlv testvg
lvcreate -l 100 -n testlv testvg /dev/sda1:0-25 /dev/sdb1:50-125
lvcreate -l 100 -n testlv testvg /dev/sda1:0-25:100-

Creating Striped Logical Volumes

lvcreate -L 50G -i2 -I64 -n gfslv vg0 
lvcreate -l 100 -i2 -nstripelv testvg /dev/sda1:0-50 /dev/sdb1:50-100

Creating Mirrored Logical Volumes

lvcreate -L 50G -m1 -n mirrorlv vg0 
lvcreate -L 12MB -m1 --corelog -n ondiskmirvol bigvg
lvcreate -L 500M -m1 -n mirrorlv vg0 /dev/sda1 /dev/sdb1 /dev/sdc1
lvcreate -L 500M -m1 -n mirrorlv vg0 /dev/sda1:0-499 /dev/sdb1:0-499 /dev/sdc1:0

Changing Mirrored Volume Configuration

lvconvert -m1 vg00/lvol1
lvconvert -m0 vg00/lvol1

Resizing Logical Volumes

lvreduce -l -3 vg00/lvol1

Persistent device numbers

You can specify these with the lvcreate and the lvchange commands by using the following arguments:
--persistent y --major major --minor minor

Changing the Parameters of a Logical Volume Group

lvchange -pr vg00/lvol1

Renaming Logical Volumes

lvrename vg02 lvold lvnew

Removing Logical Volumes

lvremove /dev/testvg/testlv
Do you really want to remove active logical volume "testlv"? [y/n]: y
  Logical volume "testlv" successfully removed

Displaying Logical Volumes

lvdisplay -v /dev/vg00/lvol2

Growing Logical Volumes

lvextend -L12G /dev/myvg/homevol
lvextend -L+1G /dev/myvg/homevol
lvextend -l +100%FREE /dev/myvg/testlv

Extending a Striped Volume

lvextend vg/stripe1 -L 406G
lvextend vg/stripe1 -L 542G
lvextend -i1 -l+100%FREE vg/stripe1

Shrinking Logical Volumes

lvreduce -l -3 vg00/lvol1

Snapshot commands

Creating Snapshot Volumes

lvcreate --size 100M --snapshot --name snap /dev/vg00/lvol1


Creates LVM2 dump information

Creating dump directory: /root/lvmdump-mydesk-2016052960712
Gathering LVM & device-mapper version info...
Gathering dmsetup info...
Gathering process info...
Gathering console messages...
Gathering /etc/lvm info...
Gathering /dev listing...
Gathering /sys/block listing...
Creating report tarball in /root/lvmdump-mydesk-2016052960712.tgz...

Low level LVM management

#dmsetup info
Name:              vg_desk-lv_home
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        1
Event number:      0
Major, minor:      253, 2
Number of targets: 2
UUID: LVM-A8amGJ4sCV1hIC1e5vi92Uyyc1iNR54bwOHcaH769Z3xeh9YNJav1EMR8hJEwKJW



Comments powered by CComment