Logical Volume Management
LVM (Logical Volume Management) is a powerful option to manage hard disks available in many Linux distributions.
There are some terms that you’ll need to know about LVM. The most important things you must understand are:
- Physical volumes: These are your physical disks, RAID arrays, or disk partitions, such as /dev/hda or /dev/hdb1.
- Volume groups: Groups physical volumes into storage groups, and is the storage used to create logical volumes. Volume groups can be resized by adding new physical volumes or ejecting existing logical volumes.
- Logical volumes: These are the volumes that you’ll end up mounting upon your system. They can be added, removed, and resized on the fly. Logical volumes (LVs) can be resized online by concatenating or truncating.
In this post, we will take you through the steps to configure disks using LVM by creating PVs, VGs, and LVs.
Consider a scenario with 2 HDD of 100GB and 200GB. First partitions both the disks /dev/hdc and /dev/hdd using fdisk command.
Create Physical Volumes (PVs).
root@raffe:~# pvcreate /dev/hdc1 root@raffe:~# pvcreate /dev/hdd1
Lets then create a Volume Group (VG).
root@raffe:~# vgcreate myvg /dev/hdc1 /dev/hdd1 Volume group "myvg" successfully created
Let’s then create logical volumes of size 16 GB and 32 GB with the name myvol1, and myvol2 hosted on the LVM volume group myvg.
root@raffe:~# lvcreate -n myvol1 --size 16g myvg Logical volume "myvol1" created root@raffe:~# lvcreate -n myvol2 --size 32g myvg Logical volume "myvol2" created
The LVs at /dev/myvg/myvol1 and /dev/myvg/myvol2 can be formatted and mounted just like any other partition.
root@raffe:~# vgdisplay --- Logical volume --- LV Path /dev/myvg/myvol1 LV Name myvol1 VG Name myvg LV UUID VAmIV4-r66d-tTPj-GxCq-QYd3-q38z-kN0k5S LV Write Access read/write LV Creation host, time raffe.example.com, 2018-03-05 23:56:22 +0100 LV Status available # open 0 LV Size 16.00 GiB Current LE 4096 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:12 --- Logical volume --- LV Path /dev/myvg/myvol2 LV Name myvol2 VG Name myvg LV UUID 2ty6DP-N1f7-pHPX-95Sr-yKj1-Sw1B-XvKJFH LV Write Access read/write LV Creation host, time raffe.example.com, 2018-10-03 10:53:56 +0200 LV Status available # open 0 LV Size 32.00 GiB Current LE 8192 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:14