Linux Logical Volume Management Operations

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

Logical volume management commands can be issued from the lvm console, or as standalone commands. For example:

lvm> lvs

produces identical results to

lvs

Inventory of Devices that May Be Used as Physical Volumes

lvmdiskscan

Example:

[root@rhel-test ~]# lvmdiskscan
  /dev/rhel_rhel-test/swap [     820.00 MiB] 
  /dev/sda1                [     500.00 MiB] 
  /dev/rhel_rhel-test/root [       6.67 GiB] 
  /dev/sda2                [       7.51 GiB] LVM physical volume
  /dev/sdb                 [       2.00 GiB] 
  3 disks
  1 partition
  0 LVM physical volume whole disks
  1 LVM physical volume

The output specifies which device is already a LVM Physical Volume

To see only the existing Physical Volumes (devices that have Volume Groups on them)

lvmdiskscan -l

Physical Volume Operations

Information about Physical Volumes

  • pvs - provides information about physical volumes available on the system.
  • pvscan - scans all disks for physical volumes.
  • pvdisplay - provides details about a specific physical volume.

Physical Volume Management Operations

  • Change attributes of physical volume
pvchange
  • Resize physical volume
pvresize
  • Check the consistency of physical volume
pvck
  • Move extents from one physical volume to another
pvmove
  • Remove LVM label(s) from physical volume(s)
pvremove

Volume Group Operations

Information about Volume Groups

vgs
vgdisplay --verbose 

Volume Group Management Operations

Logical Volume Operations

Information about Logical Volumes

  • lvs - provides information about logical volumes available on the system.
  • lvdisplay - displays attributes of a logical volume.
  • lvscan - scans all known volume groups or all supported LVM block devices in the system for defined Logical Volumes.

Logical Volume Management Operations

Creating a Logical Volume

lvm
lvm> lvcreate --size 20G --name santorini VolGroup00

Extending a Logical Volume

http://www.azhowto.com/2009/02/06/how-to-resize-lvm-running-xen-explained-part-1-increase-disk-size

Renaming a Logical Volume

lvm 
lvm> lvrename VolGroup00 LogVol05numbercat lv05


Remove a Logical Volume

Gather statistics on the free space before removing, and also on the size of the logical volume to be removed:

vgs
lvs   

Unmount the volume if necessary (or shutdown the service that is using it, as it is the case with Docker):

umount /dev/VolGroup00/MyLV1

Remove the logical volume with lvremove.

The command has a "dry run mode" (-t):

lvremove /dev/<VG_name>/<LV_name>
lvremove -t /dev/<VG_name>/<LV_name>

Example:

[root@rhel-test lvm]# lvremove -t /dev/rhel_rhel-test/docker-pool 
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
Do you really want to remove active logical volume docker-pool? [y/n]: y
  Logical volume "docker-pool" successfully removed

This command actually removes it:

lvremove [-v] /dev/VolGroup00/MyLV1

Shrinking the Filesystem and the Logical Volume

This is the simple case, it will only work if the logical volume *does not* contain a partition table:

fsadm

or

umount lvm_partition
resize2fs /dev/vg/lv newSize
lvresize -L disksize /dev/vg/lv
resize2fs /dev/vg/lv

Shrinking a Logical Volume used by a xen Virtual Machine

Logical Volume Management and Virtualization