This article is about running a new EC2 instance with a larger boot volume than the default. You can also resize a running EC2 instance.
Amazon EC2’s new EBS Boot feature not only provides persistent root disks for instances, but also supports root disks larger than the previous limit of 10GB under S3 based AMIs.
Since EBS boot AMIs are implemented by creating a snapshot, the AMI publisher controls the default size of the root disk through the size of the snapshot. There are a number of factors which go into deciding the default root disk size of an EBS boot AMI and some of them conflict.
On the one hand, you want to give users enough free space to run their applications, but on the other hand, you don’t want to increase the cost of running the instance too much. EBS volumes run $0.10 to $0.11 per GB per month depending on the region, or about $10/month for 100GB and $100/month for 1TB.
I suspect the answer to this problem might be for AMI publishers to provide a reasonable low default, perhaps 10GB as per the old standard or 15GB following in the footsteps of Amazon’s first EBS Boot AMIs. This would add $1.00 to $1.50 per month to running the instance which seems negligible for most purposes. Note: There are also IO charges and charges for EBS snapshots, but those are more affected by usage and less by the size of the original volume.
For applications where the EBS boot AMI’s default size is not sufficient, users can increase the root disk size at run time all the way up to 1 TB. Here’s a quick overview of how to do this.
Example
The following demonstrates how to run Amazon’s getting-started-with-ebs-boot AMI increasing the root disk from the default of 15GB up to 100GB.
Before we start, let’s check to see the default size of the root disk in the target AMI and what the device name is:
$ ec2-describe-images ami-b232d0db
IMAGE ami-b232d0db amazon/getting-started-with-ebs-boot amazon available public i386 machine aki-94c527fd ari-96c527ff ebs
BLOCKDEVICEMAPPING /dev/sda1 snap-a08912c9 15
We can see the EBS snapshot id snap-a08912c9 and the fact that it is 15 GB attached to /dev/sda1. If we start an instance of this AMI it will have a 15 GB EBS volume as the root disk and we won’t be able to change it once it’s running.
Now let’s run the EBS boot AMI, but we’ll override the default size, specifying 100 GB for the root disk device (/dev/sda1 as seen above):
ec2-run-instances --key KEYPAIR --block-device-mapping /dev/sda1=:100 ami-b232d0db
If we check the EBS volume mapped to the new instance we’ll see that it is 100GB, but when we ssh to the instance and check the root file system size we’ll notice that it is only showing 15 GB:
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 15G 1.6G 13G 12% /
There’s one step left. We need to resize the file system so that it fills up the entire 100 GB EBS volume. Here’s the magic command for ext3. In my early tests it took 2-3 minutes to run. [Update: For Ubuntu 11.04 and later, this step is performed automatically when the AMI is booted and you don’t need to run it manually.]
$ sudo resize2fs /dev/sda1
resize2fs 1.40.4 (31-Dec-2007)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 7
Performing an on-line resize of /dev/sda1 to 26214400 (4k) blocks.
The filesystem on /dev/sda1 is now 26214400 blocks long.
Finally, we can check to make sure that we’re running on a bigger file system:
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 99G 1.6G 92G 2% /
Note: The output reflects “99” instead of “100” because of slight differences in how df and EBS calculate “GB” (e.g., 1024 MB vs 1000 MB).
XFS
If it were possible to create an EBS boot AMI with an XFS root file system, then the resizing would be near instantaneous using commands like the following. [Update: For Ubuntu 11.04 and later, this step is performed automatically when the AMI is booted and you don’t need to run it manually.]
sudo apt-get update && sudo apt-get install -y xfsprogs
sudo xfs_growfs /
The Ubuntu kernels built for EC2 by Canonical have XFS support built in, so XFS based EBS boot AMIs might be possible. This would also allow for more consistent EBS snapshots.
Toolset
Make sure you are running the latest version of the ec2-run-instances command. The current version can be determined with the command
ec2-version
To use EBS boot features, the version should be at least 1.3-45772.
[Updated 2009-12-11: Switch instructions to default us-east-1 since all regions now support this feature.]
[Updated 2011-12-13: Note that file system resize is done automatically on boot in Ubuntu 11.04 and later.]



Follow Eric Hammond on Twitter
Eric,
I am following your instructions to resize the boot volume of an EBS AMI. However, when I run the command:
ec2-run-instances -k laptop2.priv -b /dev/sda1=:100 ami-b232d0db
I get the error
WARNING: Ignoring extra parameter(s): [ ami-b232d0db ]
Invalid argument for option '-b, --block-device-mapping MAPPING': '/dev/sda1' (-h for usage)
I am using API version 1.3-46266 2009-11-30
Erika
Erika: Based on the error message, it looks like you might have typed a space after "/dev/sda1" which does not belong there.
Eric,
There is no space after /dev/sda1 in the statement /dev/sda1=:100.
I am running command line tools version 1.3-46266 2009-11-30
Erika
Erik,
I found the answer to my problem at http://developer.amazonwebservices.com/connect/message.jspa?messageID=157133, in the last post.
This problem occurs when running EC2 commands from a Windows DOS shell. The solution is to put double quotation marks around /dev/sda1=:100, e.g. "/dev/sda1=:100" as described by TiNA
Erika
Erika: Glad you found the solution as I'm not the best person to ask about problems with Windows.
Eric,
I have launched a CentOS EBS instance of 30 GB from a EBS Image of 10GB. How do I extend the root volume to 30GB in CentOS ? resizefs is not present in CentOS package repository.
santhoshsd: I switched from Red Hat products to Ubuntu about five years ago. You might want to ask this question in a CentOS forum, and feel free to post the answer here. Just in case this is the cause: the command is "resize2fs" not "resizefs".
I tried to do what you mention in the article, creating an XFS-formatted root volume, and it works!
It's possible using the recent Canonical Ubuntu AMI and kernel. Here's my article showing how to do this and how it can be used together with your ec2-consistent-snapshot utility.
http://www.shlomoswidler.com/2010/01/creating-consistent-snapshots-of-live.html
Shlomo: Very nice, thanks! I'm a little concerned that if this were placed in a cron job, one might occasionally end up in a deadlock as the ec2-consistent-snapshot command tried to output messages which cron or syslog writes to a disk which is frozen by ec2-consistent-snapshot. I'm considering restructuring the message output so that they are buffered until the file system is unfrozen.
Is there also a way to reduce the size of an EBS volume? I would like to use the Ubuntu server images, but I really only need 2 GB (I use a separate volume for data).
You cannot run an instance with a smaller EBS boot disk than is specified by the AMI. You can, however, build your own EBS boot Ubuntu AMI with a smaller default EBS boot disk following a procedure similar to:
http://alestic.com/2010/01/ec2-ebs-boot-ubuntu
Can I use same procedure to reduce the 15GB Maverick AMI down to 10GB to fit the free EBS offer after 1st November?
Or is there a better way to have a 10GB Maverick server as EC2?
noiv11: No, you can't reduce the size of the boot disk less than the size of the AMI. If you'd like to have a smaller boot disk, you can build your own AMI starting with the downloadable images provided by Ubuntu:
http://uec-images.ubuntu.com/
See also: http://alestic.com/2010/01/ec2-ebs-boot-ubuntu
Is it possible to reduce the size of EBS? I've been using their "free tier" which include 10GB of storage free of charge only.
ezconceptmail: You cannot start a 15GB AMI with less than 15GB on your EBS root disk. Hopefully, you can afford the $0.50-$0.55 extra cost for now. Ubuntu is evaluating reducing EBS boot AMIs to 10GB:
https://bugs.launchpad.net/ubuntu-on-ec2/+bug/670161/
I couldn't get the instance to boot with a larger size when using its existing AMI, nor with another AMI created via the web gui (via the "create image (EBS AMI)" on the right-click menu of the instance). I noticed that the volume's "attachment information" would be stuck at "attaching" (instead of "attached"). The instance would boot if I didn't specify an increased size (via the "--block-device-mapping" option).
However, I did finally get it to work by manually creating a snapshot from the original volume, and then registering it as an AMI. Something is subtlely different here since I was able to successfully boot the instance with essentially the same cmd line as before (when it wasn't working).
This process either doesn't work or is out of date as of March 2011 with latest tools and Java. Doesn't seem to matter what AMI ID I use.
ec2-describe-images ami-b232d0db
IMAGE ami-b232d0db amazon/getting-started-with-ebs-boot amazon available public i386 machine aki-94c527fd ari-96c527ff
ec2-run-instances --key gsg-keypair --block-device-mapping /dev/sda1=:100 ami-b232d0db
Invalid argument for option '-B, --block-device-mapping MAPPING': '[Ljava.lang.String;@5eb7ec5d' (-h for usage)
AItOawk365XNhQqlsRLDEtmtukOoOZ6QinomWwU:
It still works for me, though I've seen others complain about that error as far back as 2009, so it's probably not a tools version issue.
You wouldn't happen to be using Windows would you?
Hi Eric,
I am running out of space in my existing ubuntu instance on EC2. Is there documentation on how to increase the size of the /dev/sda1 partition for an existing instance?
Thanks.
Azad
Azad:
Sure, I wrote about that here:
http://alestic.com/2010/02/ec2-resize-running-ebs-root
Thanks, your article saved me lots to time , everything worked very well with no problems. I just had to change my command line a bit and make sure my certificates were in place. This is what I used. (I have the default Amazon Linux set up)
ec2-run-instances --key ***** -g sg-****** --block-device-mapping /dev/sda1=:15 ami-******* -t t1.micro --instance-initiated-shutdown-behavior terminate
Also I found this page very helpful for setting up the tools: http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?SettingUp_CommandLine.html
Keep the good work up!
Regards Dave
Having problems trying to resize2fs/dev/xvda2 on an 8GB RightScale Debian Squeeze instance, I get the "Filesystem is already etc etc blocks long" message.
Thinking there might be nothing I can do apart from migrate over to an Ubuntu 11.10 instance? (Which would be a pain, I'm running a populated ISPConfig 3 installation).....
...and ideas?
Richard.
Richard:
Unfortunately, there's insufficient information in your question for a diagnosis. Perhaps the RightScale folks could help as they built the AMI and know if there is anything special about how it is built (partitions?) and what you are doing.
Panayotis:
It looks like RightScale built ami-0f01367b in eu-west-1 with a root EBS volume that is partitioned into three partitions:
This is not standard for EC2 EBS volumes as there is little benefit and there are a number of drawbacks.One of the drawbacks is that you can't easily resize the volume and the file system with this AMI. You'd have to repartition the EBS volume while the system is stopped by attaching the volume to a different instance, them move it back and restart the instance.
I would recommend using an AMI that has an EBS root volume without partitions.
Hi Eric. I've kept this page bookmarked since you first published it in 2009, and have directed a lot of "How do I resize my ec2 instance?" questions here.
Today I was playing around with creating a t1.micro instance and specified a non-standard (20GB) root disk. I expected to run: sudo resize2fs /dev/sda1
But a funny thing happen on the way to resizing:
It appears that the instance root disk was sized correctly upon creation, no? If this is now the standard behavior, you may want to update this blog entry. Or "refudiate" me in a reply to this post ;-)
jeffrubic:
Yep, you'll note that I already had an [Update] message just above the resize2fs instruction pointing out that the file system is automatically resized since Ubuntu 11.04.
Thanks for the useful posts, Eric.
For a generic Linux instance the resize2fs is still necessary although the new size of the drive can be specified at launch time using the EC2 mgmt console.
$ uname -a
Linux xx.amzn1.x86_64 #1 SMP Fri Aug 24 05:34:49 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.9G 6.7G 1.2G 86% /
tmpfs 298M 0 298M 0% /dev/shm
$ sudo resize2fs /dev/sda1
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/sda1 to 3932160 (4k) blocks.
The filesystem on /dev/sda1 is now 3932160 blocks long.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 15G 6.7G 8.0G 46% /
tmpfs 298M 0 298M 0% /dev/shm
mlemieux:
Thanks for your notes. There is no such thing as "generic Linux". It looks like your comments apply to "Amazon Linux", which is a Linux distro provided by AWS.