How to create and extend logical volumes by using LVM on Redhat 8.5

3 min read 6 months ago
Published on Aug 10, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of creating and extending logical volumes using Logical Volume Manager (LVM) on Red Hat 8.5. LVM allows for flexible disk management, enabling you to combine multiple storage devices into one logical unit, which you can easily resize as needed. Understanding LVM is essential for managing storage efficiently in a Linux environment.

Step 1: Install LVM if Not Already Installed

Before you can use LVM, ensure it is installed on your system. Follow these steps:

  1. Open your terminal.
  2. Check if LVM is installed by running:
    rpm -qa | grep lvm
    
  3. If LVM is not installed, you can install it using:
    sudo dnf install lvm2
    

Step 2: Create Physical Volumes

Physical volumes are the actual physical storage devices you will use in your volume group. To create physical volumes:

  1. Identify the disks or partitions you want to use:
    lsblk
    
  2. Create physical volumes with the following command:
    sudo pvcreate /dev/sdX
    
    Replace /dev/sdX with your actual disk identifier.

Step 3: Create a Volume Group

Next, you will create a volume group that combines your physical volumes:

  1. Use the vgcreate command to create a volume group:
    sudo vgcreate my_volume_group /dev/sdX
    
    Replace my_volume_group with your preferred name and /dev/sdX with your physical volume.

Step 4: Create Logical Volumes

Now you can create logical volumes from your volume group:

  1. Use the lvcreate command:
    sudo lvcreate -n my_logical_volume -L 10G my_volume_group
    
    Here, my_logical_volume is the name of your logical volume, 10G is the size, and my_volume_group is your volume group.

Step 5: Format the Logical Volume

To use your logical volume, you need to format it with a filesystem:

  1. Format the logical volume using:
    sudo mkfs.ext4 /dev/my_volume_group/my_logical_volume
    

Step 6: Mount the Logical Volume

After formatting, mount the logical volume to access it:

  1. Create a mount point:
    sudo mkdir /mnt/my_mount_point
    
  2. Mount the logical volume:
    sudo mount /dev/my_volume_group/my_logical_volume /mnt/my_mount_point
    

Step 7: Extend Logical Volumes

If you need to extend a logical volume:

  1. First, ensure you have free space in your volume group. Check with:

    vgdisplay
    
  2. Extend the logical volume using:

    sudo lvextend -L +5G /dev/my_volume_group/my_logical_volume
    

    This adds an additional 5GB to the logical volume.

  3. After extending, resize the filesystem:

    sudo resize2fs /dev/my_volume_group/my_logical_volume
    

Conclusion

In this tutorial, you learned how to install LVM, create physical and logical volumes, format them, and extend them when necessary. LVM provides significant flexibility for managing storage in Linux systems. For further exploration, consider learning about snapshots and mirroring in LVM to enhance your storage management capabilities.