LVM (LogicalVolumeManager) allows administrators to create meta devices in Linux that provide an abstraction layer between a file system and the physical storage that is used underneath. The meta devices (on which file systems are placed) are logical volumes, which use storage from storage pools called volume groups. A volume group is provisioned with one or more physical volumes which are the true devices on which the data is stored.
Physical Volume = PV
Volume Group = VG
Logical Volume = LV
The best analogy I can come up with for explaining LVM is a SAN. (Storage Area Network) abstracts the idea of individual hard drives and allows you to carve out “chunks” of space to use as drives. LVM is sort of like that, but for an individual system rather than an entire network.
Let’s say you have two hard drives, /dev/sdb and /dev/sdc. With LVM, any block device can be used as a physical volume (PV).
Once you have the block devices you want to add to your volume group. To do that, use the pvcreate command :
Step 1 : Create physical volume :
pvcreate /dev/sdb
pvcreate /dev/sdc
linux@ap2v:~$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 10.4 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4994
Free PE 4994
Allocated PE 0
PV UUID SRKAXh-EpYr-r2td-g0gA-31RA-fnfz-3qqGrO
--- Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 10.4 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4994
Free PE 4994
Allocated PE 0
PV UUID t2cKru-IwMy-I8re-ADp2-vzFF-Tvh5-O4zMhI
pvscan:
linux@ap2v:~$ sudo pvscan
PV /dev/sdb lvm2 [10.4 GiB]
PV /dev/sdc lvm2 [10.4 GiB]
Total: 2 [20.8 GiB] / in use: 0 [0 ] / in no VG: 2 [20.8 GiB]
Step 2 : Create the Volume Group :
You don’t currently have any volume groups, so create one using the two physical volumes :
vgcreate my_volume_group /dev/sdb /dev/sdc
You’ve created a volume group named my_volume_group using the physical volumes /dev/sdb and /dev/sdc. As with the physical volumes, if you want to check the current state of LVM Volume Groups on your system, type vgdisplay to get a listing :
linux@ap2v:~$ sudo vgdisplay
--- Volume group ---
VG Name my_volume_group
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 20.8 GiB
PE Size 4.00 MiB
Total PE 9988
Alloc PE / Size 0 / 0 GiB
Free PE / Size 9988 / 20.8 GiB
VG UUID oVYiY6-bQp9-4CVO-QgrN-LGgB-1umR-ebJQo4
Step 3 : Create the Logical Volumes :
You get /dev/sda, /dev/sdb and so on. When you create logical volumes, To create your logical volumes, type :
linux@ap2v:~$ sudo lvcreate -L 5G -n 5gig my_volume_group
Logical volume "5gig" created
linux@ap2v:~$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/my_volume_group/5gig
LV Name 5gig
VG Name my_volume_group
LV UUID 3MxOB0-ce5o-yvBD-YORT-52qV-j8HJ-oDru2G
LV Write Access read/write
LV Status available
# open 0
LV Size 5.0 GiB
Current LE 5753
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
Once you’ve successfully created your logical volume. Then mount filesystem as your /home directory
linux@ap2v:~$ sudo mkfs.ext4 /dev/my_volume_group/5gig
linux@ap2v:~$ sudo mount -t ext4 /dev/my_volume_group/5gig /home