LVM

LVM is an abbreviation for Logical Volume Manager, a device mapper which has been available under Linux since 1997, when IBM released the source code to its Journaled File System (JFS) and Logical Volume Manager (LVM) from the AIX operating system under the name Enterprise Volume Management System (EVMS), to allow the open source community to determine the evolution of both. The v2.4 Linux kernel has the original LVM iteration adapted from the IBM code but with a command line syntax that imitates Hewlett Packard's LVM knock-off in that era's HP-UX. In 2003, a ground-up refactor of the original project was released under the GPL as LVM2 by Sistina Software (which was quickly acquired by Red Hat) and merged early the following year into the v2.6 Linux kernel. LVM allows one or more physical devices to be treated as a storage pool from which logical drives may be created whose size can altered dynamically. Assuming your filesystem supports dynamic resizing, the upshot of this is you can grow/shrink logical drives (mount points) as you wish and distribute them over several partitions located on multiple physical drives. In addition to combining drives into logical devices, you can also control the spread of data amongst devices through the use of striping, however this is often better left to a RAID implementation. LVM functions on top of Software-RAID solutions without issue, typically.

Concept

 * Physical volume : A physical volume (PV) can be created using any block device you choose. Typically, the block device would be a physical disk, RAID volume, partition or even a file. PVs are sliced into logical allocation units knows as physical extents (PEs); the default PE size is 4 MiB. A single PE is the smallest storage area (Logical volume, or LV) you can create, so if you have a 128 MiB PE size, then you could create a 128 MiB storage area, or any size that is a multiple of 128 MiB.
 * Volume group : In LVM, a volume group (VG) is a set of physical volumes. All physical volumes in a volume group should have the same extent size. It is from the volume group that you actually allocate extents to create your logical volumes (see below). If you have 2 VGs each holding two 250 GiB physical volumes (for instance, two 250 GiB solid state SATA drives) then you could create, at most, two logical volumes each 500 GiB in size (less the filesystem overhead). Alternatively, if you had a single VG holding all four of your 250 GiB PVs, you could create a single 1 TiB logical volume. Note that you don't have to just create a single LV for each VG; in these examples, you could create, say, eight 128 GiB LVs, or 16 64 GiB LVs.
 * Logical volume : A logical volume (LV) is a set of extents allocated from a volume group, a concept which in practice is analogous to a typical disk partition. A logical volume can be resized as necessary, without the need for reformatting and explicit backup and copying of all its contents back to the new filesystem. Note that this cannot be done for the root filesystem mounted at /  without booting from a live image on a USB flash drive, for example. A filesystem can be created on a logical volume in the usual way, and can be mounted afterwards just as any other filesystem. Logical volumes are seen as devices with names like /dev/VolGroup00/LogVolume00 or /dev/StudentVG/year1.

Commands
Quite a large set of commands are used to manipulate LVM configurations.

Using webmin it is possible to use and configure LVM from within a browser. Fedora has a utility system-config-lvm.

…create a logical volume
The first step for putting LVM on a disk is to pick an empty partition and change its type to Linux LVM (hex code 8e ).

Using gdisk:  Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 8e
 * 1) gdisk /dev/sde

Using cgdisk: 
 * 1) cgdisk /dev/sde

To select the operation, cgdisk displays a text user interface (TUI) with lists of partitions and commands, from which the sde5 partition is selected, followed by the Type command, and finally entering 8e at the input prompt shown. Cgdisk reports the partition type hex code as unrecognized, but the modification is successful nonetheless after writing the partition table to the disk and exiting. To verify this, run gdisk again and confirm that it recognizes the partition type as Linux LVM.

To create the physical volume, use pvcreate: 
 * 1) pvcreate /dev/sde5

Then to create a volume group named myGroup using the physical volume on /dev/sde5, use vgcreate: 
 * 1) vgcreate myGroup /dev/sde5

Finally to review the status of the newly created volume group, use vgdisplay: 
 * 1) vgdisplay myGroup

If everything reported is what was desired, the next step is to create a logical volume called myVol using extents from <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">myGroup using lvcreate: <pre style="background-color: #d7d8d9; border: 2px solid indigo; margin-left: 2em; max-width: 25vmax; padding: 0.5em 1em;">
 * 1) lvcreate --size 10G --name myVol myGroup

