arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Win-6.x: Booting from a Virtual Hard Disk (VHD)
#1
Prologue:
This is a topic that was first published on the now defunct FreeFTPSpace Forums around 2014. I'm reposting it here, following the promise made in this post, in the hope to still be useful to others.

It should be noted that even though the topic focus was on Win7, the technique is also valid to any Windows 6.x, including Win10.


With windows 6.1 (Win7/Windows Server 2008 R2) [1], there is a new question that faces any sysAdmin when considering their deployment: "Do we want to install to a physical volume or a VHD?"

The routine, when you install an OS, is to select a volume/partition on a hard-disk drive and let the installation process dump it there. Your system's files and folders will then be visible/accessible when you explore that volume with any NTFS-aware file manager out there. The brand new stuff that shipped with Win 6.1 is that it gives you the option of performing that installation to a VHD file instead of a physical HDD's volume and boot natively from it.

1- What Are VHDs?
The virtual hard disk (VHD) format enables a single file to simulate a physical HDD, with its own volumes, file systems, and content. It was originally part of MS Virtual PC virtualization solution, which has been enhanced for use by Hyper-V, the new MS server virtualization platform.

Thus, to the computer, an "online"(/mounted) VHD file appears as a separate volume that can be treated exactly as any other volume on your hard disk. And, because you can store as many VHD files as you want on a disk, you can configure any Win 6.1 system to boot into different systems that you have installed in them without any repartitioning of your HDD.

Before showing how to mount and boot those VHD files, I must quickly say that for Windows 7, only the Enterprise and Ultimate editions can be configured to boot from them.

2- Mounting a VHD
The easiest way to attach/detach VHDs is through the Disk Management console:
  1. open the Disk Management tool by typing diskmgmt.msc at a command prompt to access it.
  2. in the Action option of the menu, you'll have the possibility of creating a new VHD or attaching an already existing one.
VHDs can be mounted with full read/write access or read-only. When attached, the VHD is assigned a drive letter like any other volume and can then be accessed through Windows Explorer.

3- Booting from VHD
This is really the feature that I was so delighted to find out in Windows 6.1 systems. It's very useful for multi-boot scenarios and provides an incredible ease in the portability of the operating system! As because the VHD image is a single file, you can easily back up the entire operating system environment by copying that single (+/- huge) file OR use it in a virtual environment (via HyperV, VirtualBox etc..)

The booting aspect of it boils down to the possibility of configuring the "new" Windows 6.1 systems' bootloader to start Windows from a VHD file exactly as if the VHD file were a standard partition.

Following are the 2 common scenarios that one might face:
> Installing Windows directly into a VHD (see 3.1) and
> Adding an existing VHD file (coming from another system or a virtual machine) to the boot menu so that we can boot from it (see 3.2.)
3.1- Creating a Bootable VHD Image from scratch
For the step-by-step that follows, we'll suppose that we start with an unformatted disk and we wish to install Win7 directly on a VHD file.
[ol]
[*]Boot from the Windows 7/2008 R2 media.
[*]Select the language option then click Next.
[*]At the Install Now screen, press Shift + F10 to open a command prompt window. This is done to partition our disk and create the VHD file that the operating system will be installed to.
[*]To select the targeted disk (in case we have many) and wipe its content do the following:
> diskpart
> list disk
> select disk <disk_number>
> clean
[*]Create a 100MB system partition, which the Windows 7/2008 R2 installation procedure normally creates automatically:
> create part primary size=100
> format fs=ntfs label="System" quick
> active
[*]We'll use all the remaining space to create a partition that will hold the VHD file. We'll call it "vFiles" and we'll assign the letter "D" to it.
> create part primary
> format fs=ntfs label="vFiles" quick
> assign letter=D
[*]Now we'll create a VHD file on this newly created volume. In this example, the file will be an expanding disk with 20GB in size. Note that it's possible to use type=fixed instead of type=expandable to create a fixed-size VHD. Then, we'll attach it and partition and label it as "Win7-VHD"
> create vdisk file=d:\win7-ult.vhd maximum=20000 type=expandable
> select vdisk file=d:\win7-ult.vhd
> attach vdisk
> create partition primary
> format fs=ntfs label="Win7-VHD" quick
[*]If you list the volumes on your selected disk now, you'll see your VHD partition online and waiting for you to install your OS in it:
> list vol
[*]It's all done right now, so we'll exit Diskpart and then we'll close the command prompt window that we opened previousely:
> exit
> exit
[*]From here, you continue your OS installation as usual, but don't forget to select the "Win7-VHD" partition when asked for the installation target. Note however that a warning will appear stating that you cannot install it on the "Win7-VHD" partition when you select it, don't worry about that just ignore it and proceed as usual.
[/ol]

