Creating LVM volumes on Linux

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 sdb, showing as 10G in size.

Using lsblk to view available devices on your server.

Physical Volumes

The first step in creating an LVM volume is to create the physical volume.

# pvcreate /dev/sdb
Use pvcreate to setup the physical volume.

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 group, and can be called whatever you wish. I like adding vg_ to signify that this is the volume group.

Use vgcreate to setup the volume group.

We can then view our volume groups to verify.

# vgs

We see both the primary volume group, rhel that was created during the installation of Red Hat Linux 8, and our newly created volume group.

vgs can be used to verify your volume groups on the server.

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. The -n 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).

lvcreate to setup logical volumes.

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.

lvs is the command to use to verify your logical volumes on your server.

Using the lsblk command again, we see our volume group and the logical volume

lsblk to verify the new lvm 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 volume, 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 fstab file.

mkfs.xfs to create an XFS file system on your LVM volume, then mount the volume.
Share

Ivan Windon

Ivan Windon is a Site Reliability Engineer at IBM. Ivan is actively engaged in Cloud Technologies with AWS, Google, and Azure. Ivan has extensive experience with Linux and Windows administration, DNS, Networking, IDM, and Security. In his free time, he enjoys being with his wife and two children. The family enjoys hiking, and traveling when able. His favorite locations are Yosemite NPS, and San Francisco, California.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.