Skip to main content

Resizing Root Partition on Linux in Amazon EC2

Posted on May 7, 2012 by Anthony James Founder/CEOAnthony James Founder/CEO

Changing the partition size for a root partition or any other partition is just a little bit different when you’re working in the cloud. Today I’m going to show you how to change the root partition of an EC2 instance running Linux.
Resizing the root partition on an Amazon EC2 instance starts by stopping your instance.

First, go to volumes on the left-hand EC2 navigation control panel. Once you’re there, look under attachment information and identify the volume that is attached to the instance on which you want to change the root partition.
Right-click on the volume you want to resize and select Create Snapshot.
Fill out the details of the snapshot you’re creating. This will help you identify it in your snapshot inventory.

Select Snapshots on the left hand side of the EC2 control panel. From here you can see your snapshot being created. Make sure you remember what availability zone your running instance/server is in; what you do next will require that information
Right hand click on the snapshot you just created and select Create Volume from Snapshot.

Enter the new size you would like the partition to be, select the same availability zone of your running instance then click on yes, create.
Head back over to volumes in the EC2 control panel. Once there, select the root volume we just created an image of, right click on it, and select detach volume. We are doing this because now that we created a new 10gig volume, we are going to attach that new volume in place of the old volume.
Now right click on the new volume we created.
Attach the volume

It’s important to make sure the volume is attached as /dev/sda1, so change the volume name. If you do not do this, your instance will NOT be able to turn back on.
As soon as the volume is attached, go back to your instances and turn your instance back on.
Login to your instance and run df -m as sudo or root. You’ll notice that your partition size is still the same even though we created a larger volume. Now we need to resize the partition inside of Linux.
Make note of the partition name; in our case it’s /dev/xvda1. Now type resize2fs /dev/xvda1 at the command line.

Now it starts to resize the root partition…

Once complete, type df -m to view the new root partition size and verify that it worked.

We see that /dev/xvda1 is now 10gig vs 1gig.
All Done!


Image of Jerry
8 years ago

Nicely done! This is a great write-up to resize an EC2 root partition. You made it so simple. Your instructions worked perfectly. Thanks a lot!

Image of Roberto
7 years ago

Thanks man, this was helpful!

Image of Raga Kuswardhono
Raga Kuswardhono
4 years ago

Thank you, it’s working on mine, nice instructions.

Image of chris
4 years ago

Well, I am struck with creating a root volume is 1000 GB , when I create a volume from the snapshot it is not getting reduced than 1000.

Image of Ramil Menzeleev
Ramil Menzeleev
4 years ago

Great job! It is significantly more simple than AWS instructions and it works. Thank you!

Image of Radek Bokuvka
Radek Bokuvka
3 years ago

Well done! Straightforward and easy to follow instructions.

Image of kumaran
3 years ago

Like for any /home and /var and /var/log Do we need to stop instance? Or on the fly is it possible?

Image of umesh
2 years ago

Great , worked

Image of robert
2 years ago

this worked great thanks.
It even was not necessary to resize the filesystem
seems to have been done automatically

Image of Mauricio
2 years ago

Nice it worked.
However, on GP2 (SSD), there were two points to be added:
1. When attaching the new volume, I had to name /dev/xvda
2. There was no need to run resize2fs, it got the new size right after boot (it’s Amazon-linux).
When I ran it said:
resize2fs /dev/xvda1
resize2fs 1.42.12 (29-Aug-2014)
The filesystem is already 3931643 (4k) blocks long. Nothing to do!
Thanks for the awesome tutorial

Leave a Reply

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