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
- Right click on a EBS volume
- Click Attach Volume
- Select your instance (If you want to launch a new instance, check the post - Amazon EC2 - Launching Ubuntu Server 12.04.1 LTS step by step guide)
- If the volume says "attaching" for a long time (ex. 10 mins), check this post - EBS hangs in "attaching" mode forever (will not attach) without errormsg.
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 -lSample 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 tableInstall xfs tools.
sudo apt-get install -y xfsprogs xfs
sudo mkfs.xfs /dev/xvdfAdd the new volume to the file system configuration file.
sudo vi /etc/fstabAdd the following to the end of the file.
/dev/xvdf /vol xfs noatime 0 0Save 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.
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?
ReplyDeleteHi 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