In this tutorial we will see how to create a Logical Volume Management - LVM in CentOS 8 from the command line. Remarks: This tutorial can be used for other Red Hat or Debian based distributions with some modifications. The LVM will be created using two hard disks of 1G each.
Introduction to Logical Volume Management - LVM
Logical Volume Management (LVM) treats multiple hard disks as if they were just one. Logical volumes are like files in a normal file system; the file system (or volume group, in the case of LVM) manages the allocation of space when files or logical volumes are resized. LVMs are composed of:
- PV: physical volumes, - VG: volume group - group of one or more PVs, - PE: phisical extents (VG extensions) - physical size parts, - LV: logical volume (logical volume) - virtual volume, - LE: logical extents (LV extensions) - logical size parts.
Step-by-step instructions to mount the new LVM on CentOS 8
We open a terminal in CentOS 8 if we are in a graphical environment or use the command line to execute the following commands.
To display information about the disks:
lsblk
To view partitions and configuration:
sudo fdisk -l
To create a physical volume with the two hard disks:
sudo pvcreate /dev/sdb /dev/sdc
To create a volume group:
sudo vgcreate volumegroup /dev/sdb /dev/sdc
To display the created volume group:
sudo vgdisplay volumegroup
To create a logical volume:
sudo lvcreate -L 2G -n logicalvolume volumevolumegroup
To verify the creation:
sudo lvscan/dev/grupovolumen/volumenlogico
sudo lvdisplay /dev/groupvolume/logicalvolume
To list LVM components and get information:
sudo pvssudo vgssudo lvs
To create a file system on the created LV:
sudo mkfs.ext4 /dev/volumegroup/logicalvolume
In order to use the new volume, it must first be mounted:
sudo mkdir /mnt/newvolumesudo mount /dev/groupvolume/logicalvolume /mnt/newvolume
To make the mount permanent, the following line is added to the /etc/fstab file:
/dev/volumegroup/logicalvolume /mnt/newvolume ext4 defaults 0 0
To display the newly mounted and operational volume:
df -h
To give write permissions to the user:
sudo chown -R /mnt/newvolume/
Bibliography:
Red Hat Documentation. <https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/logical_volumes>.
Red Hat Documentation. <https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/4/html/cluster_logical_volume_manager/lvm_cli>
2day Geek. <https://www.2daygeek.com/create-lvm-storage-logical-volume-manager-in-linux/>
The images used on the covers, unless otherwise indicated, are free and/or royalty-free. They belong to various authors and were downloaded from Unsplash, Pixabay, and/or Pexels.
If you are looking for a trainer to run this course or another training activity (webinar, workshops, bootcamps, etc.) in your organisation, you can find me through the contact page. Thank you very much.
If you liked the article you can help me by donating with cryptocurrencies. Thank you!!!


