VHD - Auto-mount at Startup in Windows 8

ByLine
How to Auto-mount a VHD at Startup in Windows 8
Synopsis
This tutorial will help show you how to have a VHD auto-mount as a drive 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
    46 KB · Views: 0
Last edited by a moderator:

bbrescia

New Member
I have tried this a couple of times and although it "mounts" the VHDX, I have to double-click the VHDX file in Explorer before it is visible as my H Drive. Any solution for this?
 

DavidY

Active Member
VIP Member
Pro User
I'm not sure, to be honest.

When you initially created the VHD, did you assign it to drive H:? I found that I needed to assign the same drive letter in Disk Management as I wanted to mount it with later.

Also what happens if you run the diskpart command in an elevated command prompt?

One thing to try is to run this (with whatever filenames and paths you used).
diskpart /s C:\MyVHDs\VHDLoadScripts\AttachVHD_H.txt

Note that when I tried this, it gives me this message at the end. This doesn't seem to be an issue though.
There is no volume specified.
Please select a volume and try again.

Or you could try the commands individually , eg.
diskpart
select vdisk file="C:\MyVHDs\MySecureStuff.vhd"
attach vdisk
assign letter=H
exit
 

bbrescia

New Member
Hi David - my physical HGST 4TB drive has drive letter E: assigned to it in Disk Management. Should the virtual drive have a different logical letter?

Disk 1 in DM is the physical HGST 4TB drive with the first 379MB reserved by the system, the next 2TB in an active, healthy primary partition (listed as E:), and the remaining 1.6TB unallocated.
 

DavidY

Active Member
VIP Member
Pro User
Hi bbrescia,

Have you assigned a drive letter to the virtual disk VHDX, in Disk Management?

In my example it's the Virtual drive letter I'm trying to set; what I did was create a VHDX and set it to drive H: when I first set it up in Disk Management.

The diskpart script in Task Scheduler then mounts it back to where it was before, but I think it needs to be done in Disk Management first.

There shouldn't be any changes to the physical drive letters.
 

bbrescia

New Member
yes - sorry, I am saying H: but really I meant F:. The drive is assigned to F: in DM and my script says F: too. The task reports that it ran successfully.
 

bbrescia

New Member
When I run my script from a DOS prompt, it reports successful completion but also says, "There is no volume specified. Please select a volume and try again."

ALso - after the script runs, I can see that in DM, the virtual drive is mounted with the letter F: It also appears in Explorer. It just doesn't get to the final step of appearing in Explorer if the script runs at startup. Here is my script:

select vdisk file="E:\HGST4TB.vhdx"
attach vdisk
assign letter=F
 

bbrescia

New Member
I would have saved the script to my C: drive but for some odd reason it won't let me write to the C: drive. I've checked the properties of the C: drive - it is shared and every class of user has full control, including me, the "trusted installer". What's up with that?
 

DavidY

Active Member
VIP Member
Pro User
I would have saved the script to my C: drive but for some odd reason it won't let me write to the C: drive. I've checked the properties of the C: drive - it is shared and every class of user has full control, including me, the "trusted installer". What's up with that?
Windows doesn't like you placing files in the root directory of the C: drive. It's much happier if you create a folder and put your files there, so I'd give that a try. I don't think there's any real advantage in putting them in the C:\ root directory.

I don't see why that should extend to the E:\ drive, but it might be worth trying creating a folder E:\MyVHDs or whatever, and putting the VHDX and the startup scripts there, to see if that makes a difference.

When I run my script from a DOS prompt, it reports successful completion but also says, "There is no volume specified. Please select a volume and try again."
Yes I get that too. It doesn't seem to be a problem when I've run it though; I get that message but it appears in Explorer with no problems.

I have to go to work now but will try and investigate more tonight.
 

DavidY

Active Member
VIP Member
Pro User
ALso - after the script runs, I can see that in DM, the virtual drive is mounted with the letter F: It also appears in Explorer. It just doesn't get to the final step of appearing in Explorer if the script runs at startup. Here is my script:

select vdisk file="E:\HGST4TB.vhdx"
attach vdisk
assign letter=F
I just had another thought...

What happens if you go back into Disk Management, and assign the virtual drive to another drive letter, say M:? Then change the script to assign letter=M as well and try it.

My theory is this - I'm wondering if there might be some hardware on your computer (for example a memory card reader) that has previously been mounted as F: . If there's no memory card inserted, it doesn't show in Windows Explorer, but I suspect Explorer still knows about it and has it in mind, which is why it doesn't like to show your VHD.

If so, then you need to find a drive letter that's far enough through the alphabet that Explorer doesn't have another use for it.
 

DavidY

Active Member
VIP Member
Pro User
Hi bbrescia,

Thanks for that. I don't know what the problem is. Could you post a screenshot of your Disk Management screen please?

Perhaps something in there will give us a clue.
 

bbrescia

New Member
DM Screenshot Just After Startup.jpgFile Explorer Screenshot Just After Startup.jpgDM Screenshot Just After Double-clicking the VHDX file.jpgFile Explorer Screenshot Just After Double-clicking the vhdx file.jpg

My script (file is named AttachMyVHDX.txt and is located in E:\VHDs:

select vdisk file="E:\VHDs\HGST4TB.vhdx"
attach vdisk
assign letter=F

In Task Scheduler, the "action" is: diskpart /s with parameter of E:\VHDs\AttachMyVHDX.txt

Thank you so much for sticking with this and I'm sure it will wind up to be some little fairly obvious thing that I've missed!

Bob
 

bbrescia

New Member
Oh - the pix are in order:

DM Screenshot just after startup
File Explorer shot just after startup
DM Screenshot after double-clicking the vhdx file
File Explorer screenshot just after double-clicking the vhdx file
 

DavidY

Active Member
VIP Member
Pro User
select vdisk file="E:\VHDs\HGST4TB.vhdx"
Hello Bob,

I think in this part of the script, you're saying the path to the VHDX is:
E:\VHDs\HGST4TB.vhdx

But from the screenshot, it's actually in:
E:\HGST4TB.vhdx

So you would either need to unmount the VHDX , and relocate it to the subfolder (which is what I would do, because I like putting stuff in subfolders!), or change the script.

Hope this helps!
 

bbrescia

New Member
David - eureka, mark this as solved! I am so sorry to have taken so much of your valuable time for such an oversight - but I do thank you very much for the solution.

Now I can add the other 2 HGST 4TB drives that arrived today in a RAID 5 configuration...
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top