Skip to content

Instantly share code, notes, and snippets.

@ianfabs
Last active June 28, 2023 14:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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

@laontme
Copy link

laontme commented Dec 24, 2020

To mount more drives in one step

select vdisk file="C:\VHD\coding.vhd"
attach vdisk
select vdisk file="C:\VHD\other.vhd"
attach vdisk
exit

@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"

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