Increasing Root Disk Size of an "EBS Boot" AMI on EC2

| 28 Comments

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.]

28 Comments

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

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:

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1 1 14 112423+ 83 Linux
/dev/xvda2 15 668 5253255 83 Linux
/dev/xvda3 669 1044 3020220 82 Linux swap / Solaris
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:

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1 20G 867M 18G 5% /

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.

Leave a comment

Ubuntu AMIs

Ubuntu AMIs for EC2:


More Entries

Replacing a CloudFront Distribution to "Invalidate" All Objects
I was chatting with Kevin Boyd (aka Beryllium) on the ##aws Freenode IRC channel about the challenge of invalidating a…
Email Alerts for AWS Billing Alarms
using CloudWatch and SNS to send yourself email messages when AWS costs accrue past limits you define The Amazon documentation…
Cost of Transitioning S3 Objects to Glacier
how I was surprised by a large AWS charge and how to calculate the break-even point Glacier Archival of S3…
Running Ubuntu on Amazon EC2 in Sydney, Australia
Amazon has announced a new AWS region in Sydney, Australia with the name ap-southeast-2. The official Ubuntu AMI lookup pages…
Save Money by Giving Away Unused Heavy Utilization Reserved Instances
You may be able to save on future EC2 expenses by selling an unused Reserved Instance for less than its…
Installing AWS Command Line Tools from Amazon Downloads
When you need an AWS command line toolset not provided by Ubuntu packages, you can download the tools directly from…
Convert Running EC2 Instance to EBS-Optimized Instance with Provisioned IOPS EBS Volumes
Amazon just announced two related features for getting super-fast, consistent performance with EBS volumes: (1) Provisioned IOPS EBS volumes, and…
Which EC2 Availability Zone is Affected by an Outage?
Did you know that Amazon includes status messages about the health of availability zones in the output of the ec2-describe-availability-zones…
Installing AWS Command Line Tools Using Ubuntu Packages
Here are the steps for installing the AWS command line tools that are currently available as Ubuntu packages. These include:…
Ubuntu Developer Summit, May 2012 (Oakland)
I will be attending the Ubuntu Developer Summit (UDS) next week in Oakland, CA.  This event brings people from around…
Uploading Known ssh Host Key in EC2 user-data Script
The ssh protocol uses two different keys to keep you secure: The user ssh key is the one we normally…
Seeding Torrents with Amazon S3 and s3cmd on Ubuntu
Amazon Web Services is such a huge, complex service with so many products and features that sometimes very simple but…
CloudCamp
There are a number of CloudCamp events coming up in cities around the world. These are free events, organized around…
Use the Same Architecture (64-bit) on All EC2 Instance Types
A few hours ago, Amazon AWS announced that all EC2 instance types can now run 64-bit AMIs. Though t1.micro, m1.small,…
ec2-consistent-snapshot on GitHub and v0.43 Released
The source for ec2-conssitent-snapshot has historically been available here: ec2-consistent-snapshot on Launchpad.net using Bazaar For your convenience, it is now…
You Should Use EBS Boot Instances on Amazon EC2
EBS boot vs. instance-store If you are just getting started with Amazon EC2, then use EBS boot instances and stop…
Retrieve Public ssh Key From EC2
A serverfault poster had a problem that I thought was a cool challenge. I had so much fun coming up…
Running EC2 Instances on a Recurring Schedule with Auto Scaling
Do you want to run short jobs on Amazon EC2 on a recurring schedule, but don’t want to pay for…
AWS Virtual MFA and the Google Authenticator for Android
Amazon just announced that the AWS MFA (multi-factor authentication) now supports virtual or software MFA devices in addition to the…
Updated EBS boot AMIs for Ubuntu 8.04 Hardy on Amazon EC2 (2011-10-06)
Canonical has released updated instance-store AMIs for Ubuntu 8.04 LTS Hardy on Amazon EC2. Read Ben Howard’s announcement on the…