Wednesday May 06, 2009

Importing OpenSolaris EC2 Image on Local Xen Environment

In this blog entry, I am going to walk you through the steps for importing OpenSolaris Amazon EC2 AMI on local Xen environment running on OpenSolaris 2008.11.

I assume
- you are running OpenSolaris 2008.11 build rc2 dom0.
- ec2 ami/api tools installed at /opt/ec2
- your ec2 certificate and private key files available at /opt/ec2/keys
- your ec2 keypair file located at /opt/ec2

[ Step-1 ]
Launch fresh OpenSolaris 2008.11 AMI Instance
ec2-run-instances ami-7db75014 -k your-keypair

Login in with your keypair file
ssh -i /opt/ec2/your-keypair

[ Step-2 ]
Remove EC2 specific stuff from the instance.

Open “/etc/ssh/sshd_config” and replace "PermitRootLogin without-password" with "PermitRootLogin yes" and save the file.

Set the root password
passwd: Changing password for root
New Password:
Re-enter new Password:
passwd: password successfully changed for root

Disable and remove ec2 specific services

svcadm disable svc:/ec2/sshkey:default
svcadm disable svc:/ec2/fixes:default
svcadm disable svc:/ec2/mount:default

svccfg delete svc:/ec2/sshkey:default
svccfg delete svc:/ec2/fixes:default
svccfg delete svc:/ec2/mount:default

[ Step-3 ]
Log out of the ec2 instance and transfer your keys at /mnt/keys to begin re-bundling image.
scp -i /opt/ec2/id-your-keypair -r /opt/ec2/keys/

[ Step-4 ]
Login back to ec2 instance.
ssh -i /opt/ec2/your-keypair

[ Step-5 ]
Start bundling the image.

# cd /mnt
# /opt/ec2/sbin/ -v opensolaris_2008_11_ami.img
Creating image file /mnt/opensolaris_2008_11_ami.img
Preparing clone pool on /dev/lofi/1
# will take about 10-15 minutes to create raw opensolaris image.

[ Step-6 ]
Bundle image and create parts.

export BUCKET=my-bucket
export JAVA_HOME=/usr/jdk/latest
export EC2_HOME=/opt/ec2
export PATH=$PATH:$EC2_HOME/bin
export RUBYLIB=$EC2_HOME/lib
export EC2_URL=

export EC2_PRIVATE_KEY=/mnt/keys/pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem
export EC2_CERT=/mnt/keys/cert-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem

export EC2_KEYID=xxxxxxxxxxxxxxxxxxxxxxx
export EC2_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

export DIRECTORY=/mnt
export IMAGE=opensolaris_2008_11_ami.img

# ec2-bundle-image -c $EC2_CERT -k $EC2_PRIVATE_KEY \\
--kernel aki-6552b60c --ramdisk ari-6452b60d \\
--block-device-mapping "root=rpool/52@0,ami=0,ephemeral0=1" \\
--user <user-id> --arch i386 \\

[ Step-7 ]
Upload image parts on s3

# cd $DIRECTORY/parts

# ec2-upload-bundle -b $BUCKET -m opensolaris_2008_11_ami.img.manifest.xml \\
--url \\
--retry -a $EC2_KEYID -s $EC2_KEY

[ Step-8 ]
Log out of the instance.
Download image parts and unbundle it to re-create the raw image locally.

# mkdir /osol-ec2-image
# mkdir /osol-ec2-image/parts
# cd /osol-ec2-image/parts

# ec2-download-bundle -b my-bucket -m opensolaris_2008_11_ami.img.manifest.xml \\
-a <your-access-key-id> -s <your-secret-key-id> \\
--privatekey /opt/ec2/keys/pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx .pem

# ec2-unbundle -m opensolaris_2008_11_ami.img.manifest.xml \\
-k /opt/ec2/keys/pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx .pem

# mv opensolaris_2008_11_ami.img
# cd /osol-ec2-image/
[ Step-9 ]
Create “” at /osol-ec2-image with following lines

name = "opensolaris-ec2-image"
vcpus = 1
memory = "1024"

disk = ['file://osol-ec2-image/opensolaris_2008_11_ami.img,0,w']

vif = ['']

on_shutdown = "destroy"
on_reboot = "restart"
on_crash = "destroy"

[ Step-10 ]
Launch domu image and login with root user and the password you set during step-2

xm create

Using config file "./".
Started domain opensolaris-ec2-image

