In the previous chapter, we looked at adding a new disk drive to a RHEL 9 system, creating a partition and file system, and then mounting that file system to access the disk. An alternative to creating fixed partitions and file systems is to use Logical Volume Management (LVM) to create logical disks comprising space from one or more physical or virtual disks or partitions. The advantage of using LVM is that space can be added to or removed from logical volumes without spreading data over multiple file systems.
Let us take, for example, the root (/home) file system of a RHEL 9-based server. Without LVM, this file system would be created with a specific size when the operating system is installed. If a new disk drive is installed, there is no way to allocate any of that space to the /home file system. The only option would be to create new file systems on the new disk and mount them at particular mount points. In this scenario, you would have plenty of space on the new file system, but the / home file system would still be nearly full. The only option would be to move files onto the new file system. With LVM, the new disk (or part thereof) can be assigned to the logical volume containing the root file system, thereby dynamically extending the space available.
In this chapter, we will look at the steps necessary to add new disk space to both a volume group and a logical volume to add additional space to the root file system of a RHEL 9 system.
An Overview of Logical Volume Management (LVM)
LVM provides a flexible and high-level approach to managing disk space. Instead of each disk drive being split into partitions of fixed sizes onto which fixed-size file systems are created, LVM provides a way to group disk space into logical volumes that can be easily resized and moved. In addition, LVM allows administrators to carefully control disk space assigned to different groups of users by allocating distinct volume groups or logical volumes to those users. When the space initially allocated to the volume is exhausted, the administrator can add more space without moving the user files to a different file system. LVM consists of the following components:
Volume Group (VG)
The Volume Group is the high-level container with one or more logical and physical volumes.
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
Physical Volume (PV)
A physical volume represents a storage device such as a disk drive or other storage media.
Logical Volume (LV)
A logical volume is equivalent to a disk partition and, as with a disk partition, can contain a file system.
Physical Extent (PE)
Each physical volume (PV) is divided into equal size blocks known as physical extents.
Logical Extent (LE)
Each logical volume (LV) is divided into equal size blocks called logical extents.
Suppose we are creating a new volume group called VolGroup001. This volume group needs physical disk space to function, so we allocate three disk partitions /dev/sda1, /dev/sdb1, and /dev/ sdb2. These become physical volumes in VolGroup001. We would then create a logical volume called LogVol001 within the volume group comprising the three physical volumes.
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
If we run out of space in LogVol001, we add more disk partitions as physical volumes and assign them to the volume group and logical volume.
Getting Information about Logical Volumes
As an example of using LVM with RHEL 9, we will work through an example of adding space to the / file system of a standard RHEL 9 installation. Anticipating the need for flexibility in the sizing of the root partition, RHEL 9 sets up the / file system as a logical volume (called root) within a volume group called rhel. Before making any changes to the LVM setup, however, it is essential first to gather information.
Running the mount command will output information about a range of mount points, including the following entry for the root filesystem:
/dev/mapper/rhel-root on / type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
Information about the volume group can be obtained using the vgdisplay command:
# vgdisplay --- Volume group --- VG Name rhel System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size <297.09 GiB PE Size 4.00 MiB Total PE 76054 Alloc PE / Size 76054 / <297.09 GiB Free PE / Size 0 / 0 VG UUID 8vZKNE-v6nY-uII2-NKk1-StmF-EkNp-NNKa9b
As we can see in the above example, the rhel volume group has a physical extent size of 4.00MiB and has a total of 297.09GB available for allocation to logical volumes. Currently, 76054 physical extents are allocated, equaling the total capacity. Therefore, we must add one or more physical volumes to increase the space allocated to any logical volumes in the rhel volume group. The vgs tool is also helpful for displaying a quick overview of the space available in the volume groups on a system:
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
# vgs VG #PV #LV #SN Attr VSize VFree rhel 1 3 0 wz--n- <297.09g 0
Information about logical volumes in a volume group may similarly be obtained using the lvdisplay command:
# lvdisplay --- Logical volume --- LV Path /dev/rhel/swap LV Name swap VG Name rhel LV UUID RckIC8-T5Or-vZf9-Er1e-IqW7-Q7Uc-f9cpvj LV Write Access read/write LV Creation host, time demoserver, 2023-04-10 14:11:15 -0400 LV Status available # open 2 LV Size 3.75 GiB Current LE 960 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/rhel/home LV Name home VG Name rhel LV UUID MMpQ05-Gry0-9qGg-zvGQ-Dszn-kIkd-ZpaqK6 LV Write Access read/write LV Creation host, time demoserver, 2023-04-10 14:11:15 -0400 LV Status available # open 1 LV Size <223.34 GiB Current LE 57174 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/rhel/root LV Name root VG Name rhel LV UUID OFqAB0-azjy-47DO-bzRo-ha2O-sHz5-jjMPcF LV Write Access read/write LV Creation host, time demoserver, 2023-04-10 14:11:17 -0400 LV Status available # open 1 LV Size 70.00 GiB Current LE 17920 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
As shown in the above example, 70 GiB of the space in volume group rhel is allocated to logical volume root (for the / file system), approximately 223.34 GiB to the home volume group (for / home), and 3.75 GiB to swap (for swap space).
Now that we know what space is being used, it is often helpful to understand which devices are providing the space (in other words, which devices are being used as physical volumes). To obtain this information, we need to run the pvdisplay command:
# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name rhel PV Size <297.09 GiB / not usable 4.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 76054 Free PE 0 Allocated PE 76054 PV UUID siKTC2-fq47-LXTG-VWtc-Ma33-XRCm-5uF63v
Clearly, the space controlled by logical volume rhel is provided via a physical volume located on /dev/sda2.
Now that we know more about our LVM configuration, we can add space to the volume group and the logical volume contained within.
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
Adding Additional Space to a Volume Group from the Command-Line
Just as with the previous steps to gather information about the current Logical Volume Management configuration of a RHEL 9 system, changes to this configuration can be made from the command line.
In the remainder of this chapter, we will assume that a new disk has been added to the system and that the operating system sees it as /dev/sdb. We shall also assume this is a new disk with no existing partitions. If existing partitions are present, they should be backed up, and then the partitions should be deleted from the disk using the fdisk utility. For example, assuming a device represented by /dev/sdb containing two partitions as follows:
# fdisk -l /dev/sdb Disk /dev/sdb: 14.46 GiB, 15525216256 bytes, 30322688 sectors Disk model: USB 2.0 FD Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4c33060b Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 30322687 30320640 14.5G 83 Linux
Once any filesystems on these partitions have been unmounted, they can be deleted as follows:
# fdisk /dev/sdb Welcome to fdisk (util-linux 2.37.4). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Before moving to the next step, remove any entries in the /etc/fstab file for these filesystems so that the system does not attempt to mount them on the next reboot.
Once the disk is ready, the next step is to convert this disk into a physical volume using the pvcreate command (also wiping the dos signature if one exists):
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
# pvcreate /dev/sdb WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y Wiping dos signature on /dev/sdb. Physical volume "/dev/sdb" successfully created.
If the creation fails with a message that reads “Device /dev/<device> excluded by a filter”, it may be necessary to wipe the disk using the wipefs command before creating the physical volume:
# wipefs -a /dev/sdb /dev/sdb: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54 /dev/sdb: 8 bytes were erased at offset 0x1fffffe00 (gpt): 45 46 49 20 50 41 52 54 /dev/sdb: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa /dev/sdb: calling ioctl to re-read partition table: Success
With the physical volume created, we now need to add it to the volume group (in this case, rhel) using the vgextend command:
# vgextend rhel /dev/sdb Volume group "rhel" successfully extended
The new physical volume has now been added to the volume group and is ready to be allocated to a logical volume. To do this, we run the lvextend tool providing the size by which we wish to extend the volume. In this case, we want to extend the size of the logical volume home by 14 GB. Note that we need to provide the path to the logical volume, which can be obtained from the lvdisplay command (in this case, /dev/rhel/home):
# lvextend -L+14G /dev/rhel/home Size of logical volume rhel/home changed from <223.34 GiB (57174 extents) to <237.34 GiB (60758 extents). Logical volume rhel/home successfully resized.
The last step is to resize the file system residing on the logical volume to use the additional space. The way this is performed will depend on the filesystem type, which can be identified using the following df command and checking the Type column:
# df -T /home Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/mapper/rhel-home00 xfs 234070356 1669596 232400760 1% /home
If /home is formatted using the XFS filesystem, this can be achieved using the xfs_growfs utility:
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
# xfs_growfs /home meta-data=/dev/mapper/rhel-home isize=512 agcount=4, agsize=14636544 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=1 data = bsize=4096 blocks=58546176, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=28587, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 58546176 to 62216192
If, on the other hand, the filesystem is of type ext2, ext3, or ext4, the resize2fs utility should be used instead when performing the filesystem resize:
# resize2fs /dev/rhel/home
Once the resize completes, the file system will have been extended to use the additional space provided by the new disk drive. All this has been achieved without moving a single file or restarting the server. As far as users on the system are concerned, nothing has changed (except that there is now more disk space).
Adding Additional Space to a Volume Group Using Cockpit
In addition to the command-line utilities outlined so far in this chapter, it is also possible to access information about logical volumes and make volume group and logical volume changes from within the Cockpit web interface using the Storage page, as shown in Figure 32-1:
If the Storage option is not listed, the cockpit-storaged package will need to be installed, and the cockpit service restarted as follows:
# dnf install cockpit-storaged # systemctl restart cockpit.socket
Once the Cockpit service has restarted, log back into the Cockpit interface, at which point the Storage option should now be visible.
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
To add a new disk drive to an existing volume group from within the Cockpit console, start at the above Storage page and click on a filesystem associated with the volume group to be extended from the list marked A above.
On the resulting screen, click on the + button highlighted in Figure 32-2 below to add a physical volume:
Select the new drive to be added to the volume group and click on the Add button:
On returning to the volume group screen, scroll down to the logical volume to be extended and click on it to unfold additional information. Figure 32-4, for example, shows details of the home logical volume:
To extend the logical volume using the new space, click the Grow button and use the slider in the resulting dialog to select how much space should be added to the volume. Then, click the Grow button to commit the change (the available space can be shared among different volume groups if required):
You are reading a sample chapter from Red Hat Enterprise Linux 9 Essentials. Buy the full book now in eBook or Print format.
Includes 34 chapters and 290 pages. Learn more. |
Once these steps are complete, the volume group will have been configured to use the newly added space.
Summary
Volume groups and logical volumes provide an abstract layer on top of the physical storage devices on a RHEL 9 system to provide a flexible way to allocate the space provided by multiple disk drives. This allows disk space allocations to be made and changed dynamically without the need to repartition disk drives and move data between filesystems. This chapter has outlined the basic concepts of volume groups and logical and physical volumes while demonstrating how to manage these using command-line tools and the Cockpit web interface.