DEV Community

Cover image for How to extend an EBS volume in AWS and then grow EFS Filesystem
Md Mohaymenul Islam (Noyon)
Md Mohaymenul Islam (Noyon)

Posted on • Edited on

How to extend an EBS volume in AWS and then grow EFS Filesystem

Here are the steps to extend an EBS volume in AWS and then to grow the filesystem on it:

1) Increase the EBS volume size in AWS:

  • Open the EC2 console on AWS.
  • On the left-hand side menu, navigate to 'Volumes' under 'Elastic Block Store'.
  • Identify the volume connected to your instance, right-click on it and select 'Modify Volume'.
  • Specify the new desired volume size and then select 'Modify'. The state of the volume will change to 'Optimizing' after a short while, this indicates that the size alteration has been recognized by AWS.

Note: The process can be executed while your instance is still running, but it's advisable to take a snapshot before making changes to avoid any data loss.

2) Rescan the disk on your EC2 instance:

To ensure that your EC2 instance identifies the new disk size, connect via SSH and execute the command:

sudo lsblk
Enter fullscreen mode Exit fullscreen mode

The output should reveal that the disk size has increased, but the partition size hasn't.

3) Grow the partition to use the new space:

If the partition does not reflect the new size, you will need to expand it. Run the following command to do this:

sudo growpart /dev/xvda 1
Enter fullscreen mode Exit fullscreen mode

In the command above, /dev/xvda is the disk, and 1 is the partition number.

4) Resize the filesystem:

Following the partition extension, resize the filesystem with the following command (assuming the filesystem is XFS):

sudo xfs_growfs /dev/xvda1
Enter fullscreen mode Exit fullscreen mode

The command may vary based on the filesystem. For instance, if the filesystem is EXT, you'd use resize2fs instead of xfs_growfs. If you're unsure of the filesystem, use sudo file -s /dev/xvda1 to find out.

IMPORTANT: Always ensure you have a solid backup of your data before running these operations. Misusing these commands can lead to data loss.

5) Verify the changes:

Finally, verify that your filesystem is using the new space by running the df -h command:

df -h
Enter fullscreen mode Exit fullscreen mode

You should now see that the size of the filesystem matches the size of the EBS volume you set in AWS.

Remember, these steps are specific to an AWS EC2 instance using an EBS volume with an XFS filesystem. If your setup is different, the steps may vary.

Top comments (0)