Using a VHD to Store stuff in Windows 7
Firstly, I’m not taking the credit for this one. It was Paul Stovell’s idea, but because he’s currently blogless I’m going to post it on mine… 🙂
The other day Paul was talking about a way of utilising the new VHD features of Windows 7 to keep all his documents and important stuff in a single location so that he can back them all up by copying one file. He had created a VHD and written a script that mounts it as a drive at start up. I thought this was a great idea, so I reproduced it and am now sharing it.
Firstly, create the VHD either using Virtual PC or the Disk Management console Action > Create VHD. Attach the VHD in Disk Manager then initialise and format it. Detach it and we can start scripting the attach process.
Create a text file named “Attach VHD.txt” with the following contents in %windir%\System32\GroupPolicy\User\Scripts\Logon entering the location of the VHD:
SELECT VDISK file="<Location of VHD>"
SELECT DISK 4
NOTE: I’ve used U as the drive letter. You can change this if it will cause a conflict or you just don’t like it.
In the same location, create a batch file named “Attach VHD.cmd” with the following contents:
DISKPART /s "Attach VHD.txt"
Open the group policy editor (Hit Start then type “group policy”) and drill down to User Configuration > Windows Settings > Scripts (Logon).
Open the the Logon script properties and add the batch file you just created (it should open the location you created the files in by default).
Now, log out and on again. It may take a few seconds, but the autorun screen should pop up when the drive is attached. Open Windows Explorer and you will see a new drive in your tree.
I’ve actually now moved all my user folders (i.e. Documents, Music, etc.) to the VHD, but if you don’t want to do that you can just use the libraries to include a folder and set it as the save location.
Posted on 28 April, 2009, in Uncategorized. Bookmark the permalink. Leave a comment.
Leave a comment