Ravindra BagaleCourses & study guides

Chapter 13: Amazon EBS (Elastic Block Store)

13.5 Increasing the size of a volume (root or data)

In my sessions, students often ask: "Sir, I increased the size in the console, why does df -h still show 8G?" Bagha — the disk grew, but the partition and filesystem inside Linux did not. Samjla ka? Let's fix it in two parts.

You can grow a volume without stopping the instance. It is a two-part job: (A) make the EBS volume bigger in AWS, then (B) make the partition and filesystem inside Linux use the new space.

  Before: [ EBS 8 GiB  ][ partition 8 GiB ][ filesystem 8 GiB ]
  Step A: [ EBS 20 GiB                   ][ partition 8 GiB ][ filesystem 8 GiB ]   ← lsblk shows 20G disk, df still 8G
  Step B1 growpart:  [ partition 20 GiB ]
  Step B2 xfs_growfs / resize2fs: [ filesystem 20 GiB ]                              ← df now shows 20G

Take a snapshot first

Always create a snapshot of the volume before resizing. Also note: EBS volumes can only be made bigger, never smaller, and after a modification you must wait (usually up to 6 hours) before modifying the same volume again.

Part A — Modify the volume in the console

  1. EC2 → Instances → select instance → Storage tab → click the Volume ID.
  2. Select the volume → Actions → Modify volume.
  3. Enter the new Size (e.g. 20 GiB); optionally change type to gp3 → Modify → confirm.
  4. Wait until the Volume state shows in-use – optimizing or completed (the new size is usable as soon as it enters optimizing).

CLI alternative: aws ec2 modify-volume --volume-id vol-0123456789abcdef0 --size 20

Part B — Extend partition and filesystem in Linux

Step 1 — check the current layout:

lsblk
df -hT

Example output on a Nitro instance after Part A (root volume grown from 8 to 20 GiB):

NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
nvme0n1       259:0    0   20G  0 disk
├─nvme0n1p1   259:1    0    8G  0 part /
├─nvme0n1p127 259:2    0    1M  0 part
└─nvme0n1p128 259:3    0   10M  0 part /boot/efi

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/nvme0n1p1 xfs   8.0G  1.9G  6.1G  24% /

The disk is 20G but partition nvme0n1p1 and the filesystem are still 8G.

Step 2 — grow the partition (note the space between disk and partition number):

# growpart is in package cloud-utils-growpart (AL2023/CentOS) or cloud-guest-utils (Ubuntu) - usually pre-installed
sudo growpart /dev/nvme0n1 1          # Nitro instance
# sudo growpart /dev/xvda 1           # older Xen instance (t2)
lsblk                                  # nvme0n1p1 should now be 20G

Step 3 — grow the filesystem. First check the type with df -hT:

# XFS (default on Amazon Linux 2023, Amazon Linux 2 and CentOS Stream 9) - give the MOUNT POINT
sudo xfs_growfs -d /

# ext4 (default on Ubuntu) - give the PARTITION DEVICE
sudo resize2fs /dev/nvme0n1p1         # Ubuntu root is usually /dev/nvme0n1p1 (or /dev/xvda1 on Xen)

Step 4 — verify:

df -hT /
lsblk

Data volume without a partition

If you formatted a whole disk directly (e.g. /dev/nvme1n1 with no p1 partition, as we do in 13.6), skip growpart. Just run sudo xfs_growfs -d /data (XFS) or sudo resize2fs /dev/nvme1n1 (ext4) after modifying the volume.

Ubuntu often auto-grows the root on reboot

cloud-init on Ubuntu and Amazon Linux grows the root partition automatically at boot. If you increased the root volume and rebooted, df -h may already show the new size — the manual steps above are for doing it live without a reboot.