Tuesday, December 11, 2012

Amazon EC2 - Mounting a EBS drive


This post applies to

  • mounting a new EBS volume
  • mounting an existing EBS volume or snapshot

Specs:
  • Ubuntu Server 12.04.1 LTS 64-bit
  • XFS

1.) Creating a EBS volume (skip this if you have a volume already)

  • Login to your Amazon EC2 Admin Console
  • In the left sidebar menu, expand Elastic Block Volume and click on Volumes
  • Click on Create Volume
  • Specify a size (Ex. 8 Gib)
  • Set Availability Zone to the region that your instance is in (Note that it is very important that the EBS and the instance are in the same region.)
  • Click "Yes, Create"
  • Wait till the console says the EBS is available (blue circle).


2.) Attaching a EBS volume to an instance



3.) Mounting the EBS volume

ssh into your instance  (ex. ssh -i {key} {user}@{ec2_address})


sudo apt-get update && sudo apt-get upgrade -y


Check if the drive is available by
sudo fdisk -l
Sample output:
Disk /dev/xvdf: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 
Disk /dev/xvdf doesn't contain a valid partition table
Install xfs tools.
sudo apt-get install -y xfsprogs xfs
sudo mkfs.xfs /dev/xvdf 
Add the new volume to the file system configuration file.
sudo vi /etc/fstab
Add the following to the end of the file.
/dev/xvdf /vol xfs noatime 0 0
Save the file.

/vol is the mount point for the partition /dev/xvdf.

Note that xvd[f-p] are partitions for EBS. You can choose which letter to use when creating the EBS in the EC2 admin console.


sudo mkdir -m 000 /vol

sudo mount /vol

cd into /vol to see if it's accessible.

2 comments:

  1. I'm having a hard time, with mongodb and ec2. I mounted a volume using your tutorial but how do I associate mongodb datafiles to the mounted volume once it's mounted?

    ReplyDelete
    Replies
    1. Hi Magbic, I haven't used mongo before. But I would assume you need to change paths in the Mongo config file (it's may be in /etc/mongo/conf) to point to the new mount volume. According to http://docs.mongodb.org/manual/reference/configuration-options/, you need to set dbpath to the new volume.

      Delete