cc by-sa flurdy

ec2 - Amazon Elastic Compute Cloud tips and howtos

EBS tips

This page is part of larger set of tips & howtos on ec2 by flurdy.
| More
Other ec2 docs by flurdy

What is Elastic Block Store, EBS?

Amazon ec2 instance work like a normal server with normal hard disks... Except when powered off (crashed) all data is lost!

So for the first two years of ec2 you had to make sure you wrote scripts to automatically backup your vital data to S3 (using perhaps s3sync).
And you had to calculate the cost of possible data loss between each time the backup ran.

But in 2008 Amazon launched EBS. EBS are in essence network disks, and you mount it directly or symlink to section of it. All data on ec2 instance's hard disk are still lost, but the data you care about are persisted on EBS disks.

It is still important to back up to S3 essential data or configuration which is not part of the AMI. EBS can also take snapshot of its volume, so that the data is saved to S3 and properly backed up.

What to NOT move to EBS

Instead of thinking what needs to be in an EBS, it is easier to think what does not need to be there first.
That way you eliminate a lot of over use of EBS.

What to move to EBS

Basically this is all data you do not have anywhere else and that you value.


What size EBS volume to use? Well I seem to select them too big, but its up to you.
You can always move data to a larger instance later, or even you use some undocumented resizing commands.

How to use EBS

I tend to put them into /mnt e.g:

sudo mkdir /mnt/home;
sudo mkdir /mnt/varlib;
sudo mkdir /mnt/varwww;
sudo mount /dev/sdf /mnt/home;
sudo mount /dev/sdg /mnt/varlib;
sudo mount /dev/sdh /mnt/varwww

Then symlink to wherever I need them.

sudo ln -s /mnt/home/username/bin /home/username/bin;
sudo ln -s /mnt/varlib/mysql/adatabasename /var/lib/adatabasename;
sudo ln -s /mnt/varwww/ /var/www/;
sudo ln -s /mnt/varwww/ /var/www/

But you may want to mount them directly or create a /data folder etc.

Note: Remember to check permissions on EBS files, as UID and GID don't always match between instances.
And to stop services beforehand and then start them afterwards...


When you reboot any mounts you have done will be forgotten, so better add your EBS volumes to the fstab:

sudo vi /etc/fstab

At the end append:

/dev/sdf     /mnt/home       ext3     noatime   0     0
/dev/sdg     /mnt/warwww     ext3     noatime   0     0
/dev/sdh     /mnt/warlib     ext3     noatime   0     0

Things to avoid

No home

Unless you really know your ec2 AMI scripting, do not ever mount/symlink /home or its direct subfolders to an EBS!

This is because your .ssh keys are then not accessible as EBSes may not yet be mounted if a newly launched instance or have faults, so you can not log into your own instance!

Instead keep .ssh keys on the AMI for your core admin users, and then either via backups persists the rest or not persisted at all.
Users files such as ~/bin ~/Documents etc can be symlinked instead.

Always test that you can log into AMIs immidietly after creating an AMI image.

back to flurdy's ec2 docs