In this article, I will be going over the steps to create an LVM volume on Linux. Logical Volume Manager (LVM) was originally created by Heinz Mauelshagen, who wrote the original LVM code in 1998. The primary design guidelines were taken from HP-UX’s volume manager.
The procedure is fairly straight forward, we just need to create the physical volume, the volume group, and finally the logical volume. I added a 10 GB device to this Red Hat Linux 8 server.
Creating LVM volumes
# lsblk
The lsblk command shows us the available devices on the linux server. The one we need is , showing as 10G in size.
Physical Volumes
The first step in creating an LVM volume is to create the physical volume.
# pvcreate /dev/sdb
Volume Group
Second we create the volume group.
# vgcreate vg_iscsi_vol /dev/sdb
The vg_isci_vol is just the name of the volume and can be called whatever you wish. I like adding vg_ to signify that this is the volume group.
We can then view our volume groups to verify.
# vgs
We see both the primary volume group, that was created during the installation of Red Hat Linux 8, and our newly created volume group.
Logical Volume
The final layer in creating a LVM volume on Linux is creating the logical volume.
# lvcreate -L 5G -n lv_iSCSI_volume vg_iscsi_vol
The parameter -L 5G tell the logical volume we just wish to use 5 GB of the 10 GB. is for specifying a name for your logical volume. I went with lv_iSCSI_volume (lv for the logical volume, iSCSI to signify its future role, and volume just because I wanted to).
We then verify our work once again.
# lvs
We see that it is only using 5 GBs. You can easily expand the LVM later on by using the remaining portion of the 5 GBs or adding more devices to the server and adding a new physical volume and adding it to this logical volume group.
Using the lsblk command again, we see our volume group and the logical volume
File System
Finally we need a file system on our volume.
# mkfs.xfs /dev/vg_iscsi_vol/lv_iSCSI_volume
You can also do:
# mkfs -t xfs /dev/vg_iscsi_vol/lv_iSCSI_volume
-t is for the file system type, such as xfs, ext4, gfs2, etc.
Mounting the LVM volume
Then we just need to mount the volume so we can start using it.
# mount /dev/vg_iscsi_vol/lv_iSCSI_volume /mnt
The /mnt is the location on the file system you wish to mount the and can be called whatever you want, just as long as you have created the directory beforehand. If you wish to have the mount persist after a reboot, you will need to add this to your file.