Migrating Amazon Linux AMI PV (Paravirtual) EC2 Instance to HVM (Hardware assisted Virtualization) Instance

Reading Time: 2 minutes

PV to HVM Image

As of now there is no easy way to directly migrate an existing PV EC2 (T1) instance to HVM (T2) instance. Using the following steps we will migrate data from an existing PV (Paravirtual) instance to a newly launched HVM (Hardware assisted Virtualisation) instance.

Preparation

STEP 1 – Prepare SOURCE Volume

PV Instance

PV_to_HVM_Step_1

  1. Stop the PV instance
  2. Using the AWS Console go to the PV instance root volume and create a snapshot
  3. From the snapshot create a new volume, we will call this as the source volume

 

STEP 2 – Prepare TARGET Volume

HVM Instance

PV_to_HVM_Step_2

  1. Create and Launch a new Hardware Assisted Virtual (HVM) machine of similar configuration as the PV instance. Ensure that the new HVM instance has the same base AMI as that of the PV instance and is in the same availability region.
  2. Stop the HVM
  3. Using the AWS Console go to the newly created HVM’s root volume and create a snapshot
  4. From the snapshot create a new volume, we will call this as the target volume
  5. Using the AWS Console:
    Attach SOURCE volume to the new instance as /dev/xvdf
    Attach TARGET volume to the new instance as /dev/xvdg
  6. Start the HVM

 

STEP 3 – Migrate Data from Source Volume (PV) to Target Volume (HVM)

PV_to_HVM_Step_3

 

  1. SSH into the new HVM instance and get root access by using:
    sudo su
  2. Mount the source and target drives using the following commands:
    mkdir -p /mnt/source && mount /dev/xvdf /mnt/source
    mkdir -p /mnt/target && mount /dev/xvdg1 /mnt/target

Please use ls -al /dev/xvd*  to see the drives if the above drive labels are different on your machine.

  1. Delete everything but /boot on the target volume using the following command
    cd /mnt/target && ls | grep -v boot | xargs rm -Rf
  1. Delete /boot on the source volume:
    rm -Rf /mnt/source/boot
  1. Copy the source volume’s data to the target volume preserving all the attributes:
    rsync -aAXHPv /mnt/source/ /mnt/target
  2. After the data has been copied across from the source to the target volume navigate to the following directory on the target volume:
    cd /mnt/target/boot/grub We will update the grub.conf file to tell the kernel to disable SELinux on boot.Append the following to the kernel line in your /boot/grub/grub.conf for your current kernel.enforcing=0
  3. After appending the above setting your grub.conf file should look like this:grub.conf
  4. Stop the system and detach all volumes using the AWS console.

 

 

STEP 4 – Attach the Target Volume to HVM instance as root device

PV_to_HVM_Step_4

  1. Attach the TARGET volume on the new instance as /dev/xvda.
    Please check where the original root device was mounted on the HVM instance. In most cases, it should be /dev/xvda.
  2. Start your HVM instance.It should be an exact replica of the PV instance.
    The PV instance and the source volume can be deleted.