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.
STEP 1 – Prepare SOURCE Volume
- Stop the PV instance
- Using the AWS Console go to the PV instance root volume and create a snapshot
- From the snapshot create a new volume, we will call this as the source volume
STEP 2 – Prepare TARGET Volume
- 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.
- Stop the HVM
- Using the AWS Console go to the newly created HVM’s root volume and create a snapshot
- From the snapshot create a new volume, we will call this as the target volume
- Using the AWS Console:
Attach SOURCE volume to the new instance as /dev/xvdf
Attach TARGET volume to the new instance as /dev/xvdg
- Start the HVM
STEP 3 – Migrate Data from Source Volume (PV) to Target Volume (HVM)
- SSH into the new HVM instance and get root access by using:
- 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.
- Delete everything but /boot on the target volume using the following command
cd /mnt/target && ls | grep -v boot | xargs rm -Rf
- Delete /boot on the source volume:
rm -Rf /mnt/source/boot
- Copy the source volume’s data to the target volume preserving all the attributes:
rsync -aAXHPv /mnt/source/ /mnt/target
- 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
- After appending the above setting your grub.conf file should look like this:
- Stop the system and detach all volumes using the AWS console.
STEP 4 – Attach the Target Volume to HVM instance as root device
- 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.
- Start your HVM instance.It should be an exact replica of the PV instance.
The PV instance and the source volume can be deleted.