Mounting EBS volume to an AWS EC2 Instance of Ubuntu 12.04 (reposted from Yetihq.com)

posted in: Uncategorized | 0

Are you looking to create a cloud-based solution for your website or database backend? One approach to create a cloud-based solution is to use Amazon’s AWS, which is a popular platform today. AWS is a suite of many platform software products including EC2. EC2 provides virtual instances of computer servers, which places the same function as running several desktop computers inside one’s office and connecting them to the Internet.

A popular solution for running a computer server is to run the Ubuntu 12.04 64-bit operating system. Ubuntu is an alternative to Mac OS X and Windows, which are primarily consumer-facing desktop operating systems. Ubuntu comes in two versions, one for desktop computers similar to the others and another server version without the GUI. Ubuntu’s selling points are an open source codebase, strong community support, and GUI-less server operation.

Amazon EC2 can run several operating systems include Ubuntu 12.04. Amazon’s regular EC2 servers provide the same environment as a regular server, but changes in EC2 aren’t saved when the server is terminated. In other words, when the server is shut down, data changes are lost. EC2, thus, cannot be used for running data-centric applications out of the box.

Amazon introduced another product, S3, to provide persistent data storage. It provides RESTful access to data, which cannot be accessed like a regular server: special libraries are required. Amazon later introduced Elastic Block Store (EBS), which is a “virtual hard drive” (volume) for saving persistent data. EBS is accessed like a regular file system in Ubuntu.

Amazon’s control panel for EC2 allows you to setup Ubuntu 12.04 with EBS. Amazon’s control panel, however, does not format or mount the EBS volume.

Here are steps to mount a EBS volume on an AWS EC2 copy of Ubuntu 12.04:

1. Create an EBS Volume and attach it to the EC2 instance in EC2 panel management (in the AWS portal). Note the EBS volume name (e.g.,sdb).

2. Login to the EC2 instance using ssh.

3. Confirm that the EBS volume is attached:

You should see two (or more) disks listed:/dev/xvda1 and /dev/xvdb. Note that the EBS volume name (sdb) is listed as xvdb because Ubuntu 12.04 differentiates between real and virtual drives.

4. The new disk isn’t formatted. You format the disk with the following:

You should see output such as:

5. Edit /etc/fstab, e.g., using

Add in the line to mount the new drive to /var:

6. Log out of ssh and reboot the instance from EC2 panel management (website).

7. After the server has rebooted in EC2 panel management, log back in to ssh.

8. Confirm that/dev/xvdb is mounted by typing in:

For example:

This article was written based on instructions for Ubuntu 10.10.