Last Updated: August 02, 2016
·
6.489K
· wehappyfew

Convert a Paravirtual Amazon Linux EC2 instance to HVM

<figure data-orig-width="1250" data-orig-height="625" class="tmblr-full">image</figure><h2>
<b>Prepare the instances, the snapshots and the volumes</b>
</h2><blockquote>

<b><i>Notice: <br>Make sure that all the volumes are in the same availability zone.</i></b></p></blockquote>

1. It is not mandatory, but you can SSH into the PV machine that you want to turn to HVM and apply all updates, then log out.</p>

2. Launch a new HVM instance . <br>Select the same base AMI that the PV system was created from (for our case, the Amazon 64-bit Linux AMI).</p>

3. Again, not mandatory but you can SSH to the new HVM instance and apply all updates, then log out.</p>

4. Go to the AWS Console and stop the <b>PV instance</b>. <br>Take a snapshot of the root device and create a new volume (<i><b>SOURCE VOLUME</b></i>) from this snapshot.</p>

5. Stop the <b>HVM instance</b>. <br>Take a snapshot of the root device on the new instance and create a new volume (<i><b>TARGET VOLUME</b></i>) from this snapshot.</p>

6. Using the AWS Console:</p><ul><li>Attach <i><b>SOURCE VOLUME</b></i> to the new instance as<b> /dev/xvdf</b>.<br></li><li>Attach <i><b>TARGET VOLUME</b></i> to the new instance as <b>/dev/xvdg</b>.<br></li></ul><h2><b>Migrate from Paravirtual to HVM</b></h2>

1. SSH to the new <b>HVM </b>instance and get root access (sudo su)</p>

2. Mount the source and target drives.<br><br><i><b>mkdir -p /mnt/source && mount /dev/xvdf /mnt/source </b></i><br><i><b>mkdir -p /mnt/target && mount /dev/xvdg1 /mnt/target<br></b></i><br>In my case, the devices were /dev/xvdf (source) and /dev/xvdg1 (target). These may change in your configuration based on the number of partitions and where you attached them (see step 6 in our preparation). <br>You could use <i><b>ls -al /dev/xvd*</b></i>  to see the drives.</p>

3. Delete everything but <b>/boot</b> on the target volume:<br><i><b>cd /mnt/target && ls | grep -v boot | xargs rm -Rf</b></i></p>

4. Delete<b> /boot</b> on the source volume:<br><i><b>rm -Rf /mnt/source/boot</b></i></p>

5. Copy the source volume's data to the target volume preserving all the attributes:<br><i><b>rsync -aAXHPv /mnt/source/ /mnt/target <br></b></i>( It will take a while , so have a drink and browse my other posts! : ] )<br></p>

6. Stop the system and detach all volumes using the AWS console.</p>

</p>

</p>

<i> Attach the <b>TARGET VOLUME</b></i> on the new instance as /dev/<b><i>xvda</i></b>.</p>

<i>Please be sure to note where the original root device was mounted. <br>In most cases, it should be /dev/xvda.</i></p>

7. Start your HVM instance. <br>It should now be an exact duplicate of your PV system! Hooray!<br></p><h2>CleanUp</b></h2>

You can now delete your PV instance and also SOURCE VOLUME.</p>

1 Response
Add your response

While testing out this technique, I noticed that the --sparse option to rsync is rather useful if there are sparse files on the source disk. ;-)

over 1 year ago ·