How do I extend my Linux file system after increasing my EBS volume on my EC2 instance?

3 minute read

I increased the size of my Amazon Elastic Block Store (Amazon EBS) volume, but my file systems aren't using the full volume. How do I fix that?


When a volume is expanded to a larger size, the file system must also be resized to take advantage of the larger volume size. You can resize a file system as soon as it's in the optimizing state.

The following procedure extends an 8 GB ext4 file system to get full use of a 16 GB volume. The file system is on an Amazon Elastic Compute Cloud (Amazon EC2) instance running Ubuntu.

1.    Create a snapshot of your volume before changing your volume or file system. For more information, see Create Amazon EBS Snapshots.

2.    Use the df -h command to show the size and the percentage used by the file system.

ubuntu@ip-172-31-32-114:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.7G  7.7G     0 100% /
/dev/xvdf       7.9G  7.1G  370M  96% /home/ubuntu/test

In this example, the /dev/xvdf/ file system size is 7.9G and is 96% full.

3.    Use the lsblk command to show the size of the xvdf volume.

ubuntu@ip-172-31-32-114:~$ lsblk
xvda    202:0    0    8G  0 disk
└─xvda1 202:1    0    8G  0 part /
xvdf    202:80   0   16G  0 disk /home/ubuntu/test

In this example, the size of the xvdf volume is 16G.

4.    Connect to your instance using SSH. For more information, see Connect to your Linux instance.

5.    If the volume has a partition containing a file system, that partition must be resized before the file system is expanded.

6.    Use the resize2fs command to automatically extend the size of the /dev/xvdf/ file system to the full space on the volume.

ubuntu@ip-172-31-32-114:~$ sudo resize2fs /dev/xvdf

Note: In this example, the volume is using an ext4 file system. Depending on your file system, you might need to use a different utility. For more information, see Extend a Linux file system after resizing a volume.

7.    Rerun the df –h command.

ubuntu@ip-172-31-32-114:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.7G  7.7G     0 100% /
/dev/xvdf        16G  7.1G  8.0G  48% /home/ubuntu/test

The /dev/xvdf/ file system is now 16G in size and only 48% full.

Related information

View information about an Amazon EBS volume

Make an Amazon EBS volume available for use on Linux

Extend a Windows file system after resizing a volume

AWS OFFICIALUpdated 3 years ago