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.

Assign computer startup scripts

Updated: January 21, 2005

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2

 

To assign computer startup scripts

  1. Open Group Policy Object Editor.
  2. In the console tree, click Scripts (Startup/Shutdown).

    Where?

    • Group Policy object/Computer Configuration/Windows Settings/Scripts (Startup/Shutdown)
  3. In the details pane, double-click Startup.
  4. In the Startup Properties dialog box, click Add.
  5. In the Add a Script dialog box, do the following:
    • In Script Name, type the path to the script, or click Browse to search for the script file in the Netlogon shared folder on the domain controller.
    • In Script Parameters, type any parameters that you want, the same way as you would type them on the command line. For example, if your script includes parameters called //logo (display banner) and //I (interactive mode), type //logo //I.
  6. In the Startup Properties dialog box, specify the options that you want as follows:
    • Startup Scripts for Group Policy objectLists all the scripts that are currently assigned to the selected Group Policy object. If you assign multiple scripts, the scripts are processed in the order that you specify. To move a script up in the list, click it, and then click Up. To move a script down in the list, click it, and then click Down.
    • Add–Opens the Add a Script dialog box, where you can specify any additional scripts to use.
    • Edit–Opens the Edit Script dialog box, where you can modify script information, such as name and parameters.
    • Remove–Removes the selected script from the Startup Scripts list.
    • Show Files–Displays the script files that are stored in the selected Group Policy object.
Tags

Comments are closed