Using EBS with OpenSolaris 2008 AMI on Amazon EC2
Amazon describes the functionality provided by EBS as follows:
“Amazon Elastic Block Store (EBS) provides block level storage volumes for use with
Amazon EC2 instances. Amazon EBS volumes are off-instance storage that persists
independently from the life of an instance. Amazon Elastic Block Store provides highly
available, highly reliable storage volumes that can be attached to a running Amazon EC2
instance and exposed as a device within the instance. Amazon EBS is particularly suited for
applications that require a database, file system, or access to raw block level storage.”
In this article, we will list all the necessary steps involved in creating new EBS volumes and attaching them to an existing instance. The following commands were run on an OpenSolaris 2008.11 instance. The disk device name may change in other AMIs.
Set the Environment Variables on local machine
export EC2_HOME=/opt/ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$EC2_HOME/keys/pk-************.pem
export EC2_CERT=$EC2_HOME/keys/cert-************.pem
export JAVA_HOME=/usr/jdk/latest
export EC2_URL=https://ec2.amazonaws.com
Note: Replace the values of the environment variables accordingly.
Start an OpenSolaris 2008 Instance
ec2-run-instances ami-7db75014 -k prateek-keypair
Login to the Instance
ssh -i /PATH/TO/keypair-file root@ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com
Note: Replace the value of the public host name of the above instance accordingly.
Create a keys directory
mkdir /opt/ec2/keys
Transfer your Private key and certificate to the Instance from local machine
scp -i /PATH/TO/keypair-file /PATH/TO/KEYS/*pem root@root@ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com:/opt/ec2/keys
Set the Environment Variables on the EC2 instance
export EC2_HOME=/home/EC2/ec2-api-tools-1.3-19403
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=/home/EC2/ec2-api-tools-1.3-19403/keys/pk-************.pem
export EC2_CERT=/home//EC2/ec2-api-tools-1.3-19403/keys/cert-************.pem
export JAVA_HOME=/usr/jdk/latest
export EC2_URL=https://ec2.amazonaws.com
Create a new EBS Volume
The following command can be repeated as needed to create additional volumes.
ec2-create-volume --size 128 --availability-zone us-east-1a
VOLUME vol-b1dc3fd8 128 us-east-1a creating 2009-04-22T01:23:00+0000
ec2-describe-volumes vol-b1dc3fd8
VOLUME vol-b1dc3fd8 128 us-east-1a available 2009-04-22T01:23:00+0000
You can list all the volumes along with their status as:
ec2-describe-volumes | cut -f2,3,5,6
vol-7208ed1b 2 us-east-1c available
vol-99dc3ff0 128 us-east-1a available
vol-0f2ecb66 1 us-east-1a available
vol-b1dc3fd8 128 us-east-1a available
Attaching Volumes to an OpenSolaris EC2 Instance
The command for attaching volumes to an instance is:
ec2-attach-volume -i <instance-id> -d <device-id> VOLUMENAME
In
Solaris, devices are named from 0 to 23. Device number 0 and 1 are used
for ephemeral storage. Therefore, we can use the devices starting from
2 until 23.
I have attached 2 volumes to the current instances below:
ec2-attach-volume -i i-ed573f84 -d 3 vol-6123c008
ec2-attach-volume -i i-ed573f84 -d 4 vol-b1dc3fd8
The list of the attached volumes can be displayed as:
ec2-describe-volumes | grep attached
ATTACHMENT vol-99dc3ff0 i-ed573f84 2 attached 2009-04-22T02:46:24+0000
ATTACHMENT vol-6123c008 i-ed573f84 3 attached 2009-04-22T02:47:22+0000
ATTACHMENT vol-b1dc3fd8 i-ed573f84 4 attached 2009-04-22T02:47:57+0000
ATTACHMENT vol-6e23c007 i-ed573f84 5 attached 2009-04-22T02:48:16+0000
Using EBS volumes from the Solaris Instance
You can view the mapping of the Solaris devices to the EBS volumes that we created earlier.
NOTE: Use c4d*p0 for OpenSolaris 2008.05 (ami-41e70328 )and c0d*p0 for SXCE Build 79 32 bit
image (ami-eb7a9f82)
ls -l /dev/dsk/c3d*p0
lrwxrwxrwx 1 root root 26 2008-12-14 23:32 c3d0p0 -> ../../devices/xpvd/xdf@0:q
lrwxrwxrwx 1 root root 26 2008-12-22 18:54 c3d1p0 -> ../../devices/xpvd/xdf@1:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:46 c3d2p0 -> ../../devices/xpvd/xdf@2:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:47 c3d3p0 -> ../../devices/xpvd/xdf@3:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:47 c3d4p0 -> ../../devices/xpvd/xdf@4:q
lrwxrwxrwx 1 root root 26 2009-04-22 02:48 c3d5p0 -> ../../devices/xpvd/xdf@5:q
lrwxrwxrwx 1 root root 26 2008-12-14 23:32 c3d6p0 -> ../../devices/xpvd/xdf@6:q
Now, you can use these EBS volumes just like you would use any other attached storage device.