Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon EC2: how to convert an existing PV AMI to HVM

Question:

How should I use the new AWS EC2 classes (r3, i2) with my existing AMI without recreating the whole system setup?

The new EC2 classes support only HVM based virtualization but I have only PVM AMI images.

like image 498
user3760692 Avatar asked Jun 20 '14 15:06

user3760692


People also ask

Can I change the AMI of EC2 instance?

The answer is that you cannot replace the AMI for an existing EC2 instance. However, you can replace the root volume with a new volume which is basically the same thing. That new root volume can come from another EC2 instance.

What is the difference between HVM and PVM?

Linux Amazon Machine Images use one of two types of virtualization: paravirtual (PV) or hardware virtual machine (HVM). The main differences between PV and HVM AMIs are the way in which they boot and whether they can take advantage of special hardware extensions (CPU, network, and storage) for better performance.


1 Answers

Answer:

  1. Start an Ubuntu HVM linux, any version, new

  2. Start an Ubuntu / with my existing AMI / PVM linux, and install grub packages on them: apt-get install grub-pc grub-pc-bin grub-legacy-ec2 grub-gfxpayload-lists

  3. Stop PVM linux

  4. Detach root (/dev/sda1) partition at PVM linux

  5. Attach PVM linux root partition to running HVM linux somewhere, e.g.: /dev/sdf

  6. On HVM linux: mkdir -p /mnt/xvdf && mount /dev/xvdf /mnt/xvdf

  7. rsync -avzXA /boot/ /mnt/xvdf/boot/

  8. mount -o bind /dev /mnt/xvdf/dev && mount -o bind /dev/pts /mnt/xvdf/dev/pts && mount -o bind /proc /mnt/xvdf/proc && mount -o bind /sys /mnt/xvdf/sys

  9. chroot /mnt/xvdf

  10. grub-install --no-floppy --recheck --force /dev/xvdf

  11. update-grub2

  12. exit chroot: CTRL+D

  13. stop HVM Linux

  14. detach /dev/sda1 original root AND detach /dev/sdf PVM root

  15. attach PVM root to HVM linux as /dev/sda1

  16. Start HVM linux, voilà!

  17. Create a new AMI image from the running HVM linux, it will be HVM virtualized.

like image 167
divyenduz Avatar answered Oct 24 '22 23:10

divyenduz