Migrating an AMI to use an EBS-root

As some of my sites run code not permissible on shared hosting plans, I have previously used a dedicated server, and more recently (the past year), have used Amazon EC2. My original images ran in the m1.small category (the default), but with the addition of the t1.micro category last week, I decided to migrate to this more practical instance type. There is, however, one problem – t1.micro instances must have an EBS root device.

Converting from instance-store to EBS, turned out to be much easier than expected. The general procedure is outlined below:

  • Create an EBS volume (I find the AWS console to be the easiest, although, ElasticFox is a close second)
  • Attach the EBS to a running instance (again, using the AWS console, device path will be listed)
  • SSH into the instance:
    • Format the EBS device (using the path obtained, above)
    • Mount the EBS device
    • Copy the root (/) directory to the EBS device (I used rsync)
      • Rsync options: Archive (-a), preserve extended attributes (-X), preserve hard links (-H), (optional) verbose (-v)
    • Rsync the devices (/dev) with the EBS device (not sure if this is entirely necessary)
    • Flush writes (and if you are in a directory on the EBS device, cd elsewhere), and unmount
  • Detach EBS (using AWS console)
  • Create a snapshot (using AWS console)
  • Register the AMI (using SSH or command prompt, etc) (I selected a kernel image (AKI) first, not sure if this was needed)
    • ec2-register: pass ‘-s’ and ‘-root-device-name’ as parameters (as well as all other required arguments)
  • Launch the new created image, and all should be functioning as before.

I did find that:

  1. When the new image was created, a second EBS volume was also created – having no need for the first (there is a snapshot, the original ‘instance-store’ version, and the new EBS), I deleted the original EBS, without ill effects
  2. The EBS backed instance boots a bit quicker than the ‘instance-store’ image.

By cyberx86

Just a random guy who dabbles with assorted technologies yet works in a completely unrelated field.

Leave a comment

Your email address will not be published. Required fields are marked *