Converting an EC2 AMI to vmdk image

amazon ec2disk-imagekernelvirtualbox

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?

Best Answer

I tried so much and I was giving up, but at the end I succeed!

I've managed to boot with an Amazon Linux AMI ported under vmware!

I'm almost a newby, but I did it, after hours of trials, substituting the original amazon kernel with a vmlinuz-2.6.32-38-generic taken from an ubuntu 64 10.04 distro.

I just get a lot of errors because the amazon configuration inside the AMI is looking for something in an internal address that obviously it doesn't find. It's the /usr/bin/cloud-init, I think.

But I can login inside, and it seems that everything is working!

Thanks for your help!!

I've written this blogpost with step by step instructions to migrate from AMI to Vmware.

Hope this helps!

Related Topic