204.3. Logical Volume Manager

204.3 Logical Volume Manager

Weight: 3

Description: Candidates should be able to create and remove logical volumes, volume groups, and physical volumes. This objective includes snapshots and resizing logical volumes.

Key Knowledge Areas:

  • Tools in the LVM suite

  • Resizing, renaming, creating, and removing logical volumes, volume groups, and physical volumes

  • Creating and maintaining snapshots

  • Activating volume groups

Terms and Utilities:

  • /sbin/pv*

  • /sbin/lv*

  • /sbin/vg*

  • mount

  • /dev/mapper/

  • lvm.conf

LVM

In traditional storage management, Operating system searchs for Disk Drives like /dev/sda, /dev/sdb and then looks for what partitions are available on the disks like /dev/sda1, /dev/sdb1 .Partitions are limited to the disks and they are not so flexible. Logical Volume Manager (LVM) bring us flexibility by creating an abstraction layer between Operating System and Disk Devices.

LVM functions by layering abstractions on top of physical storage devices, The basic layers that LVM use are:

  • physical volumes(pv):A physical volume is typically a hard disk, though it may be a device that looks like a hard disk (ex:software raid device).It can be a partition or entire of a disk.

  • volume groups(vg): The Volume Group is central level and heart of the LVM. It gathers together a collection of Physical Volumes and create a pool of different storage resources.

  • logical volumes(lv):The equivalent of a disk partition in a non-LVM system. logical volume takes disk space from disk space which is available on volume group. On top of logical volumes we create File Systems( xfs, ext4, ...)

LVM is capable of doing operations such as increasing, decreasing the size of a logical volume(which we will be discussing later) because the physical volume is made up of small chunks which are always of fixed size. Each physical disk that combinely makes up a volume group will have a number of small chunks of equal size, where data will reside.

This small chunks of equal size, which makes up the physical volumes are called as Physical Extents. Creating a volume group simply combines all the physical extents of all the physical volumes to form one large logical volume group.

Redhat base Systems use LVM by default, they setup LVM during installation, so here we use ubuntu to create lvm :

Working with physical volumes(pv)

Here we use sdb, sdc to create pv. In order to prepare a partition to be a physical volume in LVM, it is recommended to format it with LVM tag:

Now lets chek weather any LVM has been setup or not and start:

physical volume commands

Description

pvdisplay

display physical volume details

pvscan

scan all disks for physical volume

pvs

report info about physical volumes

pvcreate /dev/sdb1 /dev/sdc1

create physical volume

pvchange

Activate, de-Activate physical volume

pvmove

move data from one pv to another pv

pvremove /dev/sdc1

remove a physical volume

Working with volume group(vg)

Now we create a volume group consist of two pv, /dev/sdb1 and /dev/sdc1:

volume group commands

Description

vgdisplay

Display volume group details

vgscan

scans disk devices in the system looking for PV and VG

vgs

Report info about volume groups

vgcreate myfirstvg /dev/sdb1 /dev/sdc1

Create a volume group

vgextend myfirstvg /dev/sdd1 /dev/sde1

Add a new PV to VG

vgreduce myfirstvg /dev/sde1

Remove PV from VG

vgexport myfirstvg

Export VG to system

vgimport myfirstvg /dev/sdb1 /dev/sdd1

Import VG system

vgchange -a y myfirstvg

Activate VG, use "-a n" to deactivate

vgremove myfirstvg

Remove VG from the system

vgrename myfirstvg myvg00

Rename VG

vgsync /dev/myfirstvg

Sync stale PE in VG

Working with logical volume(lv)

And lets format it and mount it:

We can now easily resize volume group with lvresize:

if we havn't used -rswitch then we had to use resizefs /dev/myfirstvg/myfirstlvcommand inorder to get File System .informed about size changes.

logical volume commands

Description

lvdisplay

Display logical volume details

lvscan

Scan for logical volumes

lvs

show logical volume info

lvcreate --name --size 1G my2ndlv

Create logical volume

lvremove /dev/myfirstvg/myfirstlv

Remove logical volume

lvrename my2ndlv my3rdlv

Rename logical volume

lvextend -L1G /dev/myfirstvg/myfirstlv

Increase size of logical volume

lvreduce -L1G /dev/myfirstvg/myfirstlv

Decrease size of logical volume

lvchange -ay /dev/myfirstvg/myfirstlv

Active logical volume, use "-an" to Deactivate

lvsync /dev/myfirstvg/myfirstlv

Sync stale LE of logical volume

lvlnboot [-b/-d/-r/-s/-R/-v] /dev/myfirstvg/myfirstlv

Set lv as root, boot, swap, dump volume

LVM snapshots

snapshots lets us to freeze the current state of logical volume.Every thing which is added or removed doesn't make any changes in our snapshot and we can easily reverse to previous stat of volume. snapshots can help us to create a short term backup when no files are open. For creating snap shots we should define the size of snap shot, so we should consider amount of future changes:

Lets remove some data and restore snap shot, do not forget to unmount before restoring snap shot:

/etc/lvm/*

Lets take a look at /etc/lvm/ directory:

lvm.conf is loaded during the initialisation phase of lvm. This file can in turn lead to other files being loaded - settings read in later override earlier settings. File timestamps are checked between commands and if any have changed, all the files are reloaded.

Metadata backups and archives are automatically created on every volume group and logical volume configuration change unless disabled in the lvm.conf file. By default, the metadata backup is stored in the /etc/lvm/backup file and the metadata archives are stored in the /etc/lvm/archive file. How long and how many meta data archive are kept? it is determined by parameters we can set in the lvm.conf file.

Logical Volume Backup

A daily system backup should include the contents of the /etc/lvm directory in the backup. Note that a metadata backup does not back up the user and system data contained in the logical volumes.We can manually back up the metadata to the /etc/lvm/backup file with the vgcfgbackup command.And we can restore metadata with the vgcfgrestore command.

/dev/mapper

The Device mapper is a generic interface to the linux kernel that can be used by different storage solutions.

Lets Take a look:

By using LVM or RAID or LUKS more md-X devices are created and used. Nice interface to that is:

Some Device Mapper Devices might be created just for the system to do it things. We can work with Device Mapper Directly with dmsetup command but thats not straightforward and it is beyond the scope of LPIC exam.

so we have seen while using RAID can give us performance and reliability, LVM cause flexibility.

Last updated