How to Create and Use a VHD in Windows (Step by Step)

WINDOWSCreate & Use a VHDin WindowsVirtual Hard Disk: create, attach, detach, back updiskpart> create vdisk file="lab.vhdx"techyami.in

A VHD (Virtual Hard Disk) is a single file that Windows can treat like a real, separate drive. You create the file, “attach” it, and a new disk shows up in Explorer with its own drive letter. Detach it and it collapses back into one portable file you can copy, move, or back up like any other document.

That makes VHDs genuinely useful for everyday IT work: a disposable sandbox for testing, a tidy container for a lab or a project, a quick way to move a “whole drive’s worth” of files as one file, or an isolated space you can wipe in seconds. This guide walks through creating, attaching, formatting, detaching, and backing up a VHD using nothing but built-in Windows tools.

Table of Contents

  1. VHD vs VHDX, fixed vs dynamic
  2. The VHD lifecycle at a glance
  3. Step 1: Create a VHD with Disk Management
  4. Step 2: Initialise, partition and format
  5. Step 3: The command-line way (diskpart)
  6. Step 4: Detach and re-attach
  7. Step 5: Copy and back up the VHD file
  8. Practical uses for testing and labs
  9. Quick reference table
  10. FAQ

VHD vs VHDX, fixed vs dynamic

Two choices matter before you start:

  • VHD vs VHDX: .vhd is the older format, capped at 2 TB and widely compatible. .vhdx is newer, supports up to 64 TB, and is more resilient to power loss. On Windows 10/11 and modern Server, prefer VHDX unless you specifically need the old format.
  • Fixed vs dynamic: A fixed disk reserves all its space up front (a 50 GB VHDX takes 50 GB immediately). A dynamically expanding disk starts tiny and grows as you add data. Dynamic is convenient for labs; fixed is slightly faster and avoids surprise “disk full” moments on the host.

The VHD lifecycle at a glance

Create file Attach Initialise +format Use the drive Detach Copy /back up

Step 1: Create a VHD with Disk Management

  1. Press Win + X and choose Disk Management (or run diskmgmt.msc).
  2. On the menu bar: Action → Create VHD.
  3. Click Browse, pick a location and file name (for example C:\VHD\lab.vhdx).
  4. Set the size (for example 20 GB), choose VHDX, and choose Dynamically expanding.
  5. Click OK. Windows creates the file and attaches it automatically — it appears as a new disk, marked Not Initialized.

Step 2: Initialise, partition and format

  1. In Disk Management, find the new disk (it will say Unknown / Not Initialized). Right-click the disk label on the left and choose Initialize Disk.
  2. Choose GPT (use MBR only for old compatibility) and click OK.
  3. Right-click the Unallocated space → New Simple Volume → Next through the wizard.
  4. Assign a drive letter, format as NTFS, give it a label like LAB, and finish.

You now have a working drive in File Explorer. Use it exactly like any other disk.

Step 3: The command-line way (diskpart)

Everything above can be scripted. Open an elevated Command Prompt or PowerShell and run diskpart, then:

create vdisk file="C:\VHD\lab.vhdx" maximum=20480 type=expandable
attach vdisk
create partition primary
format fs=ntfs quick label="LAB"
assign letter=V
exit

Notes: maximum is in MB (20480 = 20 GB). Use type=fixed for a fixed-size disk. To mount an existing VHD later, you only need select vdisk file="..." then attach vdisk.

If you have the Hyper-V PowerShell module installed, the equivalent one-liners are New-VHD, Mount-VHD and Dismount-VHD — but diskpart works on every edition without extra features.

Step 4: Detach and re-attach

Detaching unmounts the drive and leaves just the file:

  • GUI: in Disk Management, right-click the disk label → Detach VHD. Leave “delete the file” unchecked.
  • diskpart: select vdisk file="C:\VHD\lab.vhdx" then detach vdisk.

To use it again, re-attach it (Action → Attach VHD, or attach vdisk). A detached VHD on the desktop can also be mounted just by double-clicking it in Explorer on Windows 10/11.

Step 5: Copy and back up the VHD file

This is the real advantage of a VHD: your whole “drive” is one file. Always detach before you copy — copying a VHD while it is attached and being written to can corrupt it.

  1. Detach the VHD (Step 4).
  2. Copy lab.vhdx to a backup location — external drive, NAS, or another folder.
  3. To restore, copy it back and attach it. To branch a test, copy the file first and attach the copy, so the original stays clean.

A detached VHDX also compacts well and moves between machines cleanly, which is why it is handy for shipping a prepared lab to someone else.

Practical uses for testing and labs

  • Disposable sandbox: install or test software on a VHD; when you are done, detach and delete the file — your main disk is untouched.
  • Project container: keep a project’s files in one VHD so they stay together and are easy to archive.
  • Snapshots by copy: copy the detached file before a risky change; revert by swapping the file back.
  • Clean transfer: hand a whole dataset or lab to a colleague as a single file.

For moving data between machines over the network instead of by file copy, a quick link-speed check first is worth it — see testing network speed with iperf3.

Quick reference table

Task Disk Management diskpart
CreateAction → Create VHDcreate vdisk file="..." maximum=... type=expandable
AttachAction → Attach VHDselect vdisk file="..." → attach vdisk
FormatNew Simple Volume wizardcreate partition primary → format fs=ntfs quick
DetachRight-click → Detach VHDdetach vdisk

FAQ

Does using a VHD slow my PC down?
Barely, for light use. A dynamic VHDX has a small overhead versus a native disk; a fixed VHDX is closer to native. For heavy I/O, a real partition is faster — but for labs and testing the difference rarely matters.

What happens if I delete the VHD file?
Everything inside it is gone, just like formatting a real drive. Detach it first, and never delete a file you still need. Keep a backup copy of important VHDs.

Can I boot Windows from a VHD?
Yes — “native boot” from VHD exists — but it is an advanced setup with licensing and configuration caveats. For most testing you just attach the VHD as data; booting from it is a separate topic.

VHD or VHDX — which should I pick?
VHDX on any modern Windows. Choose plain VHD only when an older tool or hypervisor specifically requires the 2 TB .vhd format.

Related: Test network speed between two computers with iperf3

Post a Comment

0 Comments