Create an AWS HVM Linux AMI from an Existing Paravirtual Linux AMI
Update
AWS has enabled this feature in the EC2 API. It is available as the --virtualization-type
option to aws ec2 register-image
in the new Boto based awscli.
Original answer
Yes! Unfortunately, there is not a direct way to do so. Also, some PV instances may need kernel and bootloader modifications.
- Create a volume from your existing PV AMI. If it was your own PV AMI, you can make a volume from the snapshot. If it is a 3rd party AMI, you will need to launch an instance and take a snapshot.
- Launch an HVM instance with any AMI.
- Stop that HVM instance.
- Detach the root volume from that instance.
- Attach the PV volume as the root volume(/dev/sda1 or /dev/sda if it was partitioned) to the HVM instance.
- Run
ec2-create-image
on the HVM instance. - Launch other instances with your new HVM AMI.
If that doesn't work, then before step 5, you will need to attach that volume to a running instance, set up a chroot, and install a kernel and bootloader for your distribution. You may also want to clear logs and any cloud-init cache.
In my case, I had to do the conversion manually since the instance that I create using aws ec2 register-image
did not boot. My solution is based on this post on the AWS EC2 Forum.
Preparation
Make sure that all the volumes are in the same availability zone.
SSH to your PV machine that you want to migrate from and apply all updates, then log out.
Go to the AWS Console and launch a new HVM instance by selecting the same base AMI that the PV system was created from (in my case, the Amazon 64-bit Linux AMI).
SSH to this new instance and apply all updates, then log out.
Go to the AWS Console and stop the PV instance. Take a snapshot of the root device and create a new volume (
SOURCE VOLUME
) from this snapshot.Stop the HVM instance. Take a snapshot of the root device on the new instance and create a new volume (
TARGET VOLUME
) from this snapshot.-
Using the AWS Console:
- Attach
SOURCE VOLUME
to the new instance as/dev/xvdf
. - Attach
TARGET VOLUME
to the new instance as/dev/xvdg
.
- Attach
Conversion Process
-
SSH to the new instance and get root access:
sudo su
-
Mount the source and target drives.
mkdir -p /mnt/source && mount /dev/xvdf /mnt/source mkdir -p /mnt/target && mount /dev/xvdg1 /mnt/target
In my case, the devices were
/dev/xvdf
(source) and/dev/xvdg1
(target). These may change in your configuration based on the number of partitions and where you attached them (see step 6 in Preparation). Usels -al /dev/xvd*
to see the drives. Backup
/lib/modules/*
(If the kernel of the PV ami differs from the new HVM machine. This module is used by some services of AWS.)-
Delete everything but
/boot
on the target volume:cd /mnt/target && ls | grep -v boot | xargs rm -Rf
-
Delete
/boot
on the source volume:rm -Rf /mnt/source/boot
-
Copy the source volume's data to the target volume preserving all the attributes:
rsync -aAXHPv /mnt/source/ /mnt/target
-
Edit
/mnt/target/etc/fstab
for/
partition, so that it references theTARGET VOLUME
when mounted on its final location in step (8). Either using a label or simply something along:/dev/xvda1 / ext4 defaults,barrier=0 1 1
Then restore /lib/modules/
that was backed up in Step 3. (If the kernel of the PV ami differs from the new HVM machine.)
-
Stop the system and detach all volumes using the AWS console. Attach the
TARGET VOLUME
on the new instance as/dev/xvda
.Be sure to note where the original root device was mounted. In most cases, it should be
/dev/xvda
. Start your HVM instance. It should now be an exact duplicate of your PV system. If everything looks OK, you may now delete your PV instance and also
SOURCE VOLUME
.
TLDR:
ec2-register -a x86_64 -d '3.15.7-200.fc20.x86_64' -n 'Fedora_20_HVM_AMI' --sriov simple --virtualization-type hvm -s snap-b44feb18 --root-device-name /dev/sda1
Detailed steps:
Answering further based upon Jeff Strunk's response to simplify the steps and giving a bit more details on the ec2 register image:
Create Instance using PV Image. Make / update any changes you want.
Create Image from the above instance.
-
Find the snapshot id used by the above AMI under EC2 > Elastic Block Store > Snapshot in EC2 Console.
or if you have the ec2 api tools setup:
ec2-describe-images ami-id_of_above_created_ami
and find the snapshot id for the ami
.. Assumptions for further steps: Your ec2 keys and api tools are set and ready to use:
Register a new HVM AMI using the above snapshot: example:
ec2-register -a x86_64 -d '3.15.7-200.fc20.x86_64' -n 'Fedora_20_HVM_AMI' --sriov simple --virtualization-type hvm -s snap-b44feb18 --root-device-name /dev/sda1
where
- -d is AMI description
- -n is AMI name
- -s is snapshot id from step 3.
- -a is architecture
- --virtualization-type is required for making it hvm
- --sriov is for enabling enhanced networking , though it might be redundant, not sure.
For more information:
- ec2 cli docs for register-image
- ec2 api docs ec2-register
You can do this from inside of the AWS web interface. Navigate to snapshots, click the desired snapshot you wish to convert to hvm and click on actions and then create image. In the dropdown in the create image wizard select HVM.