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.
3 Answers
Amazon details the process of attaching EBS volumes, quite well in their documentation
Via the console:
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- Click Volumes in the Navigation pane.
- The console displays a list of current volumes.
- Select a volume and click Attach Volume.
- The Attach Volume dialog box appears.
- 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).
- Select how the device is exposed to the instance from the Device list box.
- 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
.
-
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
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.
![](../../users/profiles/55728.webp)
- 1,063
- 8
- 12
-
-
There are lots of tutorials on the internet for this. For example, try checking this: http://www.coderchris.com/linux/how-to-mount-an-amazon-ebs-disk-as-a-drive-in-linux-centos/2011/01/31 – Shyam Sundar C S May 03 '12 at 17:31
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.
![](../../users/profiles/108448.webp)
- 646
- 4
- 10