Rorcraft Blog

Quick guide to Amazon EBS

We’ve switched to use Amazon EBS for a few months now. Therefore, we have been able to have a good night’s sleep without worrying our database disappearing. Here’s a quick guide.


It’s very easy to use EBS for EC2. First make sure you downloaded the latest ec2-api-tools (you can’t find EBS related tools in its old version). Here’s my ec2-api-tools info (yours don’t need to be exactly same with me):



—- ruby $ ec2ver
1.3-24159 2008-05-05
—-

EC2 instance can only use EBS in the same avaliablity zone with it, so we need to check the availability zone in which your ec2 instances are.  You can do this by



$ ec2din



INSTANCE    i-abc12345    ami-abc12345    ec2-…compute-1.amazonaws.com    ip-….ec2.internal    running        0        m1.small    2008-06-23T23:12:26+0000    us-east-1b



So the instance is in us-east-1b. Now create a 200G storage block in this zone:



—- ruby$ ec2-create-volume —size 200 -z  us-east-1b
VOLUME vol-4d826724 200 creating 2008-10-14T00:00:00+0000

1
2
3
4
5
6

You can check the block by<br />
<br />

--- ruby$ ec2-describe-volumes vol-4d826724
VOLUME vol-4d826724 200 available 2008-10-14T00:00:00+0000

The block now is created. It’s like we have bought a 200G harddisk from amazon, now let’s install it on our ec2 instance:


—- ruby$ ec2-attach-volume vol-4d826724 -i i-6058a509 -d /dev/sdh
ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh attaching 2008-10-14T00:15:00+0000

1
2
3
4
5
6
7
8

This will let the system on ec2 instance recognize our new block storage on /dev/sdh (you can specify any device name that not the same with currently used, like /dev/sdz). Now you can use this device (/dev/sdh) as a normal block device like other real disk partitions(such as /dev/sda). For example,<br />
<br />

--- ruby$ mkreiserfs /dev/sdh #this will format it with reiserfs
$ mkdir /mnt/data
$ mount /dev/sdh /mnt/data #mount the block to /mnt/data, now all data write to /mnt/data dir will be 
# persistent on the block storage vol-4d826724. it won't lost after you reboot the machine

Some other useful tools are:



ec2-describe-volumes: used to find the relationships between your blocks and instances

ec2-detach-volume: detach a block from instance



Here’s a full manual of EBS.

Contact

We love to hear about your web projects.
Email:
Sydney: +61 421 591 943
Hong Kong:+852 6901 2682

Categories