AMI with EBS volume
- select source AMI and launch Instance (AWS console->IMAGES->AMIs)
- create volume and attach to running Instance (AWS console->ELASTIC BLOCK STORE->Volumes)
- associate EIP and ssh login
- mkfs.ext3 /dev/sdf
- mkdir /mnt/ebs
- mount /dev/sdf /mnt/ebs
- rsync -a -d -p -x —exclude /root/.bash_history —exclude /etc/ssh/ssh_host_* —exclude /etc/ssh/moduli —exclude=/mnt/* —exclude=/proc/* / /mnt/ebs
- download public-key (http://aws.amazon.com/console->My Account/Console->Security Credentials), AWS Account ID : 3568-7797-8148
- make /etc/init.d/getssh shell script
- chmod a+x /etc/init.d/getssh
- /usr/sbin/chroot /mnt/ebs /sbin/chkconfig —level 34 getssh on
- sync
- umount /mnt/ebs
- yum install java-1.6.0-openjdk-devel.x86_64
- export EC2_HOME=/root/ec2-api-tools-1.5.0.1-2011.11.30
- export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk.x86_64
- export EC2_CERT=`pwd`/cert-*.pem
- export EC2_PRIVATE_KEY=`pwd`/pk-*.pem
- ec2-create-snapshot [volume ID]
- ec2-describe-snapshots [snapshot ID]
- ec2-register -a x86_64 —snapshot [snapshot ID] —description “AMI with EBS volume” —name “EBS_AMI” —kernel aki-23d43a4a —ramdisk ari-25d43a4c
#!/bin/bash
# chkconfig: 2345 95 20
# description: getssh
# processname: getssh
#
export PATH=:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
# Check that networking is up.
[ “${NETWORKING}” = “no” ] && exit 1
start() {
if [ ! -d /root/.ssh ] ; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
/usr/bin/curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/my-key
if [ $? -eq 0 ] ; then
cat /tmp/my-key » /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
rm /tmp/my-key
fi
# or fetch public key using the file in the ephemeral store:
if [ -e /mnt/openssh_id.pub ] ; then
cat /mnt/openssh_id.pub » /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
}
stop() {
echo “Nothing to do here”
}
restart() {
stop
start
}
# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $”Usage: $0 {start|stop}”
exit 1
esac
exit $?
###END OF SCRIPT