Booting from a VHD GOTCHAS

So I wanted to convert my virtual machine into a native boot, how hard can that be? Well because I am so lucky (maybe not!) I faced and done all the wrong steps and took all the bad turns. In this post I will concentrate more on the bad things I made and the problems I faced maybe to help you avoiding them.

So I started off by reading how to do this over the internet and I found several very good blogs on how to perform this task and I will not go through all the the steps in detail as you will find them more detailed over so many places. Now what was different is that all blogs were talking about building your VHD and installing the OS from scratch. But in my case I already had my VHD ready and it is working in Hyper-V and I have installed all software I need but I had a memory problem (see I am running on a 4GB laptop :( ). So I prepared myself and came up to a checklist of steps to make as follows.

  1. Edit the boot entry in my machine and add a new one pointing to my already existing VHD.
  2. Start my VHD in Hyper-V as usual and SYSPREP it to remove all drivers' dependencies.
  3. Restart my machine and then choose the new VHD boot and start it in safe mode.
  4. Allow it to install device drivers and restart. AND viola all done

Let me walk you through my experience. So I started by adding the new boot using BCDEDIT command lines

bcdedit /copy {default} /d "MY vhd boot"

bcdedit /set {guid} device vhd=[F:]\My.vhd

bcdedit /set {guid} osdevice vhd=[F:]\My.vhd

Then I said I am not going to perform sysprep! So restarted my machine and BAM it is saying that there is a bad entry in the boot store and press enter to continue that led me back to my original OS. So I checked and found that my BIOS had disabled by default bringing up and booting from USB drives and since my VHD is on an external USB drive it failed.

So I enabled this option and it tries to load and BAM blue screen of death. So I am thinking my mistake as I did not perform SYSPREP right. So I performed SYSPREP and restarted my machine (you will be hearing this many times as we go on) and BAM again the same BSOD with the same error code. I tried to start in safe mode and it got stuck on loading disk.sys device driver!!!! I binged the internet and after so many reties (that took two full days of my life) I figured it out.

 

GOTCHA #1:

If VHD booting is stuck at DISK.SYS while booting in safe mode then remember that you CANNOT boot a VHD from an external HDD.

 

So I moved my VHD to my internal HDD and had to delete and move lots of stuff to do this. I changed my boot store information, restarted my machine and BAM still BSOD. But wait this is a different error this time it is saying that it was not able to expand the VHD. I returned to the good old internet and found that during the booting process from a VHD if this VHD is dynamically expanding; it needs to be expanded to the maximum capacity while booting up. You are kidding me right! Now I had created this VHD as a dynamically expanding VHD with a maximum size of 127GB! Now my physical HDD has a total space of like 80GB so even if I formatted my machine I would not be able to boot up this machine. So I binged the internet again and this time for a way to reduce the maximum size of my dynamically expanding VHD. And to my surprise I found nothing, NILL, NULL. (I even found a guy talking about a way to do this using Linux OS, right so I have to install Linux to get this VHD booting up). Then I thought about a solution; how about using the windows backup and recovery process. So here is what I done.

  1. Started by attaching the VHD to my already running OS using storage manager.
  2. Opened Windows backup and created an on-demand backup of all the volumes on this VHD (two BTW one as system reserved and the one that is my OS C volume)
  3. Then I created a new VHD with a fixed size of 40GB and attached that using the storage manager.
  4. I created two volumes on this new VHD one with 100MB as system reserved and one with the rest.
  5. I used the Windows backup to perform a recovery of the backed up volumes to the new created volumes.
  6. Then I tried to boot the new VHD in Hyper-V and it did not work. I inserted the Windows setup disk and started repair console. I checked the boot store using BCDEDIT and it was wrong so I had to rebuild that.
  7. First I noticed that it assigned a letter C to the system reserved volume and that the C volume is now assigned letter D.
  8. I used DISKPART to fix this by using the commands below

DISKPART
LIST VOL
SELECT VOLUME 1

REMOVE LETTER=C

SELECT VOLUME 2

ASSIGN LETTER=C

EXIT

  1. Then I fixed the boot manager record in the record store as follows

BCDEDIT /set {bootmgr} device partition=\Device\HarddiskVolume1

  1. I fixed the default boot record as follows

BCDEDIT /set {default} device partition=C:
BCDEDIT /set {default} osdevice partition=C:

  1. I removed the Windows DVD and restarted the VM in Hyper-V.

Now it worked fine and on a 40GB fixed size VHD.

 

GOTCHA #2:

Do not create a dynamic size VHD with the maximum you think. You can always increase its maximum size but it is hard to decrease it.

 

So back to track (and lost another day and half). Changed again my host OS boot record to point to the new 40GB fixed size VHD and restarted my machine and BAM again BSOD. Again tried SYSPREP and no luck still BSOD but with changed error this time. I started in safe mode (maybe I should always start in safe mode the first time) and now it is stuck in loading CLASSPNP.SYS. Again binged the internet and found the problem. My laptop has SATA AHCI enabled and my VM did not have that and by default there is no way this can be changed once the OS is installed (I found a way to do this but did not try it myself on this forum https://forums.pcper.com/showthread.php?t=444831 – it seemed too risky anyway and frankly I was getting tired). So I restarted my machine and entered the BIOS utility and disabled AHCI. Booted in my VHD FINALLY it worked.

 

GOTCHA #3:

If VHD booting is stuck at CLASSPNP.sys while booting in safe mode disable SATA AHCI or change it to compatibility mode.

 

Oh and one final note, I did NOT perform SYSPREP and it worked like charm.