Skip to content

Instantly share code, notes, and snippets.

@ianfabs
Last active September 17, 2024 18:42
Show Gist options
  • Save ianfabs/1f566e0232c8c072d8834d196b79348c to your computer and use it in GitHub Desktop.
Save ianfabs/1f566e0232c8c072d8834d196b79348c to your computer and use it in GitHub Desktop.
How to Automount VHD on windows 10

So here's a pretty neat thing, I use VHD's to organize the space on my computer. You can too!

  • Click Start

  • Type in the search bar "Disk par" =>

  • Click first result =>

  • In the program, click "Action" =>

  • Under action menu, click Create VHD =>

  • Make a new folder in your C: drive called VHD =>

  • now in "C:\VHD", add disk1.vhd

  • now finish setup =>

  • attach vhd

  • Now, in The same folder, create a new file "attach_vhd.txt"

  • in that file, place the following

select vdisk file="C:\VHD\coding.vhd"
attach vdisk
exit
  • save it

  • run the following command in PowerShell

schtasks /create /tn "automountvhd" /tr "diskpart.exe /s 'c:\VHD\attach_vhd.txt'" /sc ONLOGON /ru SYSTEM

and you're done

@azhe403
Copy link

azhe403 commented Jun 28, 2023

if prefer to use PowerShell instead of diskpart can use this command

Mount-DiskImage "D:\VHD\MyDrive.vhdx"

@ThePlenkov
Copy link

Mount-DiskImage unfortunately doesn't work if Hyper-V is not enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment