VHD - Auto-mount at Startup in Windows 8

How to Auto-mount a VHD at Startup in Windows 8

information   Information
This tutorial will help show you how to have a VHD auto-mount as a drive at startup in Windows 8.

You must be signed in as an administrator to complete these steps.

Tip   Tip
If you like, you could also use Bitlocker to encrypt the VHD drive.




Here's how...


1. To start with, create a VHD file, using the drive letter you want to use for this VHD.
NOTE: For example, I've created a VHD file called 'MySecureStuff.vhd' in the 'C:\MyVHDs' folder, and I want it to be mounted as drive H.

2. Open Notepad, and copy the text below into it. (Note I have struck out the third line as I believe it was incorrect and shouldn't be entered.)

Code:
select vdisk file="[COLOR=#ff0000][B]C:\MyVHDs\MySecureStuff.vhd[/B][/COLOR]"
attach vdisk
[DEL]assign letter=[COLOR=#ff0000][B]H[/B][/COLOR][/DEL]
[DEL]
[/DEL]
A) Change the 'file=' part of the first line to contain the full path to the VHD you created earlier in step 1.​
B) Change the 'assign letter' to be the drive letter you wish to use.​
SetupScript_1a_x.png


3. In Notepad, save it as a .txt file, and close Notepad.
NOTE: For example, I've called mine 'AttachVHD_H.txt' and saved it in a folder called 'C:\MyVHDs\VHDLoadScripts'.
SetupScript_2a_x.png

4. Open the WIN+X Power User Tasks menu, and click/tap on Computer Management. (see screenshot below)
SetupScript_3.png


5. In Computer Management, select Task Scheduler on the left (point 1 on screenshot), then select Create Task (point 2 on screenshot).
SetupScript_4a.png


6. In the General tab, enter a name and description for your task. Change the radio buttons to 'Run whether user is logged on or not', and change 'Configure for:' to say Windows 8.
Task_1a.png


7. Select the Triggers tab, then click New to add a new Trigger. Change 'Begin the task' to say 'At Startup'. Optionally, you can also tick the 'Delay task for' checkbox and select 1 minute (see note below). Click on OK.

Note   Note
The reason I selected a 1 minute delay is because I plan to enable BitLocker. Delaying gives the computer the chance to prompt me to enter a Bitlocker password just after I login rather than having to manually find the drive and start BitLocker. If you aren't using BitLocker, I don't think there's any advantage in selecting the delay.


Task_2a_Sub.png

8. Select the Actions tab, then click New to add a new Action.
A) In the 'Program/Script' box enter diskpart.​
B) In the 'Add arguments' box enter:​
/s
followed by a space and then the full path and name of the script file saved in step 4. So in my example it is:​
/s C:\MyVHDs\VHDLoadScripts\AttachVHD_H.txt
C) Click on OK.​
Task_3a.png

9. Select the Conditions tab. Clear the two checkboxes to Stop if the computer switches to battery power and Start the task only if the computer is on AC power, then click on OK to create the task.
Task_4a.png

10. If a Task Scheduler dialog pops up, saying 'enter user account information for running this task' then enter the password for the administrator username.
WARNING: You will also need to update this if you ever change the password on this account.
Task_6a_Auth.png


11. Close Computer Management.

12. To test this works, restart your computer. When it restarts, you should find that after a minute, the new drive is mounted as drive H: (or whatever you selected).


That's it, you're done!


 

Attachments

  • Windows_Virtual_PC.png
    Windows_Virtual_PC.png
    15.2 KB · Views: 400
Last edited by a moderator:
MountVHD.cmd
Code:
cd /d "%~dp0"
diskpart /s MountVHD.txt
exit

MountVHD.txt
Code:
select vdisk file="D:\VHD\Name.vhdx"
attach vdisk
assign letter=V

Place in same folder >
Name.vhd
MountVHD.cmd
MountVHD.txt

Then create a shortcut to "MountVHD.cmd" in "User" "Programs" "Startup" Folder

Now when "User" login - the "MountVHD.cmd" is run from the "Startup" Folder (Just a work around to using task manager)
 

My Computer

System One

  • OS
    Windows 3.1 > Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Dell XPS 8700
    CPU
    I7
    Memory
    24 GB
Thanks Everyone for trying to help. It was my mount script. I realized I was only putting " select vdisk=" instead of "select vdisk file"... The task couldn't start because the script wasn't directing it to the vhdx.
 

