https://aws.amazon.com/developertools/351
$ vi ~/.bash_profile
export EC2_HOME= <Toolsの展開先>
export JAVA_HOME=`/usr/libexec/java_home`
export PATH=$PATH:$JAVA_HOME/bin:$EC2_HOME/bin
export AWS_ACCESS_KEY= <アクセスキーID>
export AWS_SECRET_KEY= <シークレットアクセスキー>
$ . ~/.bash_profile
$ vi vm-import.sh
<EC2 API Tools>/bin/ec2-import-instance \
<エクスポートしたVMDK>.vmdk \
--owner-akid <アクセスキーID>
--owner-sak <シークレットアクセスキー>
--format VMDK \
--region ap-northeast-1 \
--bucket pitagora \
--architecture x86_64 \
--platform Linux \
--instance-type t2.micro
$ ./vm-import.sh
$ vi check_progress.sh
./ec2-api-tools-1.7.5.1/bin/ec2-describe-conversion-tasks --region ap-northeast-1
$ watch -d sh check_progress.sh
TaskType IMPORTINSTANCE TaskId import-i-fgg4piyo ExpirationTime 2014-09-03T10:01:36Z Status active StatusMessage Pending InstanceID i-97a7178e
DISKIMAGE DiskImageFormat VMDK DiskImageSize 1568721408 VolumeSize 128 AvailabilityZone ap-northeast-1c ApproximateBytesConverted 1470714096 Status active StatusMessage Pending : Downloaded 1268776960
↓
TaskType IMPORTINSTANCE TaskId import-i-fgg4piyo ExpirationTime 2014-09-03T10:01:36Z Status active StatusMessage Pending InstanceID i-97a7178e
DISKIMAGE DiskImageFormat VMDK DiskImageSize 1568721408 VolumeSize 128 AvailabilityZone ap-northeast-1c ApproximateBytesConverted 1568716784 Status active StatusMessage Progress: 50%
↓
TaskType IMPORTINSTANCE TaskId import-i-fgg4piyo ExpirationTime 2014-09-03T10:01:36Z Status active StatusMessage Progress: 6% InstanceID i-97a7178e
DISKIMAGE DiskImageFormat VMDK DiskImageSize 1568721408 VolumeId vol-4c4afb4a VolumeSize 128 AvailabilityZone ap-northeast-1c ApproximateBytesConverted 1568716784 Status completed
↓
TaskType IMPORTINSTANCE TaskId import-i-fg3tguis ExpirationTime 2014-08-28T09:43:04Z Status completed InstanceID i-dabb0ec3
DISKIMAGE DiskImageFormat VMDK DiskImageSize 1573807104 VolumeId vol-5e7bcf58 VolumeSize 128 AvailabilityZone ap-northeast-1c ApproximateBytesConverted 1573802544 Status completed
$ ssh galaxy@
$ yum install cloud-init
OSユーザー centos で接続できることを確認
$ ssh centos@
$ sudo vi /etc/rc.d/rc.local
# Install Public Key Credentials
if [ ! -d /home/galaxy/.ssh ]; then
mkdir -m 0700 -p /home/galaxy/.ssh
restorecon /home/galaxy/.ssh
fi
# Get the root ssh key setup
ReTry=0
while [ ! -f /home/galaxy/.ssh/authorized_keys ] && [ $ReTry -lt 10 ]; do
sleep 2
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /home/galaxy/.ssh/pubkey
if [ 0 -eq 0 ]; then
mv /home/galaxy/.ssh/pubkey /home/galaxy/.ssh/authorized_keys
fi
ReTry=$[Retry+1]
done
chmod 600 /home/galaxy/.ssh/authorized_keys && restorecon /home/galaxy/.ssh/authorized_keys
chown -R galaxy:galaxy /home/galaxy
$ sudo vi /etc/ssh/sshd_config
PubkeyAuthentication yes
$ sudo reboot
$ ssh galaxy@
$ ssh galaxy@
$ sudo vi /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
$ sudo service sshd restart
$ sudo mkfs -t ext4 /dev/xvdb
$ sudo mkfs -t ext4 /dev/xvdc
$ sudo vi /etc/fstab
/dev/xvdb /disk/reference ext4 defaults 0 0
/dev/xvdc /disk/database ext4 defaults 0 0
$ sudo mount -a
$ sudo chown galaxy:galaxy /disk/*
$ cd ~/galaxy-dist
$ rm database
$ ln -s /disk/database
$ cp -r database_bak/* database/
$ sudo yum install -y ruby unzip
$ wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip
$ sudo mkdir -p /usr/local/ec2
$ sudo unzip ec2-ami-tools.zip -d /usr/local/ec2
$ vi .bash_profile
export EC2_AMITOOL_HOME=/usr/local/ec2/ec2-ami-tools-<version>
export PATH=$EC2_AMITOOL_HOME/bin:$PATH
$ . .bash_profile
$ ec2-ami-tools-version
$ sudo passwd -l root
$ sudo shred -u /etc/ssh/*_key /etc/ssh/*_key.pub
$ sudo vi /etc/ssh/sshd_config
UseDNS no
$ shred -u ~/.*history
$ shred -u ~/galaxy/paster.log
$ shred -u /var/spool/mail/galaxy
$ shred -u .ssh/authorized_keys
$ rm -rf .ssh
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/building-shared-amis.html
http://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/sharingamis-intro.html