Skip to main content

Command Palette

Search for a command to run...

How to Increase Disk Storage on a Running AWS EC2 Instance

Updated
•4 min read•View as Markdown
How to Increase Disk Storage on a Running AWS EC2 Instance
Z

DevOps Engineer

If you're running low on disk space on your running EC2 instance, you don’t need to panic. Whether you're trying to install packages, build Docker containers, or simply noticed your / directory is running out of space, you can increase the disk size without restarting the instance or losing any data.


Symptoms That You Need More Storage

Before increasing disk size, here’s how I knew I needed it:

  • I tried installing applications and it failed with "No space left on device"

  • df -h showed that the / or /dev/root partition was almost full

  • Docker containers were crashing due to low disk space

This is common, especially with default 8 GB EC2 volumes.


Step-by-Step Guide to Increase Storage on a Running EC2 Instance

Step 1: Modify the Volume from AWS Console

  1. Log into your AWS EC2 Console

  2. In the left sidebar, go to Elastic Block Store > Volumes

  3. Identify the volume attached to your instance (look for /dev/xvda)

  4. Select it, click Actions > Modify Volume

  5. Increase the size (e.g., from 8 GiB to 30 GiB)

  6. Click Modify and then Yes to confirm

AWS will show that the volume size has been updated but the instance OS still thinks it’s the old size. The next steps are how we tell the OS to use the new size.


Step 2: Check Current Disk Usage

Once connected to your instance, check how much disk space is being used and how much is available:

df -h

Sample output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.8G  6.0G  300M  95% /

Here, /dev/root is running out of space. Even though we updated the size from the AWS Console, the OS still sees it as 6.8G. We need to expand it manually.


Step 3: Verify and Understand Disk Layout

Before making changes, it’s good to inspect the disk layout:

lsblk

Output might look like:

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   30G  0 disk 
└─xvda1 202:1    0    8G  0 part /

This means the disk xvda has 30G available (updated from the console), but the partition xvda1 is still 8G. We need to extend this partition.


Step 4: Grow the Partition

We use the growpart tool to resize the partition:

sudo growpart /dev/xvda 1
  • xvda is the main disk

  • 1 refers to the first partition (xvda1)

This tells the OS to grow the first partition to use the new available space.

Expected output:

CHANGED: partition=1 start=... old: size=... new: size=...

If you get an error saying growpart: command not found, install it via:

sudo apt-get update && sudo apt-get install cloud-guest-utils

Step 5: Resize the Filesystem

Now that the partition is bigger, we need to tell the filesystem to expand and use the new space:

For ext4 filesystems (most common):

sudo resize2fs /dev/xvda1

For xfs filesystems:

sudo xfs_growfs /

The resize2fs command adjusts the file system to occupy the entire partition. You’ll see:

The filesystem on /dev/xvda1 is now XXXXX blocks long.

Step 6: Verify the New Size

After resizing, verify the change:

df -h

Expected output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        30G  4.0G   25G  15% /

Now, your storage is fully extended and ready for use.


Breakdown of All Commands and Their Purpose

# Check disk usage
sudo df -h
  • Shows human-readable disk usage

  • Use it to verify storage before and after resizing

# Check block devices
lsblk
  • Displays disks and their partitions

  • Helps you identify disk and partition names (e.g., /dev/xvda1)

# Extend partition to use available volume space
sudo growpart /dev/xvda 1
  • Extends partition 1 on the xvda disk
# Resize filesystem for ext4 (common)
sudo resize2fs /dev/xvda1
  • Resizes the filesystem to occupy the new partition space
# Resize filesystem for XFS (less common)
sudo xfs_growfs /
  • Use only if your root is using XFS

Common Questions & Answers

Q: Will this process delete my data?
A: No, if followed correctly. Still, it’s wise to create a snapshot before making any disk changes.

Q: What if I get 'command not found' errors?
A: Use the following to install missing utilities:

sudo apt install cloud-guest-utils

Q: Can I do this without stopping or rebooting my EC2 instance?
A: Yes. These steps are designed for live, running systems.

Q: My partition is already the full size, but I still see low disk. Why?
A: You may be looking at a different partition (like /boot, or /home). Use df -h and lsblk to correlate.

Q: How long does this take?
A: Normally around 10–20 minutes, including console and terminal steps.


Today I learned how to increase storage on a running AWS EC2 instance after I ran into issues like:

  • Docker builds failing

  • apt install failing with "No space left on device"

This simple but powerful trick helped me expand the root disk live, without downtime or data loss.

If you're working with cloud infrastructure, this is an essential skill to keep your instances stable and avoid headaches.