Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

Many articles helped me get here, but mostly good old SE!

http://superuser.com/questions/964666/how-to-unmount-a-vhd-via-command-line-in-windows-10

HowTo Automatically mount and umount VHD files on boot/shutdown

First, I should say that I am mounting a VHD stored on a Linux File Server, mounting in over SMB.

Second, very important, is that if you don't detach the disk upon reboot, then when you try to re-attach it, it says "The file is in use and can't be accessed"..

So we need both automount and unmount. The unmount proved a bit tricker, since I cant just put it in startup folder. You have to use Group Policy. Also, when run as a "shutdown/startup" script, it ran to early, you need to run it at "Logon/Logoff"

I have 4 files in C:\mount

mount.cmd

@ECHO OFF
DISKPART /s C:\mount\mount.txt

umount.cmd

@ECHO OFF
DISKPART /s C:\mount\umount.txt 

umount.txt

select vdisk file="\\192.168.1.255\Blizzard.vhdx"
detach vdisk 

mount.txt

select vdisk file="\\192.168.1.255\Blizzard.vhdx"
attach vdisk 

Now in start type/run `gpedit.msc` and add the scripts to logon/logoff

 

  • No labels

3 Comments

  1. Anonymous

    Thank you! Of three different guides this is the first I could make work for me, scripts work nice on desktop testing.

    I was also able to combine two separate mount*.txt files of two individual .vhdx drives into one .cmd script, but can one combine more drives to one *.txt file as a list though? I lack scripting experience but wouldn't it be convenient to have a single list of mountable *.vhdx drives to be executed by one script at one go? Just thinking of file clutter and possible complexities of managing multiple .vhdx scripts.

    Also, I had problems accessing gpedit.msc in Windows 10 even as a user with admin rights, so I couldn't assign the scripts as described here, but came up with a workaround of simply adding unmount script along side on top with the mount script in the startup event, so every time the scheduled mount task runs, it first runs unmount script and then the mount, so no worries (except that I need to find out how to enable gpedit.msc for me).

  2. I only have the one VHDx file, I use it for installing Blizzard games, other than that, everything is just Network Shares. Also, I am running an Enterprise level Windows 10 (Education), so perhaps that was why I had access to GPEdit.msc, but your fix seems logical. I am glad you got this to work! Most of my guides are exactly what you said, I used 3 guides to make one guide that worked for me (tongue)

  3. Anonymous

    This is excellent and simple. I'm actually not including the scripts at logon, but want manual control, so I created links to each cmd script and placed the links on my Desktop. I then changed the LINKS to run as Administrator (which you cannot do directly to the .cmd script itself). Now I can mount and unmount simply by clicking on either of the two links. THANKS!!