Your browser (Internet Explorer 7 or lower) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

X

Navigate / search

How to Attach EBS Volume to Amazon EC2 Instance

When I first started using EC2 (Elastic Compute Cloud) for hosting, it took me quite some time to find the information I needed to attach an EBS (Elastic Block Store) volume to an EC2 instance. For the purposes of this article, I am using Ubuntu 11.10 server 32bit, but the process is similar on other versions of Ubuntu and other Linux distributions.

Creating EBS Volumes

To create an EBS Volume using the AWS (Amazon Web Services) Management Console, select the EC2 tab, then select Volumes under the Elastic Block Store heading. Click on Create Volume to setup your EBS volume. Enter the size and zone. Snapshot is used to load a copy of a volume into a new one. To attach to EC2, the volume must be in the same availability zone as the EC2 instance.

Add new volume in EBS

Attach EBS Volume to EC2 Instance

The next step is to attach the new volume to an EC2 instance. On the instances page, make a note of the id located in the Instance column. Back on the EBS volumes page, select the new volume, then click on Attach Volume. Select the id of the EC2 instance and click on Attach. The volume has been added to the instance. The volume may need to be formatted after it has been attached to the instance and before being mounted to the local system.

Mounting an EBS Volume to EC2 Instance

Now, we need to mount the EBS volume to the EC2 instance. To make sure the volume is loaded on startup, we need to edit the fstab (file systems table) file in the etc folder. The fstab file stores a list of disks and disk partitions and their configuration options for mounting to the local file system. The screen shot below is from one of my web servers on EC2.

Editing the fstab file in Ubuntu

The bottom 3 lines are from EBS volumes attached to this EC2 instance. The first column is the path selected when attaching the volume to the instance. The second column is the location on the local file system to point to the mounted drive. In this case, I created a volume for the web files, apache log files, and database files on separate EBS volumes. The third column is the type of file system the volume was formatted with. Ext4 is an excellent choice for formatting EBS volumes. The next column specifies the configuration options when mounting the volume. The options used above have worked well for me. Set the last two columns to 0 for each volume you add to the instance.

To mount the volumes without having to restart the instance, type "sudo mount -a".

For more information, Wikipedia has an excellent article on fstab.

Post comments

Leave a comment