Convert an Instance-Store AMI to EBS-Backed AMI


  1. Launch an instance from an instance store-backed AMI.
  2. Make a note of the ramdisk ID and kernel ID your running instance is using 
  3. Create a 10GiB Amazon EBS volume in the same Availability Zone as that of your newly-launched instance e.g. /dev/sdf
  4. Attach the volume to the running instance using either the AWS Management Console or the command line interface.
  5. Make sure all services are turned off like mysqld, nginx etc.
  6. Format the volume with a file system. Newer kernels use /dev/xvdf convention
    • mkfs.ext3 /dev/xvdf
  7. Create a directory /mnt/ebs and mount the volume on it.
    • mkdir /mnt/ebs  
    • mount /dev/xvdf /mnt/ebs
  8. Copy the data on the root storage device to the newly-attached volume.
    • rsync -avx --exclude /mnt/ebs / /mnt/ebs
  9. [SPECIFIC TO UBUNTU]
    1. Edit /mnt/ebs/etc/fstab,/mnt/ebs/boot/grub/menu.lst and /mnt/ebs/boot/grub/grub.cfg and replace uses of LABEL=cloudimg-rootfs with /dev/xvda1  
    2. Remove /dev/xvda2 and /dev/xvda3 specific instructions from /mnt/ebs/etc/fstab
  10. [SPECIFIC TO CENTOS]
    1. Edit /mnt/ebs/etc/fstab,/mnt/ebs/boot/grub/menu.lst and replace uses of LABEL=/ with /dev/xvde1.
    2. Remove /dev/xvde2 and /dev/xvde3 specific instructions from /mnt/ebs/etc/fstab
  11. Create the following devices within the /mnt/ebs
    1. MAKEDEV console
    2. MAKEDEV generic
    3. MAKEDEV zero
    4. MAKEDEV null 
  12. Detach the volume from the instance.
  13. Create a snapshot of the volume.
  14. Register the snapshot of the volume as an AMI. While registering make sure you enter the architecture correct and the Kernel ID and Ramdisk ID should match the one taken a note of in Step 2. If the Ramdisk ID information is not available form the instance then leave it to Use Default.

Comments

Popular posts from this blog

To DR or Not To DR

High Availability NAT for AWS VPC with Multiple Private Subnets.

Load Balancer with SSL offloading - nginx + HAProxy