Increasing disk space on the fly inside AWS is a joy to do (kind of). Especially compared to the challenges with bare-metal or on premise systems.

Understanding the Disks

When working with disks, it is a good idea to have some idea how they work. Normally you would have a set of disks defined in you /dev system (for devices) and you should be able to see these added externally.

If you have an EC2 instance with 2 EBS volumes mounted to it, they are probably something like this. Another thing to note is that because we are using t3 (Nitro) instances, EBS volumes are mounted with different names (oh), but that should not matter. But externally they are not shown as the nvme mounts.

  • Disk 1, 10GB, /dev/sda1
  • Disk 2, 30GB, /dev/xvdb

This is normally reflected into your EC2 instance provided that you have them mounted (you have attached them, right?!).

df is a utility to “Show information about the file system on which each FILE resides, or all file systems by default”. You should see something like this if both disks are attached/mounted.

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           390M   11M  379M   3% /run
/dev/nvme0n1p1  9.7G  8.6G  1.1G  89% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/nvme1n1p1   30G   15G   15G  50% /data
tmpfs           390M     0  390M   0% /run/user/1004

lsblk is a utility to list details about block devices (disks). This will probably look something like this.

lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1     259:2    0   10G  0 disk 
`-nvme0n1p1 259:3    0   10G  0 part /
nvme1n1     259:0    0   30G  0 disk 
`-nvme1n1p1 259:1    0   30G  0 part /data

Increasing Disk space on the fly

You can either increase the size through the console of through some other means, however, it is relatively straightforward (please snapshot it first, I don’t want the blame if you break something).

After this you should be able to see the extra size reflected in lsblk. In this example we have increased the disk size to 100GB.

lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1     259:2    0   10G  0 disk 
`-nvme0n1p1 259:3    0   10G  0 part /
nvme1n1     259:0    0  100G  0 disk 
`-nvme1n1p1 259:1    0  100G  0 part /data

But the actual size available in df has not changed:

df -h
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/nvme1n1p1   30G   15G   15G  50% /data
tmpfs           390M     0  390M   0% /run/user/1004

You have increased disk, however, it does not immediately increase inside df. You will need to grow/expand your partition to be able to use the new space. To do this you will need to understand what kind of block device it is, but generally in linux you are using an ext disk.

You can grow the partition with growpart:

growpart /dev/nvme1n1 1 
CHANGED: partition=1 start=16065 old: size=104841502 end=104857567 new: size=209699102,end=209715167

Then, you can expand it with resize2fs which completes the job:

resize2fs /dev/nvme1n1p1 
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/nvme1n1p1 is mounted on /data; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 7

Now it is reflected in df and you can use all your new space!

df -h
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/nvme1n1p1  100G   15G   85G  15% /data
tmpfs           390M     0  390M   0% /run/user/1004