How to Expand Root Partition on CentOS / AlmaLinux 8/9 in VMware ESXi: A Step-by-Step Guide

How to Expand Root Partition on CentOS / AlmaLinux 8/9 in VMware ESXi: A Step-by-Step Guide

Running out of space on your CentOS or AlmaLinux VM hosted on VMware ESXi? Expanding the root partition can resolve storage issues and improve server performance. This comprehensive guide will walk you through expanding the root partition, logical volume (LVM), and filesystem in CentOS 7, CentOS 8, AlmaLinux 8, and AlmaLinux 9.

By the end of this tutorial, you will learn:

  • How to rescan the disk and extend partitions in VMware ESXi.
  • How to expand LVM-based logical volumes and filesystems.
  • How to handle situations where growpart is unavailable.

Let’s get started.

Why Expand the Root Partition?

Over time, disk space can become limited due to:

  • Increased storage needs for applications, logs, or backups.
  • Growing data requirements for websites or databases.
  • Scaling system resources to meet business demands.

Expanding the root partition ensures seamless performance without running into storage errors or downtime.

Prerequisites

Before starting:

  1. Ensure you have root or sudo access to the VM.
  2. Backup important data as a precaution.
  3. Add disk space to your VM in VMware ESXi:
    • Go to VMware ESXi dashboard.
    • Power off the VM (recommended) and increase the virtual disk size.
    • Power the VM back on.
Add disk space to your VM in VMware ESXi

Now let’s expand the root partition.

Step 1: Verify the Disk Space

Log into your CentOS/AlmaLinux server and verify the added space:

lsblk

You should see the updated disk size under /dev/sda. For example:

sda    650G  # Updated disk size
sda2   598G  # Existing partition
Verify the Disk Space

Step 2: Rescan the Disk

If the added space does not appear, rescan the disk:

echo 1 > /sys/class/block/sda/device/rescan

Verify with lsblk again.

Step 3: Extend the Partition (Using growpart or parted)

Option 1: Using growpart (Recommended)

Install cloud-utils-growpart if it’s not already installed:

yum install cloud-utils-growpart -y

Extend the second partition (sda2):

growpart /dev/sda 2

Verify the partition size:

lsblk
Extend the Partition (Using growpart or parted)

Option 2: Using parted (If growpart is unavailable)

If growpart is not installed, use parted:

parted /dev/sda

Within the parted shell:

print          # View the current partition table
resizepart 2 100%  # Extend partition 2 to use all available space
print          # Confirm the changes
quit

Step 4: Resize the Physical Volume (PV)

Once the partition is extended, resize the physical volume:

pvresize /dev/sda2

Verify the updated volume group space:

vgs

The free space in the volume group will reflect the added disk space.

Step 5: Extend the Logical Volume (LV)

Now, expand the logical volume (centos-root):

lvextend -l +100%FREE /dev/mapper/centos-root

This command allocates all available free space to the root logical volume.

Step 6: Resize the Filesystem

Finally, grow the filesystem so it can utilize the newly allocated space.

For XFS Filesystem (Default in CentOS 7/AlmaLinux 8/9):

xfs_growfs /

For EXT4 Filesystem:

resize2fs /dev/mapper/centos-root

Step 7: Verify the Changes

Confirm the root filesystem has been expanded:

df -h /
How to Expand Root Partition on CentOS / AlmaLinux 8/9 in VMware ESXi

You should see the updated size reflecting the additional space.

Conclusion

You’ve successfully expanded the root partition on your CentOS 7/8 or AlmaLinux 8/9 VM hosted in VMware ESXi. By following these steps, you’ve safely resized the partition, logical volume, and filesystem without downtime.

At ehostingserver.com, we specialize in providing reliable hosting solutions and expert tips to optimize your virtual infrastructure. If you need assistance managing your Linux servers or expanding resources, feel free to contact our team.

Share this guide to help others streamline their VM management!

FAQs

1. What if the new space does not appear in lsblk?
Rescan the disk using: echo 1 > /sys/class/block/sda/device/rescan.

2. Can I perform these steps without rebooting the VM?
Yes, all steps can be performed live without downtime.

3. Is growpart necessary to resize the partition?
No, you can use parted as an alternative.

4. What if I’m using a non-LVM partition?
For non-LVM partitions, tools like resize2fs (EXT4) or xfs_growfs (XFS) can still expand the filesystem after extending the partition.

Leave a Reply

Your email address will not be published. Required fields are marked *