Tuesday, January 3, 2012

Copying or Transferring Windows AMI across Amazons EC2 regions


The process is simple but long & tiring… Here is a brief note on how to do it:

SR (Source Region) – Where you already have an AMI that you wish to transfer to other region.
DR (Destination Region) – Where AMI need to be transferred to.

SR:
1.       Create an Instance from the AMI.
2.       Note down the volume used by this AMI.
3.       Shut down and Detach the volume.
4.       Now, create one ubuntu instance and attach the volume from step 3 to this instance.

DR:
1.       Create a blank volume of same size as that of SR point 2.
2.       Create a ubuntu instance and attach the volume from point 1 above to this instance.

Now, all we need to do is use the ‘dd’ command to binary transfer the volume from SR to the blank volume in DR. So here is the command that you will run on SR:  Make sure you have given full permissions to /dev/sdh1 or /dev/xvdf for newer versions.

sudo dd if=/dev/sda1 | ssh -i mykey.pem instancepublicdns.compute.amazonaws.com dd of=/dev/sdh1

Here:
             /dev/sda1 may need to be /dev/xvdf for newer versions
            Mykey.pem is the key that was used to create DR ubuntu instance.
            Instancepublicdns.compute.amazon.com is the public dns of DR’s ubuntu instance.

The dd command does a binary transfer and takes hell lot of time depending on the size of volume and network speed. Worst to that is that it does not display any progress indicator etc.. It only shows the results when it is done.

Once the dd command is over follow below steps:
1         .    Detach the blank volume that was created in DR Point 1.
2         .    Create a Windows Instance and shut it down.
3         .    Detach the default volume of Windows instance created above.
4         .    Attach the blank volume we created in DR Point 1.
5         .    Reboot Windows instance and you are good to go.

Now, you can create an AMI from this Windows Running instance which will be an exact copy of what you had in your source region. 

No comments:

Post a Comment