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: 402
Last edited by a moderator:
Greetings David and all,

Thanks for the walkthrough. By all rights, it should work for me but it's not.

Details: Running on Windows Server 2012 R2, logged in as the original Administrator account. Even just testing manually by right-clicking the "start button", choosing "Run" and pasting:

Code:
diskpart /s W:\BoxSync-NTFS.vhdx.txt

appears to quickly open and close the shell, but even if I instead paste:

Code:
diskpart /s W:\BoxSync-NTFS.vhdx.txt > W:\diskpart.txt

I get no log file.

I am able to manually run diskpart itself from the Run dialog, and then I copied and pasted (via clicking in the upper left corner of the shell windows, choosing Edit and then Paste) exactly what I have in the text file, and indeed it works, including showing up in Windows Explorer:

BoxSync-NTFS.vhdx.jpg

Thoughts?

By the way, in case anyone wonders, the reason why I'm using a VHD for Box Sync is because I'm using an ReFS (file system) with Transparent RAID, and Box Sync refuses to work with ReFS even though all other cloud programs work just fine with it.
 

My Computer

System One

  • OS
    Windows Server 2012 R2
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Homemade
    CPU
    Athlon 64 X2 2.2 GHz
    Motherboard
    Gigabyte
    Memory
    8 Gb DDR2
    Graphics Card(s)
    ATI Radeon 4870
    Monitor(s) Displays
    TV
    Screen Resolution
    1920x1080
    Hard Drives
    3x Toshiba 3 Tb
    1x Western Digital 1 Tb
    2x Western Digital 640 Gb
    PSU
    Corsair 750
    Case
    Cooler Master
    Keyboard
    Logitech K750
    Mouse
    Logitech M570
    Internet Speed
    15 MB / 2 MB
    Browser
    Chromium 64-bit
    Antivirus
    Webroot SecureAnywhere
Hi there.

I must admit I don't know why it isn't working. I don't know much about Windows Server and perhaps there's a difference there that's significant.

One thing to try though - what happens if you try to put the log file in a different folder path?

So instead of this:
even if I instead paste:

Code:
diskpart /s W:\BoxSync-NTFS.vhdx.txt > W:\diskpart.txt

I get no log file.
..what happens if you use a folder on another drive to hold the log? For example, if you had a d:\temp folder, you could try something like:
Code:
diskpart /s W:\BoxSync-NTFS.vhdx.txt >D:\temp\diskpart.txt

That would eliminate the possibility of it having problems accessing W: in the first place, in which case it wouldn't be able to create a log there either.
 

My Computer

System One

  • OS
    Windows 8.1, 10
Hi David
Thanks for the post, the auto-mount works perfect for me, but I have an issue. If I move say the location of OneDrive to the sdcard, my c drive reduces in same proportion as the space taken by the OneDrive in the sdcard location. How can fix this.
 

My Computer

System One

  • OS
    Windows 8.1
Hi David
Thanks for the post, the auto-mount works perfect for me, but I have an issue. If I move say the location of OneDrive to the sdcard, my c drive reduces in same proportion as the space taken by the OneDrive in the sdcard location. How can fix this.
Hi Ashameen,

Can you say a bit more about what you're trying to do, and the setup of the disks on your computer? Which drive are you using as a VHD drive?

It might be useful if you could post a screenshot of the layout in Disk Management (to bring this up, open the Win+X Power menu and click/tap on Disk Management)

If you create a dynamically-expanding VHD (as in the option at Step 6 in this tutorial) then I believe the size of the VHD won't dynamically shrink back down again when you delete files from it. Is that the issue you're finding?
 

My Computer

System One

  • OS
    Windows 8.1, 10
I am saying the purpose of the sd card is to free up some space on the c drive and to use the mounted drive (sdcard) for onedrive, dropbox etc. But with this, the cdrive space reduces also as you add files from onedrive, dropbox, pictures etc. which defeats the purpose of the sd card in the first place.

I am using drive W (my sdcard) as the VHD mounted on the C drive.
Hi David
Thanks for the post, the auto-mount works perfect for me, but I have an issue. If I move say the location of OneDrive to the sdcard, my c drive reduces in same proportion as the space taken by the OneDrive in the sdcard location. How can fix this.
Hi Ashameen,

Can you say a bit more about what you're trying to do, and the setup of the disks on your computer? Which drive are you using as a VHD drive?

It might be useful if you could post a screenshot of the layout in Disk Management (to bring this up, open the Win+X Power menu and click/tap on Disk Management)

