What is LVM? ● LVM – Logical Volume Management ● LVM provides a method of allocating space available on mass storage devices. ● LVM is far more flexible than conventional partitioning schemes: ⚫ Provides the ability to add disk space to a logical volume and its filesystem while that filesystem is mounted and active ⚫ Allows for the collection of multiple physical hard drives and partitions into a single volume group which can then be divided into logical volumes. ⚫ Allows reducing the amount of disk space allocated to a logical volume (the volume must be unmounted, the filesystem itself must allow resizing for this feature to work). LVM Components ● LVM consist of the following components: ⚫ Physical volumes (PV) ⚫ The underlying physical storage unit of an LVM logical volume is a block device such as a partition or whole disk. ⚫ The device must be initialized as a physical volume. ⚫ Volume groups (VG) : a pool of disk space out of which logical volumes can be allocated. ⚫ Logical volumes (LV): a volume group is divided up into logical volumes. Setting Up Logical Volumes ● Have the physical disk. ● Create the required partitions on the physical disk (using fdisk or other tools). ● Create a physical volume for each partition (mark each partition as PV) ● Create a volume group ● Add physical volume to volume group ● Create logical volumes ● Create new file system on logical volume – format logical volume (logical volume is seen as a device). ● Mount the file system. LVM Example. Step 1 ● Hard Drive and Partitions ● Let’s say we have the sdb hard drive with four created partitions. Each partition is 5GB in size: LVM Example. Step 2 ● Initialize partitions as physical volumes: pvcreate command
● View the current physical volumes: pvdisplay command
LVM Example. Step 3 ● Create a volume group named vgpool. Typically, we need only one volume group on the system: vgcreate command
● Add more physical volumes to the vgpool volume group: vgextend command
● View the created and
extended volume group: vgdisplay command LVM Example. Step 4 ● Create a logical volume named lvstuff: lvcreate command ⚫ Logical volumes correspond to partitions: they hold a filesystem. Unlike partitions, logical volumes get names rather than numbers, they can span across multiple disks, and do not have to be physically contiguous.
● View the created logical volume lvstuff: lvdisplay command
LVM Example. Step 5 ● Format the logical volume lvstuff LVM Example. Step 6 ● Mount the logical volume lvstuff and use the df command to see if the logical volume was mounted