Shrinking VHD

To shrink VHD file occupied by virtual Windows OS you need to shrink the volume (i.e. disk C:) inside virtual machine and physical VHD file on host machine. It works fine when you don’t use differential VHDs.

Inside virtual Windows OS run command prompt:

Then shut down virtual machine.

On host Windows OS run command prompt:

Installing IIS On Windows 10 Using DISM

After installing Windows 10 there arise a need to install Internet Information Services for ASP.NET 4.6 development. When you use “Turn Windows feature on or off” in Control panel, Windows tries to download necessary files from Windows Update. In some cases it does not work. So I have to use offline method with DISM tool.
TechNet offers a good description in this article Enable or Disable Windows Features Using DISM. You need to work only Online. Offline means to prepare an image from which you will install OS later.

1. Open Command Prompt with Administrator rights.
2. You can view a list of all features installed on your Windows OS.

3. Install IIS-DefaultDocument feature with all related features by using /All switch.

It installed 15 extra features in addition.

4. Install IIS-ASPNET45 feature the same way.

5. Install any additional IIS feature one by one.

Turning On .NET Framework 3.5 On Windows 10

After some unsuccessful attempts to turn on .NET Framework 3.5 on a newly installed Windows 10 (even if I have a stable Internet connection) and a failed try to run .NET Framework installer, I found a very graceful way to do this.

1. Open Command prompt
2. Run this command

If everything goes smoothly, you’ll see these lines showing the happy end.

Deployment Image Servicing and Management tool
Version: 10.0.10240.16384

Image Version: 10.0.10240.16384

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.

Add a Native-Boot VHD to Windows Boot Menu

If you have installed Windows on virtual hard disk, you can copy this VHD to another machine and add it to boot menu.

This can be made with the following steps:

1.Mount VHD:

  • just double-click on it and the disk will be automatically (works on Windows 8.1 and Windows Server 2012);
  • if the first method does not work, open Command prompt and run commands:

You can choose any free disk letter to assign for your VHD, not only Z.
2.Add entry to boot menu.
Open Command prompt, if it was not opened before, and run commands:

3.Optionally reboot the operating system and you will see a new entry in boot menu.
Now you can select this OS and run it!

Installing Windows from USB Flash

This post is about how to prepare the USB Flash to install Windows from it.  It works fine with Windows 8.1 and Windows Server 2012. Maybe it could work with Windows 7 and Windows Server 2008 (I has not checked myself).

1) Mount Windows image. Just double-click on ISO image. Remember the letter of the drive that Windows assigned to this image. In my case it’s disk G:

2) Plug in USB flash and remember the letter of the drive. It’s H:

3) Open command prompt and do NOT close it until the end.

4) Run the following commands to create a NTFS partition on USB flash:

Command Description
diskpart starts Disk Partition tool
list disk shows a list of disks, find USB flash disk and remember its number
select disk # replace # with USB flash disk number
clean deletes everything on USB flask
create partition primary creates partition
select partition 1
active makes it active
format fs=ntfs quick quick formats with NTFS file system
exit

5) Run the following commands to create a boot sector on USB flash:

Command Description
G: change drive, G: is a drive letter of Windows image
cd boot go to a folder
bootsect /nt60 H: create a boot sector, H: is a drive letter of USB flash

6) Copy all files from all directories, including empty subdirectories, hidden and system files from Windows image (drive G:) to USB flash (disk H:):

cd .. go to a drive root
xcopy G: H: /E /F /H

7) Close command prompt

Extending VHD

I’ve installed Windows 7 on VHD a couple of years ago and now I need some extra free space to install program. So I have to extend my VHD disk and the partition.

This can be done from another Windows operating system with the diskpart command.

If needed we can check the statuses of disks and volumes by entering additional commands

I think it would be possible to run the Windows installation disk, open Command Prompt by pressing Shift+F10 and make all the steps listed above.

Installing Windows on VHD

You can install Windows 7 and above on hard disk or on virtual hard disk (VHD). In the last case you need to create a VHD file on hard disk and install Windows inside that VHD file. The boot loader is placed outside the VHD automatically during the installation process.

During Windows installation you will see a prompt to select a type of installation: upgrade or custom.

Press Shift + F10. The Command Prompt will appear. Type the following commands:

The size of the VHD will be 100Gb.

After that select the Custom option to make a clean installation of Windows.

Important! The type of VHD must be fixed because I’ve encountered problems to install Windows from DVD or USB flash on expandable disk. But when you install Windows inside Hyper-V virtual machine, you won’t have any problem with expandable VHD.