Running out of disk space on your Amazon Elastic Block Store (EBS) volume can bring your application to a grinding halt. Whether it’s a flooded log directory or an unexpectedly large dataset, a full disk demands immediate action. In this article, I’ll walk you through the process of resizing an EBS volume step-by-step, complete with practical examples and command outputs. By the end, you’ll know how to expand your disk, verify the changes, and get your system back on track—all while keeping things clear for both beginners and seasoned developers.

This guide assumes you’re working on a Linux-based EC2 instance with an EBS volume and have administrative access. We’ll use standard Linux tools and AWS best practices to resize the disk safely. Let’s dive in!

Why Resize an EBS Volume?

When your root partition hits 100% capacity, your system may start behaving unpredictably—processes may fail, logs may stop writing, or worse, your application could crash. The df -h command is your first clue to confirm this:

Example Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1   10G   10G     0 100% /
tmpfs           3.9G     0  3.9G   0% /dev/shm

In this output, /dev/nvme0n1p1 (the root partition) is completely full. To fix this, we need to increase the EBS volume size and update the filesystem to use the new space.

Step-by-Step Guide to Resize an EBS Volume

Step 1: Verify Disk Usage

Start by confirming that your disk is indeed full. Run:

This command shows the disk usage in a human-readable format. Look for the root partition (usually mounted on /) and check the Use% column. If it’s at or near 100%, proceed to the next step.


Step 2: Identify the Block Device

To resize the disk, you need to know which block device and partition you’re working with. Use the lsblk command to list block devices:

Example Output:

NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1     259:0    0   20G  0 disk 
└─nvme0n1p1 259:1    0   10G  0 part /

Here, nvme0n1 is the EBS volume, and nvme0n1p1 is the partition mounted at /. Note that after resizing the EBS volume in the AWS Management Console (more on this later), the disk size might show as larger (e.g., 20G), but the partition size remains unchanged (10G) until we extend it.

For additional details, such as the filesystem type, run:

Example Output:

NAME        FSTYPE LABEL UUID                                 MOUNTPOINT
nvme0n1                                                      
└─nvme0n1p1 ext4         123e4567-e89b-12d3-a456-426614174000 /

This confirms the filesystem is ext4, which we’ll need for the resizing step.


Step 3: Increase the EBS Volume Size in AWS

Before resizing the partition, you need to increase the EBS volume size in the AWS Management Console:

  1. Go to the EC2 Dashboard > Volumes.
  2. Locate the volume attached to your instance (e.g., /dev/nvme0n1).
  3. Select the volume, click Actions > Modify Volume.
  4. Enter the new size (e.g., from 10GB to 20GB) and confirm.

AWS will update the volume size, but the partition and filesystem won’t automatically reflect this change. That’s what we’ll do next.

Reference: For detailed steps, see the AWS Knowledge Center.


Step 4: Create a Temporary Filesystem

Resizing operations may require temporary space, especially if /tmp is on the full root partition. To avoid issues, create a temporary filesystem in memory:

This command mounts a 10MB temporary filesystem at /tmp. The options nodev and nosuid enhance security by preventing device files and setuid binaries in this temporary space.


Step 5: Extend the Partition

Now, extend the partition to use the new EBS volume size. Use the growpart command to expand the partition:

Note: Replace /dev/nvme0n1 with your device name and 1 with the partition number (e.g., nvme0n1p1 uses partition 1).

Example Output:

CHANGED: partition=1 start=2048 old: size=20969472 end=20971520 new: size=41940992 end=41943040

This output confirms that the partition has been resized to use the additional space.

Verify the change with:

Example Output:

NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1     259:0    0   20G  0 disk 
└─nvme0n1p1 259:1    0   20G  0 part /

Now, the partition size matches the disk size (20G).


Step 6: Resize the Filesystem

The partition is larger, but the filesystem still needs to be resized to use the new space. For an ext4 filesystem, use:

Note: Replace /dev/nvme0n1p1 with your partition name.

Example Output:

resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/nvme0n1p1 is now 5242624 (4k) blocks long.

This confirms the filesystem has been resized.


Step 7: Verify the Resized Disk

Check the disk usage again to ensure the new space is available:

Example Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1   20G   10G   10G  50% /
tmpfs            10M     0   10M   0% /tmp

The root partition now shows 20GB total, with 10GB available—problem solved!


Step 8: Clean Up

Unmount the temporary filesystem, as it’s no longer needed:

Troubleshooting Tips

  • Command not found: Ensure tools like cloud-utils (for growpart) and e2fsprogs (for resize2fs) are installed. Install them with sudo apt-get install cloud-guest-utils e2fsprogs on Debian/Ubuntu or equivalent for your distribution.
  • Permission denied: Verify you’re running commands as root or with sudo.
  • Partition not resizing: Double-check the device and partition names with lsblk. Ensure the EBS volume size was increased in the AWS Console.
  • Non-ext4 filesystems: For XFS, use xfs_growfs instead of resize2fs. For other filesystems, consult the appropriate documentation.

Best Practices

  • Backup First: Always create an EBS snapshot before modifying volumes to avoid data loss.
  • Monitor Disk Usage: Use tools like CloudWatch to alert you before disks fill up.
  • Automate Resizing: For dynamic workloads, consider scripts or AWS Lambda functions to automate volume resizing.
  • Test in Staging: Practice these steps in a non-production environment to build confidence.

Conclusion

Resizing an EBS volume is a straightforward process when you break it down: verify the issue, extend the volume, expand the partition, resize the filesystem, and confirm the results. By following these steps, you can quickly recover from a full disk and keep your applications running smoothly. The commands and outputs provided here should serve as a handy reference for your next disk emergency.

For more details, check out the AWS Knowledge Center. If you run into issues or have questions, drop them in the comments or reach out to AWS Support. Happy resizing!