CentOS Logical Volume Management

An alternative to creating fixed partitions and file systems is to use Logical Volume Management (LVM) to create logical disks made of space from one or more physical disks or partitions.lux-standart.ru

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 6 based server would be created with a certain fixed size when the operating system is installed. At a leter 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 Management (LVM) provides a flexible and high level approach to managing disk space. Instead of each disk drive being split into partitions of fixed sizesi, 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:

1. VG – Volume Group: high level container that holds one or more physical or logical volumes.
2. PV – Physical Volume: represents a storage device such as a disk drive or storage media.
3. PE – Physical Extent: each physical volume is divided into equal size blocks called physical extents.
4. LV – Logical Volume: eqivalent to a disk partition and can contain a filesystem.
5. 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.

To gather information on Logical Volume setup

1. mount – displays filesystem mount information
2. /usr/sbin/vgdisplay – displays volume group information
3. /usr/sbin/lvdisplay – displays logical volume information
4. /usr/sbin/pvdisplay – displays physical volume information (devices that provide actual physical space)
5. yum install system-config-lvm – graphical Logical Volume Manager tool

To add space to CentOS Volume Group using command line
Assuming that a new disk (no previous partitions exist or any existing partitons 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:

# pvcreate /dev/sdb – Create physical volume
# vgextend VolGroup_01 /dev/sdb – Extend the Volume group VolGroup_01 with the physical volume
# lvextend -L+30G /dev/VolGroup_01/lv_root – Add 30GB (change this to match your requirements) of the physical volume to logical volume (lv_root)
# resize2fs /dev/VolGroup_01/lv_root – Resize the filesystem residing on physical volume to use the new additional logical volume space

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

Also read: Adding new disk to CentOS

Rating:
55
111 votes
(thanks!)

Leave a Reply