06-06-2020, 03:47 AM
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:
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:
[*]Create a 100MB system partition, which the Windows 7/2008 R2 installation procedure normally creates automatically:
[*]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.
[*]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"
[*]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:
[*]It's all done right now, so we'll exit Diskpart and then we'll close the command prompt window that we opened previousely:
[*]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:
4- Things to keep in mind while working with VHDs
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.
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:
- open the Disk Management tool by typing diskmgmt.msc at a command prompt to access it.
- in the Action option of the menu, you'll have the possibility of creating a new VHD or attaching an already existing one.
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:
Code: (Select All)
> diskpart
> list disk
> select disk <disk_number>
> clean
Code: (Select All)
> create part primary size=100
> format fs=ntfs label="System" quick
> active
Code: (Select All)
> create part primary
> format fs=ntfs label="vFiles" quick
> assign letter=D
Code: (Select All)
> 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
Code: (Select All)
> list vol
Code: (Select All)
> exit
> exit
[/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:
Code: (Select All)
> 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
- 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!
- 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....
- 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.
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.