Managing Logical Volume Management (LVM) Storage

Introduction:

Logical Volumes and logical volume management make it easier to manage disk space. If a LVM-hosted file system needs more space, it can be allocated  to its logical volume from the free space in its volume group and the file system can be resized. If a disk starts to fail, a replacement disk can be registered as a physical volume with the volume group and the logical volume’s extents can be migrated to the new disk.

LVM Definitions:

Physical devices are the storage devices used to persist data stored in a logical volume. These are block devices and could be disk partitions, whole disks, RAID arrays, or SAN disks. A device must be initialized as an LVM physical volume in order to be used with LVM. The entire “device” will be used as a physical volume.

Physical Volume (PV): PV are used to register underlying physical devices for use in volume groups. LVM automatically segments PVs into physical extents (PE); these are small chunks of data that act as the smallest storage block on a PV.

Volume Group (VG): VG are storage pools made up of one or more physical volumes. A PV can only be allocated to a single VG. A VG can consist of unused space and any number of logical volumes.

Logical Volumes (LV): LV are created from free physical extents in a volume group and provide the “storage” device used by applications, users, and the operating system. LVs are a collection of logical extents (LE), which map to physical extents, the smallest storage chunk of a P.V. By default, each LE will map to one PE. Setting specific LV options will change this mapping; for example, mirroring causes each LE to map two Pes.

Implementing LV storage

The first step is to add external storage like Hard disk or ISCSI to the virtual machine, then follow the below steps:

Prepare the physical device
[root@asim ~]# fdisk /dev/sdb
Create a physical volume
[root@asim ~]# pvcreate /dev/sdb1 /dev/sdb2
Create a volume group
[root@asim ~]# vgcreate vg-alpha /dev/sdb1 /dev/sdb2
Create a logical volume
[root@asim ~]# lvcreate –a Hercules –L 2G vg-alpha
Add the file system
[root@asim ~]# mkfs –t xfs /dev/vg-alpha/Hercules

To make the file system available access reboots:

Use mkdir to create a mount point directory
[root@asim ~]# mkdir /mnt/Hercules
Add an entry to the /etc/fstab file:
/dev/vg-alpha/hercules   /mnt/hercules   xfs   defaults   1  2   
Run mount –a to mount all the file systems in /etc/fstab, including the entry just added.
[root@asim ~]# mount –a

Reviewing LVM status information

Physical Volume
[root@asim ~]# pvdisplay /dev/sdb2
Volume Group
[root@asim ~]# vgdisplay vg-alpha
Logical Volumes
[root@asim ~]# lvdisplay /dev/vg-alpha/hercules

Removing a logical volume

Prepare the file system
[root@asim ~]# umount /mnt/hercules
Remove the logical volume
[root@asim ~]# lvremove /dev/vg-alpha/hercules
Remove the volume group
[root@asim ~]# vgremove vg-alpha
Remove the physical volume
[root@asim ~]# pvremove /dev/sdb1 /dev/sdb2

Leave a Reply

Your email address will not be published.