CentOS Logical Volume Manager (LVM)

How to Install and Configure LVM on CentOS

LVM (Logical Volume Manager) in CentOS can be used to:

  • create easy to maintain logical volumes
  • manage disk quotas
  • online resize of logical volumes
  • create software RAIDs
  • combine multiple hard drives into a big storage pool
Hard Disk
Photo by Nick van der Ende on Unsplash

The advantage of using LVM is that space can be added to or removed from logical volumes as needed without the need to spread data over multiple file systems.

As an example, without LVM, the root (/) file system of a CentOS based server would be created with a certain fixed size when the operating system is installed.

At a later stage if a new disk drive is installed, there is no way to allocate any of this new space to the root (/) file system. An option would be to create new file systems on the new disk and mount them at particular mount points. In this scenario you would have plenty of space on the new file system but the root (/) file system would still be nearly full. To create space on the root filesystem, files would have to be moved to the new filesystem. With LVM, the new disk (or part thereof) can be assigned to the logical volume containing the root file system thereby dynamically extending the space available.

Logical Volume Manager (LVM) provides a flexible and high level approach to managing disk space. Instead of each disk drive being split into partitions of fixed sizes, onto which fixed size filesystems are created, LVM allows for grouping together disk space into logical volumes which can be easily resized and moved.

In addition, LVM allows administrators to carefully control disk space assigned to different groups of users by allocating distinct volume groups or logical volumes to those users. When the space initially allocated to the volume is exhausted, the administrator can simply add more space without having to move the user files to a different file system.

Components of LVM are as follows:

VG – Volume Group: high level container that holds one or more physical or logical volumes.
PV – Physical Volume: represents a storage device such as a disk drive or storage media.
PE – Physical Extent: each physical volume is divided into equal size blocks called physical extents.
LV – Logical Volume: eqivalent to a disk partition and can contain a filesystem.
LE – Logical Extent: Each logical volume (LV) is divided into equal size blocks called logical extents.

  • Assume we are creating a new volume group called VolGroup_01.
  • This volume group needs physical disk space in order to function.
  • This can be achieved by allocating some disk partitions (say /dev/sda1/dev/sdb1/dev/sdb2) to the volume group.
  • These become physical volumes in VolGroup_01.
  • We then create a logical volume called, say, LogVol_01 within the volume group made up of the three physical volumes. When space runs out on LogVol_01, just add more disk partitions as physical volumes and assign them to the volume group and logical volume.

Gather information on a Logical Volume setup

CommandDescriprion
mountdisplays filesystem mount information
vgdisplaydisplays volume group information
lvdisplaydisplays logical volume information
pvdisplaydisplays physical volume information (devices that provide actual physical space)
yum install system-config-lvmgraphical Logical Volume Manager tool

Add space to CentOS Volume Group using command line

Assuming that a new disk (no previous partitions exist or any existing partitions have been deleted using fdisk utility) has been added to a CentOS 6 system and is recognised by the OS as /dev/sdb.

The following steps will accomplish this task:

CommandDescription
pvcreate /dev/sdbCreate physical volume
vgextend VolGroup_01xtend the Volume group VolGroup_01 with the physical volume
lvextend -L+30G /dev/VolGroup_01/lv_rootAdd 30GB (change this to match your requirements) of the physical volume to logical volume (lv_root)
resize2fs /dev/VolGroup_01/lv_rootResize the filesystem residing on physical volume to use the new additional logical volume space

Summary:

  1. The above steps have effectively added new space to logical volume lv_root.
  2. This has been done while the server was online and a rebbot was also not required.
  3. The users would see the new additional space though!
Menu