3

I already have a ec2 instance running ubuntu on a micro instance. The hard drive is only 7gb. I am shutting down an old server and migrating it to this one. The old server has 15gb of data I need to transfer to the ec2 instance. How can I either a) increase the size of the root ebs drive or b) (the preferred method) add ANOTHER ebs drive so I can transfer the files over and later delete if i need to.

LordZardeck
  • 181
  • 2
  • 9

3 Answers3

8

Amazon details the process of attaching EBS volumes, quite well in their documentation

Via the console:

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. Click Volumes in the Navigation pane.
  3. The console displays a list of current volumes.
  4. Select a volume and click Attach Volume.
  5. The Attach Volume dialog box appears.
  6. Select the instance to attach the volume to from the Instance list box (only instances in the same Availability Zone as the volume are displayed).
  7. Select how the device is exposed to the instance from the Device list box.
  8. Click Attach.

Via the command line:

ec2-attach-volume volume_id -i instance_id -d device

You can't resize an EBS volume live - the process entails creating a snapshot, and making a new, larger volume from that snapshot.

To resize a root EBS volume:

  • Stop the instance (not strictly required, but helps with consistency)
  • Take a snapshot of the EBS volume (e.g. ec2-create-snapshot vol-XXXXXXXX)
  • Create a new (larger) volume from the snapshot (e.g. ec2-create-volume --availability-zone XX-XXXX-XX --size XX --snapshot snap-XXXXXXXX)
  • Attach the new volume to an instance (e.g. ec2-attach-volume vol-XXXXXXXX -i i-XXXXXXXX -d /dev/sdXX)
  • check the volume (optional - e.g. e2fsck -f /dev/xvdXX)
  • resize the filesytem (e.g. e.g. resize2fs -p /dev/xvdXX)
  • check the filesystem again (optional)
  • tune the filesystem (optional - e.g. tune2fs -l /dev/xvdXX)
  • detach the EBS volume from the instance (e.g. ec2-detach-volume vol-XXXXXXXX)
  • detach the original root volume from your original instance, and attach the new volume
  • start your original instance and stop the extra one you started

Additionally, it is worth mentioning that /dev/sdXX is a symlink to /dev/xvdXX in recent versions of Linux. Many commands need to be run on /dev/xvdXX even though you tell EC2 to attach to /dev/sdXX.

Also keep in mind that you must pass your private key and certificate to almost all EC2 API commands, or alternatively, you can set (export) the EC2_PRIVATE_KEY and EC2_CERT environment variables so that you don't have to pass these values to every command.

The root volume will be automatically mounted (provided that you have it attached as the same device as the previous root volume). Other, additional EBS volumes that you attach are only made available as devices - they are not automatically mounted. You can get a list of the attached 'volumes' using cat /proc/partitions (as per this answer). To mount your volume, just run mount /dev/xvdXX /path/to/mountpoint.

cyberx86
  • 20,620
  • 1
  • 60
  • 80
  • I looked everywhere for something like "Volume", but I didn't see it till you said that. Thanks for the detailed explanation. Does that automatically mount it when it attaches? – LordZardeck May 03 '12 at 17:45
  • No, you must still mount the volume - it simply attaches it to the instance and makes it available as a device. – cyberx86 May 03 '12 at 17:46
0

Increasing the size of root EBS drive is quite complicated and involves quite a bit of work.

The easier way is to add another EBS volume of desired size, mount and symlink.

Shyam Sundar C S
  • 1,063
  • 8
  • 12
0

The easiest way to do this is to create another EBS volume of the desired size in the web interface and then attach it to the running instance with the old data. Then you can format the new drive, mount it and copy over the files.

Lars Kotthoff
  • 646
  • 4
  • 10