If you create a dynamically-expanding VHD (as in the option at Step 6 in this tutorial) then I believe the size of the VHD won't dynamically shrink back down again when you delete files from it. Is that the issue you're finding?
 

My Computer

System One

  • OS
    Windows 8.1
I am saying the purpose of the sd card is to free up some space on the c drive and to use the mounted drive (sdcard) for onedrive, dropbox etc. But with this, the cdrive space reduces also as you add files from onedrive, dropbox, pictures etc. which defeats the purpose of the sd card in the first place.

I am using drive W (my sdcard) as the VHD mounted on the C drive.
Hi ashameen,

I'm still not quite sure what your setup is?

Do I understand correctly that instead of assigning the VHD to a drive letter (which is what I did in my tutorial) you're using diskpart to set it to a mount point somewhere on the C: drive?

I've had a quick try of this scenario, and by moving a file from C: to my mounted VHD, it does reduce the space reported as used on C:, so at least for me it works.

What happens to your C: drive space when you unmount the VHD (or temporarily stop it from auto-mounting at startup)? Does the space used change?
 

My Computer

System One

  • OS
    Windows 8.1, 10
I created the vhdx on my C drive (C:\MyDrive\mount82.vhdx) and assign the vhdx to the drive letter W
select vdisk file="C:\MyDrive\mount82.vhdx"
attach vdisk
assign letter=W

But I reverted to using the sdcard without the vhdx until i find a solution to the issue.
 

My Computer

System One

  • OS
    Windows 8.1
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
 

My Computer

System One

  • OS
    windows 7
I created the vhdx on my C drive (C:\MyDrive\mount82.vhdx) and assign the vhdx to the drive letter W
select vdisk file="C:\MyDrive\mount82.vhdx"
attach vdisk
assign letter=W

But I reverted to using the sdcard without the vhdx until i find a solution to the issue.
Hi ashameen,

If your VHDX is on the C: drive, then by moving files around from other C: folders to your VHDX file (with the letter W: ), you are just moving data around from one part of C: to another, so it wouldn't save space overall.

Does that help?
 

My Computer

System One

  • OS
    Windows 8.1, 10
Yes that helps. So I have to create the vhdx on the sdcard
You could create it on the sdcard - although if you want the auto-mount to work, it means you'd have to be sure the sdcard was always inserted when you boot up.

But I'm not sure you'd get much advantage by creating a vhdx on the SD Card. If all you want to do is save space, a simpler way would be just to use the SD Card itself directly as whatever drive letter it maps to, without trying to make a VHD.
 

My Computer

System One

  • OS
    Windows 8.1, 10
Windows 8.1 Cant get Sd to mount as drive

Hello, could I possibly get some help please?. I can't get my sd card to mount as drive E when I reboot my tablet... I'm not sure why.. I've followed the steps and created a task for it but when I restart my tablet the drive isn't mounted. The error message displayed by the task simply says "unspecified error" so I really have no idea what I did wrong.
 

My Computer

System One

  • OS
    Windows
What I did in my case (and it works perfectly) is to create the VHDX on the SDcard (M) ("M:\VHDX\mount82.vhdx") , created a new simple volume from the sd card and assign it to letter N, and wrote the auto-mount script and saved it to a folder in the SDCard:
select vdisk file="M:\VHDX\mount82.vhdx"attach vdisk
assign letter=N

And follow the auto-mount procedure and you should be able to get it working.
Hope this helps
 

My Computer

System One

  • OS
    Windows 8.1
I seem to see conflicting issues - you state you can not mount your SD card as E:\

your VHD is in a folder on C:\

You are assigning E:\ My SD.vhd

So you should have a C:\ drive - D:\ SD Card - E:\ VHD

You can not have E:\ SD Card and E:\ VHD

Most people are putting the VHD file on the SD Card - not C drive
 

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
I've tried putting the vhd on my sd card and on my C drive. Neither way is working. I deleted the mount script & task and everything. I followed the steps again (putting the vhd on my sd) but when i restart the pc the vhdx doesn't mount.
 

My Computer

System One

  • OS
    Windows
I've tried putting the vhd on my sd card and on my C drive.
The vhdx is in a folder on my C drive ( Here's the path: "C:\Vhdx\My Sd.vhdx" )
View attachment 59492
Can you post the mount script which you're using when the vhd is on the SD card, please? The script above would only work if the VHD was on the c: drive - the first line ("select vdisk=...") would need to point to the SD card path instead.
 

My Computer

System One

  • OS
    Windows 8.1, 10
Back
Top