How to expand the disk space using the volume?

How to expand the disk space using the volume

Once a volume is attached, it shows up inside your VM as a separate, blank disk. It does not make your main disk (the one mounted at /) any bigger, and it won’t appear in df -h until it is formatted and mounted. The steps below make the extra space ready to use.

Note: The commands in this guide were tested on Ubuntu 24.04. Commands and device names can be different on other operating systems. For example, AlmaLinux, Rocky Linux and RHEL usually use mkfs.xfs instead of mkfs.ext4, and some servers name the new disk /dev/sdb instead of /dev/vdb.

Step 1: Check the attached volume

After you attach the volume, run df -h on the VM. Nothing new shows up, and that’s expected. df -h only lists disks that are mounted, and this one isn’t yet.

df -h

Check the attached volume

lsblk lists every disk the VM can see, mounted or not, so use that instead.

lsblk

MOUNTPOINTS

In our test the new volume is vdb. It’s 50G, has no partitions, and nothing under MOUNTPOINTS. Add the -f flag to see if there’s a filesystem on it.

lsblk -f

lsblk -f

An empty FSTYPE next to vdb means the disk is blank.

Step 2: Format the volume

Your volume may not be called vdb, so check the name in the lsblk output first. Then format it with ext4:

sudo mkfs.ext4 /dev/vdb

Run lsblk -f once more.

lsblk -f

Warning: Formatting permanently erases existing data. Readers must confirm they have selected the correct, empty disk.

FSTYPE

vdb should now list ext4 under FSTYPE, so the volume is ready to mount.

Step 3: Mount the volume

Create a folder and mount the volume on it:

sudo mkdir -p /mnt/data
sudo mount /dev/vdb /mnt/data
df -h /mnt/data

df -h /mnt/data

/dev/vdb now appears with about 49G of space, mounted on /mnt/data.

Step 4: Make the mount permanent

A mount made with the command above is lost after a reboot. To keep it, add the volume to /etc/fstab. First, get the volume’s UUID:

sudo blkid /dev/vdb

Copy the UUID from the output, then add the entry (replace your-uuid-here with your own UUID):

echo 'UUID=your-uuid-here /mnt/data ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab

Keep the UUID= part at the start. An incorrect fstab entry can cause mounting errors, and the volume will not mount again.

Now confirm the entry works:

cat /etc/fstab
sudo systemctl daemon-reload
sudo findmnt --verify --verbose
sudo mount -a
df -h /mnt/data

df -h /mnt/

Check the last line of /etc/fstab. It needs to begin with UUID=. Then look at the df -h /mnt/data output, which should list /dev/vdb on /mnt/data. Keep in mind that if you format this volume again later, it gets a new UUID, and you’ll have to change the line in /etc/fstab to match.

Step 5: Test the volume

Put a small file on the volume, then read it.

echo "volume test" | sudo tee /mnt/data/test.txt
cat /mnt/data/test.txt

cat /mnt/data/test.txt

Seeing volume test printed means the volume works and you can write to it.

Step 6 (Optional): Verify after a reboot

This step is only worth doing if you can restart the server. Plenty of production servers can’t go down, and that’s fine, since the mount -a check in Step 4 already tells you the fstab line is correct.

sudo reboot

After the server comes back up, log in and run these three commands. The volume should still be mounted and the file still there.

lsblk
df -h
cat /mnt/data/test.txt

lsblk shows

lsblk shows /mnt/data next to vdb, df -h lists /dev/vdb, and the test file is still there.

Using the extra space

Your main disk stays the same size, and the volume gives you extra space at /mnt/data. Anything you save in that folder is stored on the volume. By default the folder belongs to the root user, so to let a regular user write to it, run (replace ubuntu with your username):

sudo chown -R ubuntu:ubuntu /mnt/data

Applications such as databases, backups or website files only use the new space once they are set up to store their data in /mnt/data.

Conclusion:

After attaching the volume, format it, mount it, and add it to /etc/fstab. Your VM then has extra storage at /mnt/data that stays available after every reboot, while your main disk stays the same size.

 

All third-party logos and trademarks displayed on AccuWeb Cloud are the property of their respective owners and are used only for identification purposes. Their use does not imply any endorsement or affiliation.