How it works…
We can see the list of VGs on a system using the vgs command:
Figure 4.23 – vgs
Here, we can see two VGs: the freshly created DATA VG and the existing ol VG where the OS is installed. We will then use the VG to create an LV. This is done with the lvcreate command. The lvcreate command takes a few parameters: -L to set the size of the volume, -n for the name, and then at the end, the VG where the volume will exist. Let’s create a 3 GB volume named xfs1 in the DATA VG:
lvcreate -L 2G -n xfs1 DATA
We can also tell lvcreate to use all available space. This is done using a lowercase l and the special 100%FREE option:
lvcreate -l 100%FREE -n xfs2 DATA
The lvs command will show all the LVs on a server:
Figure 4.24 – lvs
Here, we can see the xfs1 and xfs2 volumes and their size. Additionally, we can see all the volumes in ol, where Linux was installed.
Let’s go ahead and free up some space by deleting the xfs2 LV. This is done with the lvremove command. When using lvremove, use the VG/LV to identify the LV being deleted. The following command will remove the xfs2 LV:
lvremove DATA/xfs2
You will also need to acknowledge the removal:
Figure 4.25 – lvremove
The last trick is to see the details of a specific LV. This is done with the lvdisplay command. You can run the command by itself, and this will show the details for all LVs on the server. Optionally, you can use the command to report on a single LV, in this case the xfs1 LV:
lvdisplay /dev/DATA/xfs1
The output is as follows:
Figure 4.26 – lvdisplay
Here, you can see the volume creation date, the UUID, and the size of the volume.
Once created, there are various ways to access LVs, but the most common method is by using their mapper addresses. In Linux, the /dev/mapper directory is utilized to access device mapper devices, which is a kernel-level framework that allows for the creation and management of virtual block devices. With a device mapper, advanced storage functionalities such as software RAID, encryption, and LVM can be achieved. By using LVM, a device mapper creates virtual devices that are represented as device mapper devices under the /dev/mapper directory, which act as abstractions and provide an interface for accessing and managing the underlying storage features.
For instance, logical volumes set up using LVM are mapped to device mapper devices located in the /dev/mapper directory. Each logical volume has a corresponding device mapper device entry that can be used to interact with the logical volume as if it were a regular block device. The path for accessing it is /dev/mapper followed by the VG-LV name. Thus, DATA/xfs1 would be /dev/mapper/DATA-xfs1. You can use the dmsetup ls command to show all of the mapped devices:
Figure 4.27 – dmsetup ls