Amazon

From Unix Wiki
Jump to: navigation, search

Clone Amazon EC2 Instance

Problem description

Clone existing Amazon EC2 Instance (Linux Server) to XenServer or XCP host. Since both services uses same virtualisation technique (XEN) this task doesn't produce any problem. Just small configuration adjustments.

Action Plan

  • Create clone tar archive and download it from Amazon Server:

Exec:

tar cvzpf /big/clone-`date +%F`.tar.gz --exclude=/sys/* --exclude=/dev/pts --exclude=/big/clone-`date +%F`.tar.gz --exclude=/proc/* /

Rest steps does't include work on remote Amazon Server.

  • Create new empty VM which will be used as container for clone. Preferably use identical templates for VM creation. Set CD as install device.
  • To view current VM config exec on XEN host:
xe vm-param-list uuid=<UUID>
  • Set bootloader to pygrub:
xe vm-param-set uuid=<UUID> PV-bootloader=pygrub
  • Since VM is in PV mode we need working hvm or pv VM to attach system disk and extract archive of Amazon Instance created before.

After creating necssary filesystems and extracting archive edit grub.conf and menu.lst for new installation according to default layout. CentOS 6 example:

####################################
[root@zuzafs01 ~]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,0)
#          kernel /boot/vmlinuz-version ro root=/dev/xvda1
#          initrd /boot/initrd-[generic-]version.img
#boot=/dev/xvda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-220.4.2.el6.x86_64)
root (hd0,0)
kernel /boot/vmlinuz-2.6.32-220.4.2.el6.x86_64 ro root=/dev/xvda1 console=hvc0
initrd /boot/initramfs-2.6.32-220.4.2.el6.x86_64.img
title CentOS (2.6.32-220.4.1.el6.x86_64)
root (hd0,0)
kernel /boot/vmlinuz-2.6.32-220.4.1.el6.x86_64 ro root=/dev/xvda1 console=hvc0
initrd /boot/initramfs-2.6.32-220.4.1.el6.x86_64.img
####################################
  • Chroot to new ENV (Assume /a - chroot dir):
chroot /a /bin/bash
  • Set password for root if needed.
passwd
  • Disable Amazon services:
chkconfig cloud-init off
  • Recreate SSH host keys
cd /etc/ssh/
rm ssh_host_dsa_key ssh_host_dsa_key.pub ssh_host_key ssh_host_key.pub ssh_host_rsa_key ssh_host_rsa_key.pub
  • Configure network and hostname:
system-config-network-tui
  • Fix /etc/fstab:
vi /etc/fstab
  • Unmount dir's, poweroff VM and attach storage to empty VM.

All set. Boot VM.