3.2- Creating a Bootable VHD Image from an existing file
Now suppose you have an existing VHD file that you wish to add to the boot menu and that you want to be able to boot from. This VHD could have come from any another system or even a virtual machine. The command sequence is as follows:
> bcdedit /copy {default} /d "Win7-Ultimate (SP1) VHD"
> bcdedit /set {enter GUID output from previous line} device vhd=[LOCATE]\path_to_vhd_file
> bcdedit /set {previous entered GUID value} osdevice vhd=[LOCATE]\path_to_vhd_file
> bcdedit /set {previous entered GUID value} detecthal on

4- Things to keep in mind while working with VHDs
  1. You should know that when you boot from a VHD, the pagefile is never created within the VHD file itself but outside within the first partition with enough spare space, starting from the hosting partition. Thus it is imperative to have extra empty space somewhere within the drive, or the VHD's system will boot and run without a pagefile!
  2. Converting a regular Installation to a VHD File:
    It is possible to convert a physical installation of Windows to a VHD using the Disk2vhd tool from the excellent Sysinternals suite. The VHDs created by Disk2vhd are fully bootable.
    Thus you can use Disk2vhd to capture the system disk from an OS installation and then copy that VHD to a virtual server like M$$ Hyper-V and use it as the boot volume for a virtual machine or use it to Boot a physical machine from the created VHD....
  3. VHD Limitations
    Bootable VHDs have a lot of benefits, but also some limitations. First and foremost, you can only create a bootable VHD with Windows 7 Enterprise and Ultimate editions. Other Windows 7 editions don’t support it. In addition, Bootable VHD images don't support hibernation and BitLocker, they can't be compressed and must be located on an NTFS drive.
That's it and Good Luck!

Authors Note for Win10:
If you want to use bootable VHD for Win10, please keep in mind that you won't be able to upgrade it when the next version is released.

I've already tried it, but each time Win10 refuses to do an in-place upgrade, which led me to end up with 3 consecutive Win10 versions on 3 separate VHDs. You've been warned!

Recently though, I migrated a Win10 VHD to QEMU/KVM but still didn't have time to test if I will be able to upgrade it in that environment.

Another possibility that I've recently tested (as of last week) is the brand new possibility to install Win10 inside an LXC/LXD VM (more on this in another topic.)



[1]- Vanilla Windows 7 and Server 2008 R2 have identical version and build numbers, i.e. 6.1 (Build 7600), because they were built from the same Windows code base.
VirMach's Buffalo_VPS-9 Holder (Dec. 20 - July 21)
microLXC's Container Holder (july 20 - ?)
VirMach's Phoenix_VPS-9 Holder (Apr. 20 - June 20)
NanoKVM's NAT-VPS Holder (jan. 20 - ?)
#2
Nice tutorial, although I rarely needs booting directly from VHD.

The main reason I do not use it is that hibernation is too important for me. I need hibernation working for all Operating Systems I use. Smile

But still I realize that booting from VHD does have some good usage cases. Thank you for posting about it here.


#3
(06-06-2020, 03:47 AM)fChk Wrote: [1]- Vanilla Windows 7 and Server 2008 R2 have identical version and build numbers, i.e. 6.1 (Build 7600), because they were built from the same Windows code base.

This part of the OP should have raised few eyebrows, at least I hope :-)

Think about it a bit... if win7 and win2k8 R2 share a common set of core system files (explaining the same build number that they have), how does the system know which version of the two and which edition of that version (Pro, Ultimate, Enterprise etc.. for Win7) has to be booted ? It's an interesting question to ask for the inquisitive minds.

Well, here is the thing, the answer is entrusted in a very strategic file called the system license policy file: "tokens.dat"; it's stored in a very deep folder: "\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\Software ProtectionPlatform\". Thus the decision to take a client or server configuration as well as to enable or disable the features ad-hoc to the edition that is loading is done at boot-time by consulting "tokens.dat" file [1].

If you open your registry (by typing regedit) and take a look at the value of "ProductType" under the HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions key, you'll see that it is "WinNT". For Win 2k8 R2, that should be "LanmanNT" or "ServerNT", depending on its role (with or without Active Directory respectively.) This value (among others) is loaded into the registry based on that famous licensing policy file mentioned earlier.

For the features enabled by edition of a given version, they are loaded in the value of "ProductPolicy". It's in Hex and contains a cached copy of the data inside the tokens.dat file.

Now, you're in the know too...


[1]- Remember that tampering with tokens.dat is a direct violation of the software license.
VirMach's Buffalo_VPS-9 Holder (Dec. 20 - July 21)
microLXC's Container Holder (july 20 - ?)
VirMach's Phoenix_VPS-9 Holder (Apr. 20 - June 20)
NanoKVM's NAT-VPS Holder (jan. 20 - ?)
#4
it is a really nice tutorial. i think i will find some time eventually to experiment on how to boot this vhd from within grub2 or grub 4dos.

