Converting an EC2 AMI to vmdk image

Posted by Reed G. Law on Server Fault See other posts from Server Fault or by Reed G. Law
Published on 2012-03-29T14:12:56Z Indexed on 2012/08/30 15:40 UTC
Read the original article Hit count: 336

I've come quite close to getting Amazon Linux to boot inside VirtualBox, thanks to this answer and these websites. A quick overview of the steps I've taken:

  1. Launch EC2 instance with Amazon Linux 2011.09 64-bit AMI
  2. dd the contents of the EBS volume over ssh to a local image file.
  3. Mount the image file as a loopback device and then to a local mount point.
  4. Create a new empty disk image file, partition with an offset for a bootloader, and create an ext4 filesystem.
  5. Mount the new image's partition and copy everything from the EC2 image.
  6. Install grub (using Ubuntu's grub-legacy-ec2 package, not grub2).
  7. Convert the image file to vmdk using qemu-img.
  8. Create a new VirtualBox VM with the vmdk.

Now the VM boots, grub loads, and the kernel is found. But it fails when it tries to mount the root device:

dracut Warning: No root device "block:/dev/xvda1" found

dracut Warning: Boot has failed. To debug this issue add "rdshell" to the kernel command line.


dracut Warning: Signal caught!

dracut Warning: Boot has failed. To debug this issue add "rdshell" to the kernel command line.
Kernel panic - not syncing: Attempted to kill init!
Pid: 1, comm: init Not tainted 2.6.35.14-107.1.39.amzn1.x86_64 #1

I have tried changing /boot/grub/menu.lst to find the root device by label and UUID, but nothing works. I'm guessing the xen kernel is not compatible with VirtualBox.

The reasoning behind all this effort is to make a Vagrant box that is as close to possible as the production enviroment, so deploys can be tested locally. I know it's cheap to do test runs on EC2, but poor connectivity often ruins the experience. Plus it would be really nice to have a virtual machine with the production environment so that co-workers don't have to install everything under the sun just to get up and running with app development.

If I were to try running a different kernel, what kernel could I get to be as close as possible to Amazon Linux 2011.09?

© Server Fault or respective owner

Related posts about amazon-ec2

Related posts about virtualbox