+44(0)1268 906092 Website specialists
Estimated reading time: 6 minutes
Kevin Gordon

Kevin Gordon

Director and founder

Author Kevin is a published writer in NET magazine, the UK’s leading Web Design and Development magazine monthly. Here he talks about how to migrate from PV to HVM so you can downgrade your AWS instance and save a lot of money.


So you are on AWS (Amazon Web Services) but you’re on a free instance that is not big enough or a m3.medium which is extremely expensive.

It is because you were put on PV (paravirtual) – which limits which other instances you can be on.

To move to lower hardware, you need to convert PV to HVM. This is step by step guide on how you do it.

Migrate AWS PV to HVM. If you are stuck on PV / paravirtual then you can either be on the t1.tiny (free but not big enough) or the m3.medium. The later is hugely expensive. To move to a lower hardware, you need to convert PV to HVM. This is how you do it.

Using the Amazon script to convert from PV to HVM

Amazon has a script that you can run that automatically converts your PV instance to a HVM instance. The following are the requirements to run the script:


  • Launch a temporary Amazon Linux instance (PV or HVM). Do this in the same region as the instance you would like to convert. This is just going to be used to run the commands to convert / generate a converted AMI. Therefore it doesn’t really matter what the configuration is, as long as it’s the same region.
  • It is advisable to stop your source PV instance first before running the script, if the instance is not already stopped. My recommendation, to protect your ‘live site’, from a backup snapshot, create an image, then from that launch an instance, and use that as the source instance.
  • The script needs to be executed as the root user on the temporary instance, so sudo to the root user before executing the following steps:

sudo su -
wget https://s3.amazonaws.com/jacquecp/pv-hvm-latest.sh
chmod +x pv-hvm-latest.sh
./pv-hvm-latest.sh i-xxxxxxxx

In the "i-xxxxxxxx" in the above, substitute the source PV instance you’d like to convert to HVM.

What the script does

To migrate AWS PV to HVM, the script does the following:

  1. Checks the Operating System.
  2. Checks prerequisite software and installs if required – requires aws-cli and jq.
    If you don’t have aws-cli installed, please follow the steps in the document marked [1] at the end of my correspondence to install the aws-cli, using Pip.
  3. Checks for sufficient IAM permissions of the IAM credentials configured in aws-cli. If the script asks you to enter Access Key and Secret Key, please provide these credentials.
  4. Checks that source instance is not the same as the working instance (script cannot be executed from instance to be converted), checks that source instance does exist in your account. When it asks you for the source PV instance ID, re-enter the instance ID of your PV source instance.
  5. When it asks you for the region, enter “Ireland”.
  6. As soon as it asks you for the output format, you can enter “JSON”.
  7. Create an AMI of the source instance.
  8. Create volume of the source instance root volume.
  9. Attach the volume to temporary (working instance) instance.
  10. Create destination volume (1GB larger that source volume).
  11. ‘fsck’ and resize the source volume.
  12. Partition the destination volume.
  13. ‘dd’ data from source to destination partition.
  14. Installs grub on the destination volume.
  15. Fix /boot/grub/menu.lst.
  16. Fix /etc/fstab.
  17. Copy snapshots of any additional volumes you might have attached to the source instance.
  18. Create a new AMI with BlockDeviceMapping for all EBS volumes (as per the BlockDeviceMapping of the source instance).
  19. A log file is also created in /tmp, and the script will prompt you to remove the rest of the temporary resources.

What to do then / how to start the new instance

When the script successfully creates the new HVM AMI from your source PV instance, you will see the new AMI ID displayed on your command prompt. Take note of this, as we’re going to launch an instance from this new AMI.

Go back to your EC2 Console to select this AMI in the “IMAGES” section of the navigation pane. After selecting the right AMI ID, follow the normal instance launch process to launch a t2.large instance by clicking on the “Launch Instance” button and go through the launch wizard. Things to remember, is assigning the correct security group, adding the monitoring user, enabling advanced monitoring.

Once you have launched the new HVM instance and everything is in order, please terminate your temporary instance to stop incurring minor costs.

To migrate AWS PV to HVM you may need to look at the final stage below.

Migrate AWS PV to HVM – sort out CloudFront and Fail2ban and then you’re done

For my setup, I also had CloudFront in front, and to get this working, I needed to re-assign the elastic IP address to the new instance. This was the easy bit, the site worked, but the backend didn’t. I thought this was due to something wrong with the setup, so created a new CloudFront instance, and repointed the DNS at that. However it was Fail2ban blocking it, so I set it to ignore the offending IP addresses and it then worked perfectly.

If you need any further help

To migrate AWS PV to HVM, if you need any further help, or clarification on the above, leave a comment below or feel free to get in contact with us here. We’re a boutique web design agency, that can be commissioned for development work too.

Want to get more help or further guidance?

Check out other awesome blog content:

Thank you.

Thanks for visiting. Cheerio! Cheers and bye for now. So, farewell and hope to see you soon.

We've been Digital Technology Labs.