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

3 minute read
0

I increased the size of my Amazon Elastic Block Store (Amazon EBS) volume, but my file systems don't use the full volume.

Resolution

When you expand a volume to a larger size, you must resize the file system to take advantage of the larger volume size. You can resize a file system as soon as it's in the optimizing state.

Note: The following steps are applicable only to filesystems that use the entire disk device. You can't use these steps to increase filesystems on partitions, the root filesystem, RAID devices, or Logical Volume Manager (LVM).

The following example extends an 8 GB ext4 file system to fully use a 16 GB volume. The file system is on an Amazon Elastic Compute Cloud (Amazon EC2) instance.

1.    Before you change your volume or file system, create a snapshot of your volume. For more information, see Create Amazon EBS snapshots.

2.    Use SSH to connect to your instance. For more information, see Connect to your Linux instance.

3.    Run the df -h command to show the size and the percentage that the file systems uses.

Example output:

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 the preceding example output, the /dev/xvdf file system size is 7.9G and is 96% full. On Nitro instances, disk devices are named /dev/nvmeXn1 and partitions are named /dev/nvmeXn1pY. In the filesystem names, X identifies the disk and Y identifies the partition.

4.    Run the lsblk command to show the size of the xvdf volume.

Example output:

ubuntu@ip-172-31-32-114:~$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
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 the preceding example output, the size of the xvdf volume is 16G.

5.    If there's a partition in the volume that contains a file system, then resize that partition before you expand the file system.

6.    Run the resize2fs command to automatically extend the size of the /dev/xvdf file system to the full space on the volume. You must use the device name that you get from the df -h command.

Example output:

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

In the preceding example output, the volume uses an ext4 file system. Depending on your file system, you might need to use a different utility. If you receive an "resize2fs: Device or resource busy while trying to open /dev/xvdf" error, then you're applying the resize to a disk partition.

Note: You can run the resize2fs command only for ext3 and ext4 filesystems.

7.    Rerun the df -h command.

Example output:

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

In the preceding example output, the /dev/xvdf file system is now 16G in size and 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 OFFICIAL
AWS OFFICIALUpdated 5 months ago