it may appear pointless to jump all this hoops to use Windows. why not install directly on a partition or usb stick if one has to keep that vhd on an ntfs partition. but i think one could think about security from isolation as a big advantage. you could do whatever you want and get you system as riddled with malwares as you want when inside it. also i see a chance to keep the default boot to lead inside one such vhd for any other user that may want to use your system. security...
Sincere Thanks to VirMach for my VPS9. Also many thanks to Shadow Hosting and cubedata for the experiences I had with their VPSs.
#5
booting to vhd is a nice feature . what i think for the use case it is great and open lot of posibility ., for example is virus testing or doing compartment so you only use vhd for browsing for example and another vhd for work . but it is unfortunate that it doesnt support windows version update . microsoft probably abandon this feature . they dont bother to add support to vhd booting
Terminal
humanpuff69@FPAX:~$ Thanks To Shadow Hosting And Post4VPS for VPS 5
#6
(06-11-2020, 07:18 PM)rudra Wrote: it may appear pointless to jump all this hoops to use Windows. why not install directly on a partition or usb stick if one has to keep that vhd on an ntfs partition. but i think one could think about security from isolation as a big advantage. you could do whatever you want and get you system as riddled with malwares as you want when inside it. also i see a chance to keep the default boot to lead inside one such vhd for any other user that may want to use your system. security...

(06-12-2020, 12:55 PM)humanpuff69 Wrote: booting to vhd is a nice feature . what i think for the use case it is great and open lot of posibility ., for example is virus testing or doing compartment so you only use vhd for browsing for example and another vhd for work . but it is unfortunate that it doesnt support windows version update . microsoft probably abandon this feature . they dont bother to add support to vhd booting

It's quite interesting that in both quotes above there is a misunderstanding of what booting from a VHD is all about. Thus I advice them to re-read section 1.

When a VHD is used to boot from physical hardware -which is this thread's topic- then there is no sandboxing from a security perspective. Your hardware, system boot, all accessible filesystems and shared networked volumes are all exposed to whatever malware/virus you're testing.

If you want the sandboxing security aspect of VHD, you then have to use it inside a VM!.. The Key-Point in using VHD is the portability ascpect, meaning you move it across physical machines as well as VMs. That's all !
VirMach's Buffalo_VPS-9 Holder (Dec. 20 - July 21)
microLXC's Container Holder (july 20 - ?)
VirMach's Phoenix_VPS-9 Holder (Apr. 20 - June 20)
NanoKVM's NAT-VPS Holder (jan. 20 - ?)
#7
Nice tutorial @fChk!

This is something completely new to me and appears advantageous due to the portability factor. Your explanation in the OP as well as the last post is great for a newbie like me. 

Quote:Before showing how to mount and boot those VHD files, I must quickly say that for Windows 7, only the Enterprise and Ultimate editions can be configured to boot from them.

Quick question, is that the same for Windows 10 too. Cuz I've Professional for both Win 7 and 10, and umm no plans of upgrading so just wondering if I'll be able to use it. 

Thanks again for the tutorial!
Sayan Bhattacharyya,

Heartiest thanks to Post4VPS and Virmach for my wonderful VPS 9!
#8
(02-28-2021, 04:26 PM)sohamb03 Wrote: Quick question, is that the same for Windows 10 too. Cuz I've Professional for both Win 7 and 10, and umm no plans of upgrading so just wondering if I'll be able to use it. 

Thanks again for the tutorial!

No!.. you can perfectly boot from a VHD with Win10 Pro!.. At least that was the case when I was still using it that way!..
VirMach's Buffalo_VPS-9 Holder (Dec. 20 - July 21)
microLXC's Container Holder (july 20 - ?)
VirMach's Phoenix_VPS-9 Holder (Apr. 20 - June 20)
NanoKVM's NAT-VPS Holder (jan. 20 - ?)
#9
(03-01-2021, 08:46 AM)fChk Wrote: No!.. you can perfectly boot from a VHD with Win10 Pro!.. At least that was the case when I was still using it that way!..

Thanks for the confirmations, I'll try it out once my exams are over in the next few months. Though first I'll need a good amount of backups, I've a lot of stuff on this disk that is important and well I never saved it elsewhere including coursework material and other personal documents.
Sayan Bhattacharyya,

Heartiest thanks to Post4VPS and Virmach for my wonderful VPS 9!


Possibly Related Threads…
Thread
Author
Replies
Views
Last Post
2,555
04-07-2017, 12:19 PM
Last Post: Han105

person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting