Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save senthilsweb/eccf9177bad861cd3341a7065c89907e to your computer and use it in GitHub Desktop.
Save senthilsweb/eccf9177bad861cd3341a7065c89907e to your computer and use it in GitHub Desktop.
How to Resize and Extend an EBS Volume on AWS EC2 Running Amazon Linux

Title: How to Resize and Extend an EBS Volume on AWS EC2 Running Amazon Linux

Introduction: Expanding the storage space of an Amazon EC2 instance is a common task that many users encounter. AWS allows you to increase the size of Elastic Block Store (EBS) volumes on-the-fly, which is incredibly useful when you run out of disk space. However, resizing the volume through the AWS Management Console isn't the final step – you also need to extend the file system within your EC2 instance to make use of the new space. This article will guide you through the process using Amazon Linux.

Step 1: Increase EBS Volume Size through AWS Management Console Before we dive into the command-line steps, the resizing process begins in the AWS Management Console. Here's what you need to do:

  • Navigate to the EC2 Dashboard.
  • In the "Volumes" section, select the volume you want to resize.
  • Choose the "Modify Volume" option.
  • Set the new size for your volume and apply the changes.
  • AWS will then provision the additional space, which can take a few minutes.

Step 2: Connect to Your EC2 Instance Once AWS confirms that the volume has been resized, connect to your EC2 instance using SSH:

ssh -i /path/to/your/key.pem ec2-user@your-instance-ip

Step 3: Verify the New Volume Size After logging in, verify that the operating system recognizes the new volume size:

lsblk

You should see the new size reflected under the SIZE column for xvda, but not for xvda1.

Step 4: Install the growpart Tool Amazon Linux might already have growpart installed. If not, you can install it with:

sudo yum install cloud-utils-growpart -y

Step 5: Extend the Partition With growpart, extend the xvda1 partition to occupy all the new space:

sudo growpart /dev/xvda 1

Step 6: Resize the File System Finally, use xfs_growfs to resize the file system. This command is specific to XFS, which is the default file system on Amazon Linux:

sudo xfs_growfs -d /

Step 7: Confirm the New File System Size Confirm the file system now uses the full volume:

df -h

Conclusion: If you've followed the steps above, your Amazon Linux EC2 instance should now reflect the new EBS volume size. You've not only increased the volume through the AWS Console but also extended the Linux file system to utilize the additional space. This process ensures that your EC2 instance has room to grow and supports your applications' needs.

Remember to monitor your disk usage and perform these steps again when needed. Happy computing!


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment