लोड हो रहा है...... कृपया प्रतीक्षा करें........

October 14, 2021

Migrate EC2 Classic Paravirtual (PV) Linux instances to Hardware-assisted virtual machine (HVM)

Migrate EC2 Classic Paravirtual (PV) Linux instances to Hardware-assisted virtual machine (HVM)

In this Blog, we explain how to Convert EC2 Instance PV to HVM Virtualization Type .

AWS will be retiring the EC2-Classic Platform on August 15, 2022. There are fair chances that if you are running any instance on ec2 classic network then that might be running on PV virtualization type and t1.micro instance type. Here we will convert t1.micro to t2.micro instance type as t1.micro is PV (Paravirtual) machine and t2.micro is HVM (Hardware-assisted Virtual Machine).

Here are the requirements for converting a PV instance to HVM.

We will need three Instances. A PV Instance(which needs to be converted), A HVM Instance, and a Conversion Instance.

1. Preparation

Take a snapshot of the current PV Instance and create a new volume from the snapshot and tag it with the name OS-PV. (It’s always better to take snapshots in a stopped state).

Next create an HVM instance, using as close as possible your current OS, (i.e., make sure the kernel versions match).

Create the HVM instance in the same Availability Zone (AZ) as your PV instance and with the same size of EBS volume.

Once it has started and is running you can stop it. Tag the Volume with something like OS-HVM and detach it from the HVM instance.

Launch a new conversion instance and wait for it to fully start. (It is important that the instance is fully started before attaching the other volumes.) You can Tag it as OS-Conversion.

2. Conversion

Now SSH into the conversion instance.

ssh -i mykey.pem ubuntu@10.10.10.0

Attach the HVM volume to the conversion instance as /dev/xvdf. For example:

cd /    
sudo mkdir /hvm
sudo mount /dev/xvdf1 /hvm

Ensure you keep the HVM boot directory by moving it to the tmp directory.

sudo mv /hvm/boot  /tmp/boot.hvm

Empty out the rest of the drive with the below command

sudo rm -Rf /hvm/*

Verify the drive is now empty.

sudo ls -al /hvm

Find the new EBS volume which you have already created and tagged as OS-PV. Attach it to the conversion instance as /dev/xvdg from AWS console and mount it like this.

sudo mkdir /pv
sudo mount /dev/xvdg /pv

Verify that it is mounted and has the correct file structure.

# You should see the boot and other root directories.
sudo ls /pv

Then copy the contents of /pv to /hvm

sudo cp -p -R /pv/* /hvm

Change the boot directory to be HVM based. Remove the PV boot directory and replace it with the HVM boot directory.

sudo rm -R /hvm/boot

Copy back the saved HVM boot directory.

sudo mv /tmp/boot.hvm  /hvm/boot

Verify there are now all the needed directories and files on the HVM volume with.

sudo ls -al /hvm

You can now unmount the hvm volume.

sudo umount /hvm

Find the OS-HVM volume and detach it from the conversion instance. Attach it back to the HVM instance as device /dev/xvda or /dev/sda1 whatever your root volume type is. Then Start the HVM instance.

Now you have a new HVM instance running with an exact copy of your old PV instance.

Clean up the conversion instance and any unwanted or leftover volumes/snapshots.

Posted in Tutorial
Write a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.