Road to Nowhere

Do you know what you want?

Notes

AMI with EBS volume

  1. select source AMI and launch Instance (AWS console->IMAGES->AMIs)
  2. create volume and attach to running Instance (AWS console->ELASTIC BLOCK STORE->Volumes)
  3. associate EIP and ssh login
  4. mkfs.ext3 /dev/sdf
  5. mkdir /mnt/ebs
  6. mount /dev/sdf /mnt/ebs
  7. rsync -a -d -p -x —exclude /root/.bash_history —exclude /etc/ssh/ssh_host_* —exclude /etc/ssh/moduli —exclude=/mnt/* —exclude=/proc/* / /mnt/ebs
  8. download public-key (http://aws.amazon.com/console->My Account/Console->Security Credentials), AWS Account ID : 3568-7797-8148
  9. make /etc/init.d/getssh shell script
  10. chmod a+x /etc/init.d/getssh
  11. /usr/sbin/chroot /mnt/ebs /sbin/chkconfig —level 34 getssh on
  12. sync
  13. umount /mnt/ebs
  14. yum install java-1.6.0-openjdk-devel.x86_64
  15. export EC2_HOME=/root/ec2-api-tools-1.5.0.1-2011.11.30
  16. export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk.x86_64
  17. export EC2_CERT=`pwd`/cert-*.pem
  18. export EC2_PRIVATE_KEY=`pwd`/pk-*.pem
  19. ec2-create-snapshot [volume ID]
  20. ec2-describe-snapshots [snapshot ID]
  21. 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