How to Expand an EBS Volume and Resize a Filesystem on AWS
TL;DR:
This tutorial will guide you through the process of expanding an EBS volume, resizing the partition, and extending the filesystem on an AWS instance running Debian-based Linux systems.
This tutorial will guide you through the process of expanding an EBS volume, resizing the partition, and extending the filesystem on an AWS instance running Debian-based Linux systems.
Prerequisites:
- You have an AWS EC2 instance running.
- The instance has an EBS volume attached, which you want to expand.
- You are comfortable using the command line and can SSH into your instance.
Steps Overview:
- Expand the EBS volume in AWS Console
- Verify the new disk size in the instance
- Resize the partition using
growpart - Resize the filesystem using
resize2fs
Step 1: Expand the EBS Volume in the AWS Console
- Log in to the AWS Management Console.
- Navigate to the EC2 Dashboard and click on Volumes under Elastic Block Store.
- Find the EBS volume attached to your instance (e.g.,
vol-xxxxxxx). - Click Actions and select Modify Volume.
- Change the Size to your desired new size (e.g., increase from 50GB to 100GB).
- Click Modify, and confirm the changes.
Note:
- The resizing can take a few minutes to complete, depending on the volume size.
- You do not need to stop your instance during this process, but it’s recommended to perform such operations during a maintenance window.
Step 2: Verify the New Disk Size on the EC2 Instance
- SSH into your EC2 instance:
ssh -i path-to-your-key.pem username@your-instance-ip
- Once logged in, run the following command to verify that the instance recognizes the new disk size:
lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 100G 0 disk ├─xvda1 202:1 0 50G 0 part / ├─xvda14 202:14 0 3M 0 part └─xvda15 202:15 0 124M 0 part /boot/efi
- In this example,
/dev/xvdanow shows 100GB, but the partition/dev/xvda1is still at 50GB.
Step 3: Resize the Partition Using growpart
- Install
cloud-guest-utilsif it's not already installed. This package contains thegrowparttool.
On Debian-based systems (like Debian, Ubuntu):
sudo apt-get update
sudo apt-get install cloud-guest-utils
- Use
growpartto resize the partition. In this case, we’re resizing partition 1 (/dev/xvda1):
sudo growpart /dev/xvda 1
Example output:
CHANGED: partition=1 start=262144 old: size=104857600 end=105119744 new: size=209715167 end=209717759
- Verify the change by running
lsblkagain:
lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 100G 0 disk ├─xvda1 202:1 0 99.9G 0 part / ├─xvda14 202:14 0 3M 0 part └─xvda15 202:15 0 124M 0 part /boot/efi
Now the partition has expanded to use the entire 100GB of space.
Step 4: Resize the Filesystem Using resize2fs
- Now that the partition is resized, you need to resize the filesystem to utilize the newly allocated space. You can do this while the filesystem is mounted:
sudo resize2fs /dev/xvda1
Example output:
resize2fs 1.46.2 (28-Feb-2021) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required The filesystem on /dev/xvda1 is now 26214400 (4k) blocks long.
- Verify that the filesystem has been expanded by running
df -h:
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 99G 60G 39G 61% /
You should now see that /dev/xvda1 has been resized to reflect the full 100GB size with available space.
Conclusion
You’ve successfully expanded your EBS volume, resized the partition, and extended the filesystem to utilize the new disk space—all while keeping your production server online.
Summary of Commands:
- Check disk layout:
lsblk
- Install
cloud-guest-utils(if needed):
sudo apt-get install cloud-guest-utils
- Resize the partition:
sudo growpart /dev/xvda 1
- Resize the filesystem:
sudo resize2fs /dev/xvda1
- Verify the new size:
df -h
Best Practices:
- Always take an EBS Snapshot before modifying disk partitions to protect your data.
- Perform this operation during low-traffic periods if possible.
- Monitor system logs during and after resizing to ensure everything works as expected.
Latest Comments
Sign in to add a commentNo comments yet. Be the first to comment!