Director and founder
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.
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 -
chmod +x pv-hvm-latest.sh
"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:
- Checks the Operating System.
- 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  at the end of my correspondence to install the aws-cli, using Pip.
- 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.
- 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.
- When it asks you for the region, enter “Ireland”.
- As soon as it asks you for the output format, you can enter “JSON”.
- Create an AMI of the source instance.
- Create volume of the source instance root volume.
- Attach the volume to temporary (working instance) instance.
- Create destination volume (1GB larger that source volume).
- ‘fsck’ and resize the source volume.
- Partition the destination volume.
- ‘dd’ data from source to destination partition.
- Installs grub on the destination volume.
- Fix /boot/grub/menu.lst.
- Fix /etc/fstab.
- Copy snapshots of any additional volumes you might have attached to the source instance.
- Create a new AMI with BlockDeviceMapping for all EBS volumes (as per the BlockDeviceMapping of the source instance).
- 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:
Lockdown 2.0 is a great time to work on your website. Whether it’s updating front end content or adding metadata and new plugins in the back end there’s never been a better time to focus on your website.
Thanks for visiting. Cheerio! Cheers and bye for now. So, farewell and hope to see you soon.
We've been Digital Technology Labs.