One of the great benefits of virtualized infrastructure is no longer are we constrained by the physical limitations of hardware. Before where adding CPU, Memory, or Disk Space would have required a system to be taken down, virtualized infrastructure like our Virtual Cloud Servers allows for changes to disk or RAM at the touch of a button. Here we’ll show you how to utilize this to grow your Linux system’s disk on-the-fly all without ever taking your system down.

This guide was designed around CentOS procedures, but Ubuntu and other distributions should be similar.

First, you’ll need utilize the appropriate method to grow the disk size of the underlying storage for your Virtual Machine, after that’s done you should see something like the following in your system logs:

[779134.335674] virtio_blk virtio1: new size: 314572800 512-byte logical blocks (139 GB/150 GiB)
[779134.336323] vda: detected capacity change from 41943040000 to 161061273600

If this doesn’t happen, you may need to reboot your VM for Linux to pick up that the underlying storage device is now larger.

You just need to run two commands to grow your Linux file system, first, you’ll use growpart to extend the appropriate partition to the new end of the underlying storage device. Second, you’ll run resize2fs to complete online resizing of the file system.

$ sudo growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=81917952 end=81920000 new: size=314566717,end=314568765
$ sudo resize2fs /dev/vda1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 19
The filesystem on /dev/vda1 is now 39320839 blocks long.
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       148G   25G  117G  18% /

That’s it, there’s only two commands you need to run to grow your disk space in a virtualized Linux environment. No more are the days of having to take down your system for extended periods of time waiting for a file system to be expanded.