Next, format the logical volume for a filesystem with a label of <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">myNewLvmFs (this example uses the Ext4 filesystem created by the mke2fs command) and then assign the new 10 GiB filesystem a mount point at <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">/mnt/myVol with mount: <pre style="background-color: #d7d8d9; border: 2px solid indigo; margin-left: 2em; max-width: 50vmax; padding: 0.5em 1em;">
 * 1) mke2fs -t ext4 -L myNewLvmFs /dev/myGroup/myVol
 * 2) mkdir -p /mnt/myVol
 * 3) mount -t ext4 -o defaults,noatime,errors=remount-ro /dev/myGroup/myVol /mnt/myVol

The <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">myVol logical volume can now be accessed at <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">/mnt/myVol. Like any other filesystem mounts, logical volumes can be mounted automatically during the boot process by adding them to /etc/fstab.

…extend a logical volume
In this example, we want to increase the <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">/tmp logical volume's size by 5 GiB. The process follows these general steps: <div style="background-color: #d7d8d9; border: 2px solid indigo; color: #000; font-family: monospace; line-height: 1.3; margin: 1em 0 1em 2em; max-width: 47.5vmax; overflow-x: auto; padding: 0.6em 1.1em; white-space: pre-wrap; word-wrap: break-word;">&num; lvdisplay
 * 1) Find out the logical volume's name using lvdisplay:

--- Logical volume --- LV Name               /dev/vg0/tmp VG Name               vg0 LV UUID               nqtEqA-GVKK-RUG4-HVcT-NfP4-N83O-faJ6u2 LV Write Access       read/write LV Status             available LV Size               15.00 GB Current LE             3840 Segments              2 Allocation            inherit Read ahead sectors    0 Block device          253:0
 * 1) open                 1

--- Logical volume --- LV Name               /dev/vg0/swap VG Name               vg0 LV UUID               dbiYzB-56AM-O61X-XJLY-ZgzA-M4oS-LlPeoc LV Write Access       read/write LV Status             available LV Size               2.00 GB Current LE             512 Segments              1 Allocation            inherit Read ahead sectors    0 Block device          253:1 <div style="background-color: #d7d8d9; border: 2px solid indigo; color: #000; font-family: monospace; line-height: 1.3; margin: 1em 0 1em 2em; max-width: 47.5vmax; overflow-x: auto; padding: 0.6em 1.1em; white-space: pre-wrap; word-wrap: break-word;">&num; lvextend --size +5G /dev/vg0/tmp
 * 1) open                 2
 * 1) Extend the volume <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">/dev/vg0/tmp by 5 GiB using lvextend:

Extending logical volume root to 15.00 GB Logical volume root successfully resized <div style="background-color: #d7d8d9; border: 2px solid indigo; color: #000; font-family: monospace; line-height: 1.3; margin: 1em 0 1em 2em; max-width: 47.5vmax; overflow-x: auto; padding: 0.6em 1.1em; white-space: pre-wrap; word-wrap: break-word;">&num; lsblk -f
 * 1) Discover which file system is used on the logical volume using lsblk:

NAME                    FSTYPE      LABEL UUID                                   MOUNTPOINT sdc … ├─sdc7                  LVM2_member 7thP  hTUUoY-i7R9-zAsh-CqCp-5lqp-h1qw-uU0nQV ├─vg_vg0-lv_tmp (dm-0) ext4       Temp  87bab36e-c72a-48d1-a12d-4dcfc1736545   /tmp …        In this case, the filesystem in use is <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">ext4. <div style="background-color: #d7d8d9; border: 2px solid indigo; color: #000; font-family: monospace; line-height: 1.3; margin: 1em 0 1em 2em; max-width: 47.5vmax; overflow-x: auto; padding: 0.6em 1.1em; white-space: pre-wrap; word-wrap: break-word;">&num; resize2fs -p /dev/vg0/tmp
 * 1) Extend the filesystem on the logical volume using that filesystem's utilities (for this example using <span style="background-color: #e7e8e9; border: 1px solid #c7c8c9; font-family: monospace; padding: 0 4px;">ext4 that would be resize2fs):

resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg0/tmp is mounted on /tmp; on-line resizing required. Performing an on-line resize of /dev/vg0/tmp to 5242880 (4k) blocks. Begin pass 1 (max = 7) Extending the inode table. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - 100% The filesystem on /dev/vg0/tmp is now 5242880 blocks long.