My Computer

System One

  • OS
    Windows
@bbrescia - did you ever figure out why you were getting the "There is no volume specified"? I ask because I too am getting that message, but the curious thing is that this script had been working just fine up until several weeks ago. I haven't been able to make troubleshooting this issue a priority until now, so I really don't know what updates/changes might've "broken" this for me.
 

My Computer

System One

  • OS
    Windows 8.1
@bbrescia - did you ever figure out why you were getting the "There is no volume specified"? I ask because I too am getting that message, but the curious thing is that this script had been working just fine up until several weeks ago. I haven't been able to make troubleshooting this issue a priority until now, so I really don't know what updates/changes might've "broken" this for me.
Hi BWB8771

One thing I would try is to attempt running the commands manually to see if it gives more information. So you could try these steps. If there are any errors, note the message down and type exit to get out of diskpart :
  1. open an elevated command prompt
  2. enter the command: diskpart
  3. when Diskpart loads, enter the command: select vdisk file="{Path to your VHD}"
  4. enter the command: attach vdisk
  5. does that work without generating an error?
  6. If it all worked, enter this command to detach the vdisk: detach vdisk
  7. whatever happened, enter this command to exit diskpart: exit
Does that work without errors? If there was an error, what was the error message?
 

My Computer

System One

  • OS
    Windows 8.1, 10
@DavidY - thanks for taking the time to reply. I encountered no issues or errors while performing your steps 1-7,

When I run diskpart /s c:\batch\Attach_VHD.txt I encounter:
There is no volume specified.
Please select a volume and try again.

The script in the "Attach_VHD.txt" is:
select vdisk file=Z:\FileHistory.vhd
attach vdisk
rescan
rescan
rescan
rescan
select partition 1
assign letter=H


The italicized lines were ones that I added on anecdotal advice in this thread.

Even though I am still getting that "no volume.." message, my VHD successfully mounts to drive H:, so I am okay with this. Of course, now that I've said/posted that, I'm going to jinx myself :)
 

My Computer

System One

  • OS
    Windows 8.1
@DavidY - thanks for taking the time to reply. I encountered no issues or errors while performing your steps 1-7,
....
Even though I am still getting that "no volume.." message, my VHD successfully mounts to drive H:, so I am okay with this. Of course, now that I've said/posted that, I'm going to jinx myself :)
Right I think I know what's happening.... I think I made a mistake in the original tutorial! Apologies! :eek::eek:

The statement "assign letter=h" should be deleted from the script file - I think the best way to set the driver letter is in disk management when the VHD is created, or use disk management to change it later. Luckily, once you've assigned a letter to a VHD, it 'remembers' it the next time it starts up.

The command "assign letter=h" only seems to work in diskpart if you have already selected the volume beforehand, and I think the only ways to select a vdisk volume are (a) if it already has a drive letter, or (b) if you know the volume number - which could vary depending on other factors so I'm not sure there's a safe way to determine that at run time if it is being called by Task Scheduler.
 

My Computer

System One

  • OS
    Windows 8.1, 10
Hi,

I have applied the procedure (included assign letter ...) ant it works. Thanks for procedure ... it's very useful to overcome a very annoying problem on Windows 10: impossible put OneDrive folders in SD card. I find the solution more/less at the beginning of august.

