How to Extend an LVM Partition to Use Unallocated Space in Linux

Introduction

If you’re running Linux with Logical Volume Manager (LVM), you may encounter situations where your partition isn’t using all the available disk space. This guide explains how to extend an LVM partition to utilize unallocated space, ensuring you maximize your storage potential.


Prerequisites

  1. A Linux system with LVM configured.
  2. Root or sudo privileges.
  3. Unallocated space in your Volume Group (VG).

You can verify the current disk and volume setup using:

lsblk
df -H
sudo vgdisplay

Step 1: Check Available Space

Run the following command to determine the unallocated space in your Volume Group:

sudo vgdisplay

Look for the Free PE / Size field, which shows the unallocated space available in the volume group. For example:

Free  PE / Size       96767 / <378.00 GiB

This indicates that you have ~378 GiB of free space to allocate.


Step 2: Extend the Logical Volume

Use the lvextend command to allocate the free space to your logical volume. Replace /dev/ubuntu-vg/ubuntu-lv with your logical volume path.

Command:

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Explanation:

  • -l +100%FREE: Allocates all available free space to the logical volume.
  • /dev/ubuntu-vg/ubuntu-lv: The path to your logical volume.

If successful, you’ll see output confirming the extension:

Size of logical volume ubuntu-vg/ubuntu-lv changed from 100.00 GiB to 478.00 GiB.
Logical volume ubuntu-vg/ubuntu-lv successfully resized.

Step 3: Resize the Filesystem

After extending the logical volume, resize the filesystem to use the additional space.

For ext4 Filesystems:

sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

For xfs Filesystems:

sudo xfs_growfs /

(Replace / with the appropriate mount point if different.)


Step 4: Verify the Changes

Check that the filesystem now reflects the new size:

df -H

You should see the logical volume’s size updated to match the allocated space. For example:

Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv  478G   12G  444G  3% /

Troubleshooting

  1. Error: “Can’t parse size argument”: Ensure you’re using -l instead of --size when allocating the free space.
  2. Filesystem resize issues: Check the type of filesystem and use the appropriate resize command (e.g., resize2fs for ext4, xfs_growfs for xfs).
  3. Check Logical Volume Path: Verify the path to your logical volume using: sudo lvdisplay

Conclusion

Extending an LVM partition is straightforward once you understand the commands and process. By following this guide, you can ensure your system uses all available disk space efficiently. LVM’s flexibility allows you to manage storage dynamically without requiring downtime, making it a powerful tool for Linux administrators.

Tags: #Linux #LVM #StorageManagement #SystemAdministration