Skip to main content

Free guides and live chat support for Windows storage problems.

PCVITA Logo
VHD

How to Create VHD or VHDX and Attach It Permanently in Windows?

  • Ashwani TiwariPublished ByAshwani Tiwari
  • Tej Pratap ShuklaApproved ByTej Pratap Shukla
  • Published
  • Updated
  • Reading Time6 min
Quick Answer

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.
Do You Know?

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.

  1. Sign in with an account from the Administrators or Backup Operators group.
  2. Choose a folder outside the Windows directory. Microsoft states that the path must not sit inside that directory.
  3. Check the free space on the host drive. Fixed size files need all their space at once.
  4. 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.

  1. Open Disk Management from the Start menu with Administrator permissions.
  2. Select Action and Create VHD.
  3. Click Browse, select a folder and type a file name. Select Virtual Disk files (*.vhdx) in the Save as type list and click Save.
  4. Enter the Virtual hard disk size. The minimum is 3 MB.
  5. 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.

  1. Right click the unallocated space and select New Simple Volume.
  2. 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.

Heads Up

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.

  1. Type diskpart and press Enter.
  2. Type create vdisk file="C:\VHDs\data.vhdx" maximum=10240 type=expandable to create a 10 GB file. The size is in MB.
  3. Type select vdisk file="C:\VHDs\data.vhdx" and then attach vdisk.
  4. Type create partition primary and then format fs=ntfs quick.
  5. Type assign letter=V and then exit.

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.

Pro Tip

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.

  1. Open Notepad and type select vdisk file="C:\VHDs\data.vhdx" on line one and attach vdisk on line two. Save it as C:\VHDs\mount.txt.
  2. Open Task Scheduler and select Create Basic Task. Name it Mount Virtual Hard Disk.
  3. Select the trigger that starts the task when the computer starts.
  4. Select Start a program. Type diskpart in Program/script and /s C:\VHDs\mount.txt in Add arguments.
  5. Check Open the Properties dialog and click Finish.
  6. 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?

MethodWorks WhenSkill LevelCost
#1 Disk ManagementYou want a form with every optionBeginnerFree
#2 DiskPartYou repeat the setup or need read onlyMediumFree
#3 Task SchedulerThe disk must return after a restartMediumFree

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.