The Auto_mount procedure stopped to work after 3 days ... I discovered that there is a parameter to uncheck. ("configuration tab", "Stop if ... 3 days was checked by default)

But today, in september, the auto Mount hasn't work again ... and I do not have any idea: there is a message in Planning Utility Window: "Parameter not correct (0x80070057)".

Do you have any idea?

Thanks.

Massimo
 

My Computer

System One

  • OS
    WINDOWS 10
Hi,

I have applied the procedure (included assign letter ...) ant it works. Thanks for procedure ... it's very useful to overcome a very annoying problem on Windows 10: impossible put OneDrive folders in SD card. I find the solution more/less at the beginning of august.

The Auto_mount procedure stopped to work after 3 days ... I discovered that there is a parameter to uncheck. ("configuration tab", "Stop if ... 3 days was checked by default)

But today, in september, the auto Mount hasn't work again ... and I do not have any idea: there is a message in Planning Utility Window: "Parameter not correct (0x80070057)".

Do you have any idea?

Thanks.

Massimo
Hi Massimo,

I'm not sure.

Could you post a copy of the script you are using, and a screenshot of Task Scheduler, showing the command you are running?

David
 

My Computer

System One

  • OS
    Windows 8.1, 10
This is a great fix... and updating to Win 10 broke it somehow.

Any help would be much appreciated!

I'm running an Asus Transformer Tablet (originally win 8.1, now win 10). Like I said, I had it working great when the tablet was running Win 8.1, and the updated to Win 10 apparently killed it.

The VHDX is on an SD card, drive letter D. I can open diskpart and manually enter the text in my mount script.txt file and it all works, so I'm really stumped as to why the mount script itself doesn't work.

When I try running the mount script.txt from Run, a command window pops up and disappears without doing anything. Anyway, here are my settings:

VHDX location:
D:\Media Store.vhdx

text file location:
C:\external card\mount script.txt

sc1.PNG

sc2.JPG

text of mount script:

select vdisk file="D:\Media Store.vhdx"
attach vdisk
assign letter=f

FWIW, under last run result I get "Unspecified error (0x80004005)".

EDIT:

I tried running thte script from an elevated command prompt and got the error message:
DiskPart was unable to open or read the script file.
Make sure the file you specified exists.​
 

My Computer

System One

  • OS
    Win 10, Win 8.1, Linux,
in your second screen shot put quotes " " around "C:\ blah blah.txt"

command prompt does not like SPACES in names unless in qoutes
 

My Computer

System One

  • OS
    Windows 3.1 > Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Dell XPS 8700
    CPU
    I7
    Memory
    24 GB
Awesome! Worked like a charm. I was tearing my hair out trying to figure this one out-- you saved me from baldness. My wife thanks you :)
 

My Computer

System One

  • OS
    Win 10, Win 8.1, Linux,
in your second screen shot put quotes " " around "C:\ blah blah.txt"

command prompt does not like SPACES in names unless in qoutes
Thanks for that answer. :) (I've been away so not able to get offline for a few days.)
 

My Computer

System One

  • OS
    Windows 8.1, 10
diskpart.png


We are a freeware development team (sordum.org) and just read the topic and created a very small portable App to solve the problem (VHD - Auto-mount at Startup) it is very easy to use :

1. Right click Diskpart_svr.exe and run as admin
2. Edit the first command and use install service Button , if you want to uninstall it just use uninstall button

Any feedback will be greatly appreciated
Downlod:
http://www.sordum.net/forum/download/file.php?id=93

Does this only work as an installed service?
Can this exe be called to complete the operation ('portably')?
Is there any way to request the diskpart /mount operation at bootExecute (assuming this is the earliest occasion at which an executable launch can be requested?

I miss autoexec.bat
 

My Computer

System One

  • OS
    windows 7,10
What do you want to do - AutoMount a VHD or Boot a VHD
 

My Computer

System One

  • OS
    Windows 3.1 > Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Dell XPS 8700
    CPU
    I7
    Memory
    24 GB
DavidY - thanks for the detail here. I have a Surface Pro 3 and my hard drive is almost full. I purchased a 64GB SD Card to hopefully work around that. I followed the instructions on the post I thought exactly. When I re-booted I don't see the new drive at all. I had turned on BitLocker before I did any of your steps, not sure if that's the difference? I don't ever get prompted to put in a BitLocker password though. Let me know what you think. Thanks!
 

My Computer

System One

  • OS
    Windows 8.1Pro
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Surface Pro 3
DavidY - thanks for the detail here. I have a Surface Pro 3 and my hard drive is almost full. I purchased a 64GB SD Card to hopefully work around that. I followed the instructions on the post I thought exactly. When I re-booted I don't see the new drive at all. I had turned on BitLocker before I did any of your steps, not sure if that's the difference? I don't ever get prompted to put in a BitLocker password though. Let me know what you think. Thanks!
Hi kremster,

Really sorry - I had a busy week and didn't respond sooner.

Can you describe how your drive letters are organised, please? How are you using the VHD file?

I believe that you could encrypt the whole SD card with Bitlocker without using a VHD drive at all - see here, for instance.
http://www.eightforums.com/tutorials/21188-bitlocker-turn-removable-data-drives-windows-8-a.html

Or it is something else which you're trying to do?

Regards
 

My Computer

System One

  • OS
    Windows 8.1, 10
DavidY,

Thanks for the response. I guess I should be a little more clear on what I'm doing, sorry I thought you could read my mind. :)

So as I mentioned I got that 64GB SD Card for my Surface Pro 3. I'm still running 8.1 but need to upgrade to 10 so if it makes sense to upgrade before I proceed, just let me know.

We use OneDrive to sync our files to the cloud. My hard drive is nearly full so my ability to sync new data to OneDrive is running out very soon as my hard drive fills up. So I'm trying to format the SD Card to where my machine will actually recognize it as a drive (rather than removable media) and then I can sync OneDrive files to it. I first completed the steps on this page:
On Windows 8 or 10, particularly on tablets with a permanently inserted SD card, is there a universal way to treat the card as a non-removable drive? - Super User

While going through that, it said the following "Now, the trick to bring it all together is to set up Windows so that the drive is mounted when the computer boots, as it's no fun having to go into Disk Management each time your computer starts to mount the drive. To do this, you'll need to create a script for mounting it, and then using Task Scheduler to execute the script on boot. I found a really good guide here, which I'll summarize below." - I followed those steps closely while just changing the naming conventions slightly.

That 'here' reference above is of course to your page about doing the VHD Auto-Mount and that sounded like something I should incorporate. I should probably caveat this whole thing with the fact that I'm not an IT professional. I certainly know more than the average Joe and I'm seen as the IT guy in my office (unfortunately) but I'm not overly technical and this process is a bit out of my league. Anyway, I walked through the steps on the other article, together with yours, and once completed I don't see the new SD Card anywhere within File Explorer. I actually do see it under C:/SD Card, but when I try to access it, it gives me an error saying that Location is not available.


I can still see the SD Card under Disk Management as File System Unknown (BitLocker Encrypted) and Status is Health (Primary Partition).

I tried to include screenshots of both of those but it didn't seem to let me post those?

Anyway, let me know if you think I should start over and add BitLocker after the fact - if this is the case, I assume I just need to re-format the SD Card and I'll be back at the beginning of the process? Or should I upgrade to Windows 10 first, then re-try these steps? Hopefully that better explains it. Let me know! I appreciate it.
 

My Computer

System One

  • OS
    Windows 8.1Pro
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Surface Pro 3
If your drive is rather full - you will have a hard time upgrading to windows 10...

I see you mention C:\SDCard - is there a . vhd or .vhdx file in that directory ??

Because it appears to me you formatted the SDCard and mounted as a folder C:\SDCard

try to add a file into C:\SDCard (the SDCard is now mounted as a folder on C:\ and not a drive with drive letter)

And just a side note - a vhd can be mounted from removable media - although not sure about using onedrive sync with removable media - but a vhd would also be assigned a drive letter

It seems to me that you should sync the onedrive cloud storage with C:\SDCard
 

My Computer

System One

  • OS
    Windows 3.1 > Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Dell XPS 8700
    CPU
    I7
    Memory
    24 GB
If your drive is rather full - you will have a hard time upgrading to windows 10...

I see you mention C:\SDCard - is there a . vhd or .vhdx file in that directory ??

Because it appears to me you formatted the SDCard and mounted as a folder C:\SDCard

try to add a file into C:\SDCard (the SDCard is now mounted as a folder on C:\ and not a drive with drive letter)

And just a side note - a vhd can be mounted from removable media - although not sure about using onedrive sync with removable media - but a vhd would also be assigned a drive letter

It seems to me that you should sync the onedrive cloud storage with C:\SDCard

- Yes I put a .vhdx file in the C:\SD Card directory
- "Because it appears to me you formatted the SDCard and mounted as a folder C:\SDCard" - yes, that's what I attempted - not sure if I did it correctly given the errors I'm getting.
- I tried to add a file to C:\SD Card and I get the same error - "Location is not available"
- I expected that the VHD would assign the SD card it's own drive letter, but that didn't happen.
- "It seems to me that you should sync the onedrive cloud storage with C:\SDCard" - this is what I'm trying to do. Unsuccessfully thus far.

Regarding the upgrade to Windows 10, I could free up another 12GB of data once I can figure out this SD Card and move those files from my C drive over to the SD card. So I would think 25GB free should be enough space for the upgrade to 10?
 

My Computer

System One

  • OS
    Windows 8.1Pro
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Surface Pro 3
Back
Top