Amazon EBS – How to Grow the Storage | Edoceo's Blog

Amazon EBS – How to Grow the Storage

Seen loads of good posts about EBS describing how to use them to provide cross instance persistent storage. Really it’s awesome. All the EC2 images store to their own EBS and if the EC2 crashes a new one can be resumed with minimal downtime. Amazon has nice pictures about this use case.

Quite simple to increase the size of an EBS volume, just: create, attach, mount, write, umount, snapshot, create, attach, check, resize, check, mount, delete. We’re going to walk through the process using Amazon EC2 command line tools.

Create the initial volume and attach to an EC2 instance.

$ ec2-create-volume --size 1 --availability-zone us-east-1a
$ ec2-attach-volume vol-3b0eea52 -i i-7b648e12 -d /dev/sdx1

The device name can be anything you want, we’ve used /dev/sdx, /dev/sdVolume, /dev/sdebs1. There doesn’t appear to be any restrictions on this file name or location. We currently use the convention of /dev/ebs#

In the EC2 image make a file system on this volume then mount and populate.

# mke2fs -j -L'EBS_Test' /dev/sdx1
# mount /dev/sdx1 /mnt/ebs1
# for f in /etc /opt /var/www; do rdiff-backup $f /mnt/ebs1/$f; done

Actually Resizing

Super easy, minimal downtime. Here’s the precautious way to do it. Unmount the EBS, create snapshot of EBS. Create new Volume with Snapshot at new size, resizefs, mount.

# (ec2-host) umount /dev/sdx1
$ ec2-create-snapshot vol-3b0eea52
$ ec3-describe-snapshots
$ ec2-create-volume  --availability-zone us-east-1a --size 2 --snapshot snap-b954bbd0
$ ec2-describe-volumes
$ ec2-attach-volume vol-360eea5f -i i-7b648e12 -d /dev/sdx2
# (ec2-host) e2fsck -f /dev/sdx2
# (ec2-host) resize2fs -p /dev/sdx2
# (ec2-host) e2fsck -f /dev/sdx2
# (ec2-host) tune2fs -l /dev/sdx2
# (ec2-host) mount /dev/sdx2 /mnt/ebs2

Once you’re sure the EBS has re-mounted and is clean with all your data you can then go back and delete the original volume.

$ ec2-describe-volumes
$ ec2-detach-volume vol-3b0eea52
$ ec2-delete-volume vol-3b0eea52


Create the volume has you see fit with a reasonable size. Fill with data then when space runs out plan on some short down time. Then snapshot, re-create, resize and re-mount. Adjustments need to be made for different file system types.

  • http://www.blogger.com/profile/13528237414516132237 harish ganesan

    Thanks edoceo for the article. I have written a detailed blog on Amazon EBS .Thought it might be useful for your blog readers.

    URL : http://harish11g.blogspot.in/2013/05/understanding-Amazon-Elastic-Block-Store-EBS-in-detail.html

  • Anonymous

    It’s never correct English to say “Seen” without “have” in front of it.

    Just so you know… it’s NEVER correct.

    There’s an implied I in front of it and “I seen” is always wrong. Always. “I HAVE seen” or “I saw.”

    Thank you for your post, but try not to abuse the English language.

  • Anonymous

    I want to increase the size of my system drive. Which steps would I need to change/add?

  • http://www.blogger.com/profile/14272497941329601460 Mr.Franc

    After step e2fsck -f /dev/sdx2
    I have this message:

    e2fsck 1.41.4 (27-Jan-2009)
    e2fsck: Superblock invalid, trying backup blocks…
    e2fsck: Bad magic number in super-block while trying to open /dev/sdg

    The superblock could not be read or does not describe a correct ext2
    filesystem. If the device is valid and it really contains an ext2
    filesystem (and not swap or ufs or something else), then the superblock
    is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193

    after e2fsck -b 8193 , the same message.

  • http://www.blogger.com/profile/00556151416922584710 Spandex

    This page is indeed massively useful. Used it several times and saved it in case it ever disappears! Thanks.

    Slight addition: I have to use fdisk to make the partition larger, otherwise my resize2fs reports that it’s already max size.

    1) create volume from snapshot
    2) attach it
    3) partition table still telling it to use smaller size so I fdisk it and delete + recreate partition at max size.
    4) THEN do resize2fs.

  • http://www.blogger.com/profile/07034283384400157169 Jean-Paul

    Two notes

    1. When creating the snapshot, you use the volume initially created to backup the data. Shouldn’t that be the volume attached to the ebs bootable image?

    2. there’s one ec3-describe-snapshots command that should be ec2-describe-snapshots

  • Anonymous

    Thank you, this saved a ton of time!

  • http://www.blogger.com/profile/05792512639005368356 David Mail

    Thank you, it was useful.
    I looked how to resize the file system after creating a new larger volume from a snapshot. resize2fs did the trick on my Fedora 8 instance