How to Create VHD or VHDX and Attach It Permanently in Windows?
Create VHD or VHDX files in Windows with built in tools. You get 3 methods in this guide. Method 1 uses Disk Management to build and format the disk. Method 2 uses DiskPart commands in an admin Command Prompt. Method 3 adds a Task Scheduler job that attaches the file at startup. Choose VHDX for new disks.
You need a separate drive for test files, a backup copy or a virtual machine. A virtual disk file gives you that drive without a new physical disk.
This guide shows how to create VHD and VHDX files in Windows 11 and 10 and how to attach them at every startup. Microsoft describes the base steps on its page about managing virtual hard disks.
Why Create VHD or VHDX Files?
VHD and VHDX files act like real drives. Windows mounts the file and shows it in File Explorer with a drive letter. You store data in a single file that you copy, move or detach. Many users create VHD files for this reason.
- Test space. You try apps and settings away from your main drive.
- Portable backup. You keep a set of files in one file on any disk.
- Virtual machines. Microsoft lists Hyper-V virtual machines as the main purpose of these files.
- Clean storage. You split work data from personal data without a new partition.
Microsoft states that Disk Management creates and initializes the VHD at the same time. You then format the new disk and assign a drive letter.
What to Check Before You Start
Plan the file before you create VHD storage. Wrong paths and sizes cost you time later.
- Sign in with an account from the Administrators or Backup Operators group.
- Choose a folder outside the
Windowsdirectory. Microsoft states that the path must not sit inside that directory. - Check the free space on the host drive. Fixed size files need all their space at once.
- Choose VHDX when you create VHD storage for new setups. Use VHD only for an old system.
Method #1: Create and Initialize in Disk Management (Free, Best for Most Users)
Disk Management gives you a form with every setting on screen. Use it when you create VHD or VHDX files by hand and want every option on screen.
- Open Disk Management from the Start menu with Administrator permissions.
- Select Action and Create VHD.
- Click Browse, select a folder and type a file name. Select Virtual Disk files (*.vhdx) in the Save as type list and click Save.
- Enter the Virtual hard disk size. The minimum is 3 MB.
- Select Dynamically expanding or Fixed size and click OK.
Dynamically expanding files grow as you add data. Fixed size files take the full space on creation and a large one needs extra time.
Your new disk appears in the lower pane. If it shows as Not Initialized, right click it and select Initialize Disk. Choose MBR or GPT and click OK. GPT does not work on old Windows versions.
- Right click the unallocated space and select New Simple Volume.
- Assign a drive letter, select the file system and click Finish.
Attach an existing file in the same window. Select Action and Attach VHD, click Browse, select the file and click OK. A blue icon means the disk is available.
This attach step lasts until the next restart in many setups. Use Method 3 when the disk must come back on its own.
Method #2: Create VHD With DiskPart (Free, Fast for Scripts)
DiskPart can create VHD files from the command line. Microsoft states that you need Administrators group rights for DiskPart. Open Command Prompt as administrator first.
- Type
diskpartand press Enter. - Type
create vdisk file="C:\VHDs\data.vhdx" maximum=10240 type=expandableto create a 10 GB file. The size is in MB. - Type
select vdisk file="C:\VHDs\data.vhdx"and thenattach vdisk. - Type
create partition primaryand thenformat fs=ntfs quick. - Type
assign letter=Vand thenexit.
Microsoft states that the attach vdisk command needs a selected VHD first. It also lists the readonly option that blocks every write to the disk.
Test the commands on a small file first. Wrong disk numbers in DiskPart cause data loss on real drives.
Method #3: Attach VHD Permanently With Task Scheduler (Free, Needed After Restart)
Task Scheduler attaches the file every time Windows starts. A Microsoft Q&A answer uses this job to keep a VHD attached after a restart.
- Open Notepad and type
select vdisk file="C:\VHDs\data.vhdx"on line one andattach vdiskon line two. Save it asC:\VHDs\mount.txt. - Open Task Scheduler and select Create Basic Task. Name it
Mount Virtual Hard Disk. - Select the trigger that starts the task when the computer starts.
- Select Start a program. Type
diskpartin Program/script and/s C:\VHDs\mount.txtin Add arguments. - Check Open the Properties dialog and click Finish.
- Click Change User or Group, type
SYSTEM, click Check Names and click OK.
Restart your PC and open File Explorer. The drive letter returns without any action from you.
Which Method Fits Your Case?
| Method | Works When | Skill Level | Cost |
|---|---|---|---|
| #1 Disk Management | You want a form with every option | Beginner | Free |
| #2 DiskPart | You repeat the setup or need read only | Medium | Free |
| #3 Task Scheduler | The disk must return after a restart | Medium | Free |
Safe Handling Tips
- Use Detach VHD. Detach the disk before you move the file to another folder.
- Copy the file. Save a copy of the VHDX file before you resize or reformat the disk.
FAQs About Virtual Hard Disks
What is the difference between VHD and VHDX?
Both are virtual disk files that Windows shows as a drive. Microsoft lists .vhd and .vhdx as the file types and recommends .vhdx.
Do I need admin rights to create VHD files?
Yes. Microsoft states that your account must belong to the Backup Operators or Administrators group. Open Disk Management with Administrator permissions.
Why does my VHD disappear after a restart?
Windows can leave the file detached after a restart. A Microsoft Q&A answer fixes this with a Task Scheduler job that starts DiskPart at startup.
Does Detach VHD delete my data?
No. Microsoft states that detaching makes the disk unavailable and does not delete the VHD file or the data on it.
What size can I set for a new virtual disk?
Microsoft lists 3 MB as the minimum size. You choose Fixed size or Dynamically expanding as the type.
Which drive icon shows an attached VHD?
Disk Management shows a blue icon for an attached disk that is available. A gray icon means the disk is detached and unavailable.
Can I attach a VHD as read only?
Yes. DiskPart supports the readonly parameter in the attach vdisk command. Any write to the disk then returns an error.
Closing Words
You create VHD files in minutes with Disk Management or DiskPart. Create VHD disks, initialize them, format them and assign a drive letter before you store data.
- Methods 1 and 2 create VHD or VHDX disks with Windows alone.
- Method 3 attaches the file again after every restart.