Table Of Contents

This process has been tested on multiple EC2 instances but I must state as always, you should make at least one back up and maybe a backup of your back up to be safe. This will run you through extending your root file system on a running EC2 instance with out any lengthy downtime. First you’ll want to get into your EC2 instance’s ssh portal using your AWS Key, I will not be covering how to do this in this article. Now we’ll run through each command inside of your SSH terminal to extend the file size… I’ve notated the step and what each one does. As every system is a little different place make sure that you’re using the correct values. I’ve filled in the values that you’d need to do this on our last system but make sure you use yours.

df -h
fdisk /dev/xvda1 // Replace this with your root drive
u // Changes fdisk to display units
p // write down the starting block
d // Deletes the partition
n // Creates a new partition
p // Tells the system that this will be a primary partition
1 // Tells the system that this will be partition #1
2048 // replace with your starting block ***Very important or your system will fail and you'll need to restore from a backup
w // Writes the changes we just made
reboot // reboots your system.


After your system reboots, you can run df -h again, and you’ll see that your volume is taking full advantage of the increase in space. This process is almost always needed on the centos ami as they tell they system to setup your instance using an 8G drive, and you’re more than likely using a much larger drive, so you’ll have to resize it. There are alternative ways to getting this done and Amazon even suggests that you use their snapshot tool, but I’ve found that it causes your system to be offline for too long, especially when this works when done correctly and only causes your system to go offline for as long as a reboot. Much better option in my opinion. I’d love to hear from you about the method that you use. Please let me know in the comments below!

    Leave a Reply

    Your email address will not be published. Required fields are marked *