Need more storage for your EC2 instance but worried it might stop working during the upgrade? The good news is that increasing your storage won’t cause any downtime!
The only catch here is that you can’t accomplish this purely through the AWS console; it calls for a few extra steps. However, rest assured, these additional steps shouldn’t be too complicated.
目次
Take a snapshot of EBS Volume (Optional)
While this step is optional, it is always recommended to take a backup if the volume upgrade doesn’t go as planned. Feel free to skip this step if you deem it unnecessary.
On AWS console, go to volumes page and select your volume. In my case, I have an 8 GiB EBS storage volume. Click on ‘Actions,’ and from the dropdown menu, select ‘Create snapshot.
Provide a description for your snapshot, and then click the ‘Create snapshot’ button.
You should now be able to view your newly created snapshot.
Expanding an EBS Volume Using the AWS Console
In the AWS console, go to the ‘Volumes’ section and choose the volume you wish to adjust. Next, click on ‘Modify volume’ from the ‘Actions’ dropdown menu.
Adjust the Size (GiB) to your desired value – for instance, let’s set it to 16 in this case. Once you’ve made the adjustment, go ahead and click ‘Modify.’
Note:
- Downgrading your volume is not possible.
- The minimum volume size allowed is 8 GiB.
There will be a pop-up notification prompting you to extend the file system, which is the next step we’ll be covering. Feel free to read through the information and then click ‘Modify’ to proceed.
The volume modification process will take some time. Importantly, there will be no downtime throughout this process, meaning your EC2 instance will remain running.
Once your volume state is “In-use” or have been completely modified, go ahead and proceed to the next steps.
Expanding a Linux File System After Resizing a Volume
Access your instance via SSH or use EC2 Instance Connect to run the following commands.
First lets’s check our current file system situation.
1 |
df -hT |
We have increased the volume size to 16 GiB but it still displaying as 8 GiB.
Next, let’s verify whether the volume has a partition.
1 |
sudo lsblk |
We currently have a single 16 GiB disk with one partition of 8 GiB instead of 16 GiB, which isn’t the output we wanted. To resolve this, we’ll need to extend partition number 1.
Pay attention to the partition naming since they required different commands to be executed. In this case, we have xvda which is Xen-based. If yours looks something like nvme0n1 , use the Nitro-based command.
Now, execute the following command to extend the partition.
For Xen-based:
1 |
sudo growpart /dev/xvda 1 |
For Nitro-based:
1 |
sudo growpart /dev/nvme0n1 1 |
The output should look like the following.
Next, let’s check our partition again
1 |
sudo lsblk |
Great, the partition 1 size has been upgraded to 16 GiB.
Now, let’s check our volume again.
1 |
df -hT |
Despite extending the partition, the size still displays as 8 GiB. Not to worry, let’s take note of our file system type, which in this case is xfs , and proceed to the next step.
After checking whether your file system type is xfs or ext4 , run the following command according to your file system type to extend the file system mounted on /.
For XFS file system:
1 |
sudo xfs_growfs -d / |
For Ext4 file system Xen-based:
1 |
sudo resize2fs /dev/xvda1 |
For Ext4 file system Nitro-based:
1 |
sudo resize2fs /dev/nvme0n1p1 |
The output should looks like this.
Lastly, let’s verify our extended file system.
1 |
df -hT |
Now the file system of EBS Volume has been extended correctly.
If you encounter unexpected issues or the process doesn’t go as planned, you can refer to AWS documentation on extending Linux file system for troubleshooting guidance.
AWS Documentation : Extend a Linux file system after resizing a volume
Conclusion
Although expanding an EBS volume on EC2 instances can’t be done entirely through the AWS console, extending the file system is straightforward, and there’s no downtime. If you’re unsure, you can always refer to the easy-to-follow AWS documentation.
- Simple AWS DeepRacer Reward Function Using Waypoints - 2023-12-19
- Restrict S3 Bucket Access from Specified Resource - 2023-12-16
- Expand Amazon EBS Volume on EC2 Instance without Downtime - 2023-09-28
- Monitor OpenSearch Status On EC2 with CloudWatch Alarm - 2023-07-02
- Tokyo’s Coworking Space Hidden Gem: AWS Startup Loft Tokyo - 2023-05-24