This post is useful to those who want to convert AWS ec2 instance from PV type to HVM type.
Linux Amazon Machine Images(AMI) uses two type of virtualization which is either ParaVirtual (PV) or Hardware Virtual Machine (HVM).
If you are running any AWS ec2 instance having PV virtualization type and wants to upgrade the instance to different Instance Family(https://aws.amazon.com/ec2/instance-types/) which only supports HVM virtualization type then AWS does not allow direct upgrade of instance type to different family(like c3 class to c4 class) so the existing instance must be converted to HVM virtualization type and then only the instance can be upgraded to other instance family type.
So below are the steps to convert the instance from PV to HVM virtualization type.
- Install grub on the source PV instance.(The instance which you want to upgrade).
sudo yum install grub -y or sudo apt-get install grub -y
- Launch a temporary Amazon Linux instance (PV or HVM) in the same region as the source PV instance.
Note: We will run a script from step-5 below to generate an AMI so it doesn’t matter what’s the configuration is for the new temporary instance as long as it’s in the same region as the source instance. - Install the jq filter on the temporary instance.
sudo yum install jq or sudo apt-get install jq
- On the temporary instance download conversion script and make it executable.
wget https://s3.amazonaws.com/jacquecp/pv-hvm-latest-v2.sh; chmod +x pv-hvm-latest-v2.sh;
- Execute script: (i-xxxx in below is the instance id of the source PV instance)
sudo ./pv-hvm-latest-v2.sh i-xxxx
- Follow the prompts and you will need to wait a while as this process will take some time. On completion, a new AMI id will be available and displayed on the console.
during execution of the script you will need to provide access key, secret key, region information for AWS CLI configuration setup so keep this information handy during conversion. - Launch an HVM instance from the new AMI id provided to replace your PV instance.
Reference: https://forums.aws.amazon.com/thread.jspa?messageID=648055
hi
I do this for aws ec2 pv to hvm , but i get error .
Finalizing snapshot(s) for final AMIparse error: Invalid numeric literal at line 1, column 3
./pv-hvm-latest-v2.sh: line 1152: /usr/bin/jq: Argument list too long
./pv-hvm-latest-v2.sh: line 48: /usr/bin/seq: Argument list too long
Please help me and thank you very much.
Can try doing the below and check.
1) Detach the instance store volume from the source instance
2) Use the script to create the HVM AMI of the source instance (without the instance store volume)
3) When launching an instance using the created HVM AMI, attach the instance store volume.
Even if it does not work then may be you can contact with aws support to see if they can help with the script as the mentioned script might not be working in your case and if aws support can provided updated script then that can help.
Thanks
I’ve given up this way and will create new hvm ec2, and copy file from pv ec2 .
Ok. No Problem. 🙂
Your script worked great! Thanks for the help.
The only issue I ran into is that my instances were using the newer instance format (17 character format).
I updated the instance ID length line in your code to support only the 17 character instance ID: https://s3.amazonaws.com/files.dgdean.com/pv-hvm-latest-v3.sh
If you are still using the old use the one in the guide above.
Hey Alex, Its good to hear that the script worked great and helped you.
Thanks for sharing the updated script to support for 17 character instance ID which is the latest format updated by aws team.
Thanks again. 🙂
Hi,
I used https://s3.amazonaws.com/files.dgdean.com/pv-hvm-latest-v3.sh script .but new AMI virtualization type is still paravirtual.
plz help.
If your new type is still paravirtual then may be the process was not completed properly as it should.
There must be some log file created by this process.
look at /tmp folder to see if there is any file name like pv-hvm-latest-v3.sh.xxxx.log (/tmp/pv-hvm-latest-v3.sh.xxxx.log)
and see if there are any errors in the log file which you might want to look at and fix.
Hi, on step 2 “Launch a temporary Amazon Linux instance in same region as the source PV instance” this instance has to be PV or HVM?
Hi,
The temporary instance can be PV or HVM.
As we will run a script in step-5 to generate an AMI, it doesn’t matter what’s the configuration is for the new temporary instance as long as it’s in the same region as the source instance.
I have updated the step 2 section now.
Thanks for asking this question, It helped me update this post. 🙂
The latest version of the original sh script in step 4 is available at the below link (exclude any vX from the uri).. this will add support for long instance ids, which is not supported by the original script;
https://s3.amazonaws.com/jacquecp/pv-hvm-latest.sh
Thanks for mentioning about the latest version of the script. (Y)
AWS support on Thursday 10.6.22 said to me : (unsupported help)
# wget https://s3.amazonaws.com/jacquecp/pv-hvm-latest.sh /// if you are not able to access this link, feel free to copy the code from git hub link ” “https://gist.github.com/comeara/e06bdf2666923a810e58507ee6833988 ” into a file named ‘pv-hvm-latest.sh ‘ using any text editor of your choice (Ex: vi)
I’m getting stuck at “Preparing source device..”
I think because /dev/sdj is a symlink to /dev/nvme1n1?
lsblk output is
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 256G 0 disk
├─nvme0n1p1 259:3 0 256G 0 part /
└─nvme0n1p128 259:4 0 1M 0 part
nvme1n1 259:1 0 8G 0 disk