xm console opensolaris-ec2-image
v3.1.4-xvm chgset 'Mon Oct 13 22:14:51 2008 -0700 15904:94bd0a643efe'

SunOS Release 5.11 Version snv_101b 32-bit

Copyright 1983-2008 Sun Microsystems, Inc. All rights reserved.

Use is subject to license terms.
Hostname: dhcp-umpk16-85-23
Reading ZFS config: done.
Mounting ZFS filesystems: (5/5)

dhcp-umpk16-85-23 console login:

Sunday Oct 12, 2008

how to create and setup facebook application on Amazon EC2 instance

After setting up the facebook application development platform on Amazon EC2 follwing this link, users can simply follow the README file located at "/var/apache2/2.2/htdocs/footprints/README" to test out the sample "footprints" application.

Here are the detailed steps, one can follow to sucessfully deploy the sample facebook application available on Amazon EC2 instance.

bash # cd /var/apache2/2.2/htdocs/footprints
bash # ls
config.php  index.php   lib.php     README

edit the config.php and set
$db_ip = 'localhost';
$db_pass = '';

if you have changed your db password, set it accordingly.

create database needed for the sample application. Database script for creating table structure is available in the config.php file.

­bash­3.2# /usr/mysql/bin/mysql ­u root
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 1
Server version: 5.0.45 Source distribution
Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.

mysql> create database footprints;
Query OK, 1 row affected (0.00 sec)
mysql> use footprints
Database changed

mysql> CREATE TABLE `footprints` (
    ­>   `from` int(11) NOT NULL default '0',
    ­>   `to` int(11) NOT NULL default '0',
    ­>   `time` int(11) NOT NULL default '0',
    ­>   KEY `from` (`from`),
    ­>   KEY `to` (`to`)
    ­> );

Query OK, 0 rows affected (0.01 sec)

mysql> select \* from footprints;
Empty set (0.00 sec)


open and login with your facebook username and password.
goto the Developer section and click on the "Setup new application".

Provide appropriate application name and agree to the terms and conditions. finally click on the submit button to create the new application.

setup new application

Click on the "Edit Settings" and provide following details.

Call back URL:

Canvas page URL:

replace osolami with any avaiable string, to identify your application.

Check mark on  "Can your application be added on facebook?"

In the default FBML text box provide follwing

<br />Hi
<fb:name uid="profileowner" firstnameonly="true" useyou="false"/>! This is the default FBML as specified
in Footprints' account configuration page. This will get replaced the first
time you get stepped on.

after the change, click on "Save" button to update the settings.

facebook application settings page

facebook application settings

facebook application info page


Copy API Key and Secret Key from the above page and change that in to

after the change config.php should look like as given below

bash # cat config.php


// Get these from

$api_key = 'd4ec887d2c2d820300eb95785fa5bd68';

$secret = 'a8db36baf5c93f3673fce7ea799d6b40';

/\* While you're there, you'll also want to set up your callback url to the url

\* of the directory that contains Footprints' index.php, and you can set the

\* framed page URL to whatever you want. You should also swap the references

\* in the code from to your framed page URL. \*/

// The IP address of your database

$db_ip = 'localhost';
$db_user = 'root';

$db_pass = '';

// the name of the database that you create for footprints.
$db_name = 'footprints';

/\* create this table on the database:

CREATE TABLE `footprints` (

`from` int(11) NOT NULL default '0',

`to` int(11) NOT NULL default '0',

`time` int(11) NOT NULL default '0',

KEY `from` (`from`),

KEY `to` (`to`)



Replace the URL to
in /var/apache2/2.2/htdocs/footprints/lib.php

Note: Here "" is your canvas page URL. make the necessary changes accordingly.


Every thing is set. Now we are ready to hit the application URL
provide facebook username and password to login in

facebook application login page

Once you are logged in. You will see your sample facebook application running on EC2 instance.

It should look like as given below.

facebook application preview

facebook application preview

"leave your foot prints on some of your friends by steping upon them, and see the database table with updated stepping history".

bash # /usr/mysql/bin/mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \\g.

Your MySQL connection id is 5

Server version: 5.0.45 Source distribution

Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.

mysql> use footprints;

Database changed

mysql> select \* from footprints;


| from | to | time |


| 51760XXXX | 101467XXXX | 1223533149 |


1 row in set (0.00 sec)


You are all done and set with the sample facebook application on amazon ec2 instance.


Divyen Patel


« June 2016