035 Extend Existing Logical Volumes

Tech Tutorial: Create and Configure File Systems - Extending Existing Logical Volumes #

Introduction #

In this tutorial, we will cover a crucial skill for the Red Hat Certified System Administrator (RHCSA) exam: extending existing logical volumes. Managing storage effectively is fundamental for system administrators, especially when dealing with system updates, upgrades, and ensuring that there is always enough space available for the system and user data.

Logical Volume Management (LVM) in Red Hat Enterprise Linux (RHEL) offers a more flexible approach to managing disk space than traditional partitioning methods. One of the significant advantages of using LVM is the ability to resize volumes (either expand or reduce) dynamically. This guide will focus on extending existing logical volumes, which is particularly useful when a volume is running out of space and needs additional capacity.

Prerequisites #

Before proceeding with this guide, you should have the following:

  • A system running RHEL or a derivative distribution.
  • Sufficient unallocated disk space or an available physical volume that can be added to your Volume Group (VG).
  • Basic understanding of LVM concepts such as Physical Volumes (PVs), Volume Groups (VGs), and Logical Volumes (LVs).

Step-by-Step Guide #

Step 1: Checking the Current Logical Volume Configuration #

Before making any changes, it’s essential to understand the current state of your logical volumes. Use the lvdisplay command to display detailed information about all logical volumes in the system.

sudo lvdisplay

This command will output information such as LV Name, VG Name, LV Size, and more, which are critical for identifying the logical volume you want to extend.

Step 2: Preparing Additional Physical Volume (If Required) #

If you do not have enough free space in your existing volume group, you will need to add a new physical volume. First, identify a free disk or partition using the lsblk command.

lsblk

Assume /dev/sdb is free and can be initialized as a physical volume:

sudo pvcreate /dev/sdb

Add this new physical volume to your volume group (replace YourVolumeGroup with the actual name of your volume group):

sudo vgextend YourVolumeGroup /dev/sdb

Step 3: Extending the Logical Volume #

Once you have sufficient space in your volume group, you can proceed to extend the logical volume. First, decide by how much you want to extend the volume. You can specify the size either in megabytes (M), gigabytes (G), or as a percentage of the free space in the VG.

To extend the logical volume by, say, 10GB, use the following command (replace YourLogicalVolume and YourVolumeGroup with actual names):

sudo lvextend -L +10G /dev/YourVolumeGroup/YourLogicalVolume

Alternatively, to extend the LV to use all free space in the VG:

sudo lvextend -l +100%FREE /dev/YourVolumeGroup/YourLogicalVolume

Step 4: Resizing the File System #

After extending the logical volume, you need to resize the filesystem to utilize the additional space. For ext4 filesystems, use:

sudo resize2fs /dev/YourVolumeGroup/YourLogicalVolume

For XFS filesystems, use:

sudo xfs_growfs /dev/YourVolumeGroup/YourLogicalVolume

Conclusion #

Extending logical volumes is a common task for system administrators managing Linux servers, especially in dynamic environments where data growth can be unpredictable. By following the steps outlined in this tutorial, you can ensure that your systems remain operational without running out of disk space. Always ensure to backup important data before performing disk operations to avoid unintended data loss.

This tutorial provided a practical approach to extending logical volumes using Red Hat’s recommended utilities and commands, aligning with the RHCSA exam objectives and ensuring that skills learned are both testable and applicable in real-world scenarios.