Skip to content

Attach a .vhd in Windows Server 2008 R2.

January 20, 2010

Windows Server 2008 R2 (and Windows 7) has the ability to create and attach VHDs directly from Disk Management. Unfortunately they detach if your server reboots. This can be fixed with a little scripting.

Open the Group Policy Object Editor mmc Snap-in and drill down to Local Computer Policy -> Computer Configuration -> Windows Settings -> Scripts -> Startup.

Create two new scripts. The first script is a diskpart script to actually mount your VHD file. Call it step1.txt.

select vdisk file=”c:\mydisk.vhd”
attach vdisk

The second script is a .cmd script that just runs diskpart with the /s switch and passes in your diskpart script file. Call it AttachVHD.cmd

diskpart /s step1.txt

Set the AttachVHD.cmd as a Startup script in the Group Policy Object snap-in.

Windows will now automatically attach your .vhd when your system reboots.


From → Technology, Windows

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: