How to Expand a Volume on a Linux Virtual Machine?

Storage
byPavitra

Introduction

Expanding a volume on a Linux virtual machine allows you to increase the available disk capacity when the existing storage is no longer sufficient. After extending the VM’s disk from the CMP Dashboard, additional steps are required inside the Linux operating system to ensure that the new capacity is available to the partition and filesystem.

This guide explains how to verify the current disk layout, install the required cloud-utils-growpart utility, extend the target partition using growpart, and resize the filesystem using resize2fs. Follow the steps carefully to ensure that the additional storage capacity is correctly recognized and utilized by the Linux VM.

Prerequisites

Before expanding a volume on a Linux VM, ensure the following requirements are met:

  • The VM’s disk has already been extended from the CMP Dashboard.
  • You have access to the Linux VM with root privileges or sufficient administrative permissions.
  • The cloud-utils-growpart utility is installed.
  • You have identified the disk and partition that need to be extended.

Important: Increasing the disk size from the CMP Dashboard does not automatically make the additional space available to the filesystem inside the Linux VM. The partition and filesystem may need to be extended separately.

Steps to Expand the Volume

Step 1: Verify the Current Disk Layout

Log in to the Linux VM and run the following command to view the current disk and partition layout:

Bash
lsblk

Review the output and identify the disk and partition that correspond to the volume you want to expand.

For example, if the target partition is /dev/vda1, the underlying disk is /dev/vda and the partition number is 1.

Note: The disk and partition names can differ between VMs. Always verify the output of lsblk before running the partition expansion command.

Step 2: Install cloud-utils-growpart

The growpart utility is used to extend a partition into the additional space available on the disk.

Red Hat, CentOS, and Rocky Linux

Run:

Bash
yum install cloud-utils-growpart -y

Debian-based Distributions

Run:

Bash
apt install cloud-utils-growpart

Alternatively, the utility can be installed using:

Bash
apt install cloud-guest-utils -y

Note: Use the package manager appropriate for your Linux distribution.

Step 3: Extend the Partition

After installing growpart, extend the target partition using the following command format:

Bash
growpart /dev/vda 1

In this example:

  • /dev/vda is the disk.
  • 1 is the partition number.
  • The resulting target partition is /dev/vda1.

Example output:

[root@cmp ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2099200 old: size=60815327 end=62914526 new: size=102758367
end=104857566

growpart command

Important: Replace /dev/vda and 1 with the actual disk and partition identified using lsblk. Do not copy the example values unless they match your VM.

Step 4: Resize the Filesystem

After extending the partition, resize the filesystem so that it can use the additional disk capacity.

For the filesystem procedure documented in the source, run:

Bash
resize2fs /dev/vda1

Example output:

[root@cmp ~]# resize2fs /dev/vda1
resize2fs 1.47.8 (5-Feb-2023)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 7
The filesystem on /dev/vda1 is now 12844795 (4k) blocks long.

resize2fs command

After the command completes, verify the available disk capacity from inside the VM.

Important: The resize2fs procedure provided in this article is based on the filesystem command documented in the source. Ensure that the filesystem and device path match your actual VM configuration before executing the command.

Verify the Expanded Volume

After completing the partition and filesystem expansion, verify that the additional capacity is available.

Run:

Bash
lsblk

You can also use:

Bash
df -h

Review the output and confirm that the expected partition and filesystem capacity have increased.

Tip: If the disk size has increased but the filesystem still shows the previous capacity, verify that both the partition expansion and filesystem resize steps were completed successfully.

Troubleshooting

The Additional Disk Space Is Not Visible

If the new disk capacity is not visible inside the Linux VM:

  1. Confirm that the disk was successfully extended from the CMP Dashboard.
  2. Run lsblk to verify the current disk and partition sizes.
  3. Confirm that the correct disk and partition were selected.
  4. Run growpart against the correct disk and partition.
  5. Run the appropriate filesystem resize command.
  6. Verify the final filesystem capacity using df -h.

growpart Command Is Not Found

If the system reports that growpart is unavailable, install the required package:

For Red Hat, CentOS, and Rocky Linux:

Bash
yum install cloud-utils-growpart -y

For Debian-based distributions:

Bash
apt install cloud-utils-growpart

Or:

Bash
apt install cloud-guest-utils -y

Incorrect Disk or Partition Identified

If you are unsure which disk or partition should be extended, run:

Bash
lsblk

Carefully review the output before executing growpart.

For example:

Bash
growpart /dev/vda 1

Here, /dev/vda represents the disk and 1 represents its first partition.

Warning: Do not run growpart against an incorrect disk or partition. Always verify the storage layout before making partition changes.

Summary

In this guide, we expanded a Linux VM’s disk by first extending the disk from the CMP Dashboard and then performing the required operations inside the guest operating system.

The process consists of:

  1. Verifying the disk and partition layout using lsblk.
  2. Installing cloud-utils-growpart.
  3. Extending the required partition using growpart.
  4. Resizing the filesystem using resize2fs.
  5. Verifying the resulting capacity.

These steps allow the Linux VM to use the additional storage capacity provided after the volume is expanded.

Conclusion

Expanding a volume on a Linux virtual machine in CMP requires both the disk expansion at the platform level and the corresponding partition and filesystem expansion inside the guest operating system.

Always verify the disk layout before making partition changes, use the correct disk and partition identifiers, and confirm the final capacity after resizing. Following the procedure in this guide ensures that the additional disk space is properly made available to the Linux VM.

FAQ’s

Do I need to expand the disk from the CMP Dashboard first?

Yes. The source procedure requires the VM’s disk to be extended from the CMP Dashboard before performing the Linux operating-system steps.

What command can I use to check the current disk layout?

Use:

Bash
lsblk

This displays the disks and partitions available inside the Linux VM.

What is cloud-utils-growpart used for?

cloud-utils-growpart provides the growpart utility, which is used to extend an existing partition into available disk space.

How do I extend the first partition on /dev/vda?

Use:

Bash
growpart /dev/vda 1

Before running the command, verify that /dev/vda and partition 1 are the correct target using lsblk.

Does extending the partition automatically resize the filesystem?

No. After extending the partition, the filesystem may also need to be resized so that it can use the additional capacity.

Which command is used in this procedure to resize the filesystem?

The source procedure uses:

Bash
resize2fs /dev/vda1

The device path should be replaced with the actual target partition where applicable.

What should I do if the new capacity is still not visible?

Verify the disk and partition sizes using:

Bash
lsblk

Then check filesystem capacity using:

Bash
df -h

If the partition has not been extended, repeat the growpart step with the correct disk and partition.

Can I use the example /dev/vda1 on every Linux VM?

No. Device names vary between systems. Always use lsblk to identify the correct disk and partition before running any storage modification command.