This section contains step-by-step instructions for completing various common tasks. Note that these tasks require administrative credentials. Therefore, you should:
-
Run all commands at an elevated command prompt (click Start, right-click Command Prompt, and then click Run as Administrator).
-
Accept any confirmation dialog boxes that you receive from User Account Control (UAC).
In this topic
Creating, attaching, and detaching VHDs by using Disk Management
Disk Management is an MMC snap-in that you can use to perform the following operations:
-
Create a VHD. This task creates a new VHD by using the available disk space on the computer, and then saves it to the location that you specify.
-
Attach a VHD. This task attaches (sometimes referred to as “mounts” or “surfaces”) the VHD so that it shows up as a disk and assigns it a drive letter.
-
Detach a VHD. This task detaches (sometimes referred to as “unmounts” or “unsurfaces”) the VHD and unassigns a drive letter.
Create a VHD
Use the available disk space on the computer to create a VHD, and then save it.
To create a VHD by using Disk Management
-
Open Disk Management (click Start, type Disk Management in the Search box, and then press ENTER).
-
Select Create from the Action menu. This launches a dialog box that you can use to specify the parameters for a new VHD.
-
Specify the following:
-
Location: This is the location and file name where the new VHD will be saved when it is created. For example: E:\test.vhd.
-
Virtual hard disk size: This is the size of the VHD. Note that if you select Dynamically expanding, the virtual hard disk size is the maximum size the VHD will expand to.
-
Virtual hard disk format: This is the format of the VHD. You can select either of the following:
- Fixed size: The size of a fixed VHD is allocated based on the maximum size and it does not change. Fixed size VHDs are recommended for production environments.
- Dynamically expanding: A dynamic VHD is as large as the data that is written to it at any given time.
Note |
|---|
|
When you create a dynamic VHD, Windows does not test for free space on the physical computer based on the maximum size requested. Therefore it is possible to create a dynamic VHD with a maximum size that is larger than the available free space on the hard disk drive on the physical computer. The maximum size of a dynamic VHD is 2,040 GB. |
For example, the following screenshot will create a 1 GB, dynamically expanding VHD, and save it to the drive E.
-
Click OK to create the VHD. After it is created, the VHD is attached and it appears as an uninitialized disk.
-
To initialize the disk, right-click it in the Disk Management pane (in the example below, right-click the area that says Disk 3), and then click Initialize Disk.
After the VHD is initialized, you can treat the VHD as any other disk. For example, you can create new volumes, format volumes, and assign drive letters to volumes within the VHD. The following screenshot shows the user interface when you format a VHD.
Attach and detach a VHD
If you have an existing VHD, you can attach it and the VHD shows up as a disk.
To attach an existing VHD
-
Select Attach VHD from the Action menu.
-
Enter the path to the VHD and specify whether it should be attached as a read-only disk.
-
Click OK. After the VHD is attached, you can treat it as any other disk. For example, you can create new volumes, format volumes, and assign drive letters to volumes within the VHD. Additionally you can browse existing volumes within the VHD.
-
Optionally, you can detach the VHD so that it no longer shows up as a disk. To do this, right-click the disk, and then click Detach VHD.
Creating, attaching, and detaching VHDs by using DiskPart
You can use the DiskPart command-line tool to perform the following VHD operations:
-
Create a VHD. This task creates a new VHD by using the available disk space on the computer, and then saves it to the location that you specify.
-
Attach a VHD. This task attaches (sometimes referred to as “mounts” or “surfaces”) the VHD so that it shows up as a disk, and then assigns it a drive letter.
-
Detach a VHD. This task detaches (sometimes referred to as “unmounts” or “unsurfaces”) the VHD, and then unassigns a drive.
Note |
|
All of VHD operations in this section are scriptable. For more information about scripting DiskPart commands, see DiskPart on Microsoft TechNet (http://go.microsoft.com/fwlink/?LinkId=128458). |
Create a VHD
You can use the DiskPart command-line tool to create a new VHD. You must specify the maximum size of the VHD. Optionally, you can specify the following:
-
To create a dynamically expanding VHD (the default is fixed).
-
A source VHD. When you specify a source VHD, Windows populates the new VHD with the contents of the source VHD.
-
A parent VHD. When you specify a parent VHD, Windows creates a new differencing VHD that is a child of the parent.
Create a dynamic disk
The following screenshot shows a series of commands that perform the following tasks:
-
Create a new 2 GB dynamically expanding VHD (called test.vhd)
-
Create a 1 GB primary partition inside the new VHD
-
Format the new 1 GB partition
-
Assign a drive letter (M:) to the new partition
Create a differencing disk
A differencing disk is similar to a dynamic VHD, but it contains only the modified disk blocks of the associated parent VHD. The parent VHD is read-only, so you must modify the differencing disk. A differencing disk is sometimes referred to as a “child” VHD. To create a differencing disk, you must have a parent VHD.
The following screenshot shows a command that creates a new, dynamically expanding differencing VHD (called child.vhd), which is the child of another VHD called 7105.serverenterprise.vhd.
Attach and detach a VHD
The following screenshot shows a series of commands that perform the following tasks:
-
Attach the VHD. This task mounts the VHD so that it shows up as a disk and assigns it a drive letter.
-
Detach the VHD. This task unmounts the VHD and unassigns a drive letter.
Creating a bootable VHD
This section describes how to create a VHD and apply a Windows image from a .wim file to a partition in the VHD. You apply the Windows image by using a Windows PowerShell script, Install-WindowsImage, or ImageX (which is included in the Windows AIK). You can configure a VHD that contains a Windows 7 Ultimate or Windows Server 2008 R2 image for native VHD boot or for booting in a Hyper-V virtual machine.
The steps that are covered in this section are:
-
Create and attach a VHD file by using DiskPart.
-
Locate the install.wim image to apply to the VHD.
-
Apply a .wim image to a partition in the VHD.
After you create a .vhd file by using the steps in this section, you can configure it for native boot or to boot in a virtual machine by following the instructions in the Preparing a VHD image for boot section later in this document.
Before you begin
Before you continue, do the following:
-
Ensure that you have the following prerequisites:
-
A computer with Windows 7 or Windows Server 2008 R2 installed and running.
-
Access to media that contains Windows 7 or Windows Server 2008 R2.
-
Download and install the Windows AIK or Windows PowerShell. You can create and attach a VHD file and configure it for native boot by using features in Windows 7 (Steps 1 and 2 below). However, to create a bootable Windows 7 VHD (Step 3), you need to use the Windows AIK or Windows PowerShell to apply a .wim to the VHD. Specifically, you can use the Windows PowerShell script, Install-WindowsImage.ps1, or the Imagex.exe deployment tools.
-
Consider using WIM2VHD. You can use the Windows Image to Virtual Hard Disk (WIM2VHD) command-line tool to automate many of the steps in this section. To download WIM2VHD, see the MSDN Code Gallery (http://go.microsoft.com/fwlink/?LinkId=155155). Documentation for WIM2VHD is available on the MSDN site. WIM2VHD must be run from a system running Windows 7, Windows Server 2008 R2, or Windows Server 2008 with Hyper-V enabled. WIM2VHD also requires that the Windows AIK for Windows 7 be installed to use ImageX.
Specifically, WIM2VHD automates the following tasks:
-
Creates a new VHD of a specified type and size
-
Applies a WIM to a VHD
-
Uses an Unattend file to automate the OOBE portion of Windows setup the first time a generalized VHD is booted (optional)
-
Applies updates to VHDs (optional)
-
Enables a kernel debugger (optional)
Step 1: Use DiskPart to create and attach a VHD
Before you begin, note the following:
-
The default VHD type created when you use DiskPart is a fixed VHD. Therefore, to create another type of file, you must specify TYPE=EXPANDABLE as shown below. Note that creating a fixed VHD takes quite a bit longer because the entire file is allocated at the time it is created.
-
You can also use the Disk Management console to perform the above steps if you prefer. For instructions, see the Creating, attaching, and detaching VHDs by using Disk Management section earlier in this document.
To create and attach a VHD
-
Open an elevated Command Prompt window (click Start, right-click Command Prompt, and click Run as administrator).
-
Run the following commands to create and attach the VHD. This example creates a dynamic VHD that has 25 GB maximum size and saves the VHD file in a folder, c:\vhd.
diskpart
create vdisk file=C:\VHD\<filename>.vhd maximum=25000 type=expandable
select vdisk file=C:\VHD\<filename>.vhd
attach vdisk
create partition primary
assign letter=v
format quick FS=NTFS label=VHD
exit
For more information about these commands, run diskpart help create vdisk in the command line. The complete output for this example is shown in the following screenshot.
Step 2: Locate the install.wim image to apply to the VHD
The next step is to locate a Windows 7 installation image (.wim) to apply to the volume in the VHD. Before you begin, ensure that you have a .wim image from one of the following locations:
-
The product DVD. The installation image is located at \sources\install.wim. Note that the DVD also contains a Boot.wim file, which is the Windows PE image that you can use to network boot to run Windows Setup.
-
A Windows installation that you have captured to a .wim by using Imagex.exe or the Image Capture Wizard for Windows Deployment Services.
-
A product DVD .iso image. These images are available to MSDN and TechNet subscribers, and they are also available from the Windows Products Home page (http://go.microsoft.com/fwlink/?LinkId=155370). You must mount .iso images or burn them to physical media to access the .wim files within the .iso file.
Note |
|---|
|
The Windows PE image in Boot.wim does not support native VHD boot |
Step 3: Apply a .wim image to the VHD
There are two ways that you can apply a .wim image to a VHD.
-
Use the Install-WindowsImage.ps1 Windows PowerShell script. The Windows PowerShell script has fewer options than Imagex.exe and does not require you to download the Windows AIK. The script can perform two tasks: display a list of images in a .wim and apply a .wim to a partition in a VHD. You should use the script if you are not familiar with the Windows AIK and Imagex.exe, or if the Windows AIK is unavailable.
-
Use the Imagex.exe command-line tool.
Using the Install-WindowsImage.ps1 Windows PowerShell script
Before you begin, note that the first time you run Windows PowerShell, you may get an error that unsigned scripts cannot be executed.
If you receive this error, you need to set the Windows PowerShell execution policy to allow unsigned local scripts, but still require signed scripts from remote locations. To configure this, run set-ExecutionPolicy RemoteSigned at the Windows PowerShell command prompt.
To use the Install-WindowsImage.ps1 script
-
Click Start, and type PowerShell in the Start text box.
-
In the results, right-click Windows PowerShell, and click Run as Administrator.
-
To list the images and index numbers in a .wim, use the following syntax:
C:\Vhd\Install-WindowsImage.ps1 -WIM <path to .wim>
-
To view the help for this script, run help .\Install-WindowsImage.ps1 –detailed or see the Appendix in this guide.
-
To apply an image from a .wim to a VHD, use the following syntax:
C:\Vhd\Install-WindowsImage.ps1 –WIM <String> -Apply –Index <Int32> -Destination <Drive>
In the following example, volume D: is the DVD drive with Windows product DVD, and volume V: is the VHD created in Step 1:
C:\vhd> PowerShell
PS C:\vhd> .\Install-WindowsImage.ps1 -WIM D:\sources\install.wim
Index Image Name
[1] Windows Server 2008 R2 Standard (Full Installation)
[2] Windows Server 2008 R2 Standard (Server Core Installation)
[3] Windows Server 2008 R2 Enterprise (Full Installation)
[4] Windows Server 2008 R2 Enterprise (Server Core Installation)
[5] Windows Server 2008 R2 Datacenter (Full Installation)
[6] Windows Server 2008 R2 Datacenter (Server Core Installation)
[7] Windows Web Server 2008 R2 (Full Installation)
[8] Windows Web Server 2008 R2 (Server Core Installation)
Done.
PS C:\vhd> .\Install-WindowsImage.ps1 -WIM D:\sources\install.wim -Apply -Index 5 -Destination V:
Applying "Windows Server 2008 R2 Datacenter" to V:...
WARNING: This may take up to 15 minutes...
Elapsed Time: 00:10:57.6302827
Done.
Apply image by using the ImageX deployment tool
If you have the Windows AIK installed on your computer, you can use Imagex.exe to apply a .wim to a VHD. If you do not have the Windows AIK, you can download and install it on the computer where you will create a VHD. You can also use ImageX to capture a customized Windows image into a .wim file before you apply the .wim to a VHD.
To apply a .wim image to a VHD
-
The Install.wim (on the Windows product DVD) contains multiple images for different versions of the operating system. To apply the proper image, locate the index for the version of the image that you need. The following table contains the index for the operating systems that support native VHD boot. Note that all Windows Server 2008 R2 versions support native VHD boot.
Note |
You can view the index of an image by running imagex /info <path to .wim>. The output lists the metadata for all images in the .wim file. To find the index for the version of the image that you want, view the <DESCRIPTION> element for each of the images in the output. |
|
Index
|
Operating System Version
|
|
4
|
Windows 7 Ultimate
|
|
1
|
Windows 7 Enterprise
|
|
1
|
Windows Server 2008 R2 Standard (Full Installation)
|
|
2
|
Windows Server 2008 R2 Standard (Server Core Installation)
|
|
3
|
Windows Server 2008 R2 Enterprise (Full Installation)
|
|
4
|
Windows Server 2008 R2 Enterprise (Server Core Installation)
|
|
5
|
Windows Server 2008 R2 Datacenter (Full Installation)
|
|
6
|
Windows Server 2008 R2 Datacenter (Server Core Installation)
|
|
7
|
Windows Web Server 2008 R2 (Full Installation)
|
|
8
|
Windows Web Server 2008 R2 (Server Core Installation)
|
-
Use the following syntax to apply the Windows image from the install.wim to the VHD volume, using the applicable index. If you are applying a .wim from a network share instead of local media, use a wired network connection for a faster network connection speed to transfer the image file.
Imagex /apply <path to .wim> <image_index> <path to apply>
For example, to apply the Datacenter version of the image from the install.wim to the VHD partition, use the image index 5. Using the DVD media in the DVD drive with volume letter F:, and the VHD partition volume V:, the command would be the following:
D:\>imagex /apply F:\sources\install.wim 5 V:\
Note |
|
It takes approximately 10-15 minutes to apply the image. |
Now that you have created a VHD file, you can configure it for native boot or to boot in a virtual machine by following the instructions in the Preparing a VHD image for boot section later in this document.
Creating VHDs by using Hyper-V
You can use the Hyper-V Manager to create VHDs. Some customers prefer this method because there is a user interface that leads users through the process.
Note |
| VHDs that you create by using Hyper-V Manager will be configured for virtual machine boot by default. To configure the VHD for native boot, follow the instructions for Prepare a VHD image for native boot in the Preparing a VHD image for boot section. |
To create a bootable VHD by using the Hyper-V Manager
-
Start Hyper-V Manager (click Start, click Administrator Tools, and click Hyper-V Manager).
-
Click Action, click New, and then click Virtual Machine.
-
Specify a Name and Location for the new virtual machine, and then click Next.
-
Click Next on the Configure Networking screen.
-
Click Create a virtual hard disk, specify the storage location and maximum size for the VHD, and then click Next.
-
Click Install an operating system from a boot CD/DVD-ROM, and then select the drive or the .iso file.
-
Click Next, and then click Finish. When the wizard completes, Windows will create a new virtual machine in the Off state.
Use the following procedure to start the new virtual machine to begin installing Windows:
To start the new virtual machine
-
Right-click the new virtual machine.
-
To add a DVD or a virtual DVD to a virtual machine, click Settings.
-
Under IDE Controller, select DVD Drive.
-
Specify one of the following, and then click Apply:
- If installing from a physical DVD, select Physical CD\DVD drive, and then specify the drive letter.
- If installing from a bootable .iso file, browse to the path under Specify the media to use with your virtual CD\DVD drive, click Image file.
-
Select the virtual machine from the Virtual Machines pane, and then in the Actions pane, click Connect.
-
Click Actions, and then click Start.
-
When you are prompted to Press any key to boot from CD\DVD, press a key and proceed with the installation.
Now that you have created a VHD, you can configure it for native boot or to boot in a virtual machine by following the instructions in the following section: Preparing a VHD image for boot.
Preparing a VHD image for boot
After you have a VHD, you can configure it for native VHD boot or for booting in a virtual machine. The locations of the boot configuration data (BCD) store and the other boot files that are required to boot the system are different for native boot and virtual machine boot.
- For native VHD boot, you configure the boot entry in the BCD store to be on the physical system partition outside the VHD. The system partition can be the same or different than the volume that hosts the VHD file. For instance, by default Windows 7 Setup will create a separate 100MB partition to host the BCD store.
- For a virtual machine boot, you configure the boot entry in the BCD store to be on the volume inside the VHD.
Note |
| You must use an elevated Command Prompt window (right-click Command Prompt, and then click Run as Administrator) to run the commands that update the boot configuration data. |
Prepare a VHD image for native boot
Use the procedure in this section to prepare a VHD for native boot. For more information about BCDBoot parameters, see BCDBoot Command-Line Options (http://go.microsoft.com/fwlink/?LinkId=155166).
Note |
If you are an advanced user and familiar with BCDEdit, you can update the BCD manually instead of using the following procedure (using BCDBoot). To do this, run the following syntax at an elevated command prompt and note the GUID in the output: bcdedit /copy {default} /d “<your boot menu description>”. Next, using the GUID from the previous command, run the following two commands: bcdedit /set {GUID} device vhd=[C:]\VHD\<yournewvhd>.vhd and bcdedit /set {GUID} device vhd=[C:]\VHD\<yournewvhd>.vhd |
To update the BCD for native VHD boot
-
This procedure assumes you have Windows 7 installed and you want to add a second boot option to boot from the VHD. For this example, the VHD file is located in C:\VHD\<yournewvhd>.vhd, and the VHD is attached and assigned the volume letter, V. The following command creates a new BCD entry for native VHD boot of the Windows image in your VHD file:
V:\Windows\System32\bcdboot V:\Windows
BCDBoot creates the boot configuration entry so that Windows Boot Loader can boot from the VHD image. It also sets the default boot option for the computer to boot Windows from the VHD, which is currently assigned volume letter V.
Optionally, you can use steps 2-4 if you want to modify the default boot entry.
-
Run bcdedit (with no parameters) to display the system boot configuration entries.
The following screenshot shows an example of the BCDEdit output with two Windows Boot Loader entries. The default boot option, {default}, is for the VHD boot from volume V, the other boot option is for the Windows 7 image that is installed on volume C.
-
If you have Windows 7 installed on the hard disk drive, and you configure native VHD boot of Windows 7, there will be two entries in the list with the description text string Windows 7. To change the text in the boot menu (from Windows 7), use the following syntax where the GUID is the identifier of the VHD boot entry:
bcdedit /set {GUID} description=”Windows 7 RC VHD”
Note |
| Some boot entries have aliases instead of GUIDs (such as {default} for the default boot entry or {current} for the boot entry of the current system). To find the associated GUID, view the verbose output for all the boot entries by running bcdedit -v. |
-
To change the default system boot option to be the installed Windows 7 image, instead of the native VHD boot image (or an additional VHD image on the same system), run the following syntax where the GUID is the Windows Boot Loader entry that you want to be the default:
When the system restarts, the Windows Boot Manager displays a menu with a list of available images to boot.
Prepare a VHD image to boot inside a virtual machine
If you still have the VHD attached after running the Install-WindowsImage.ps1 script or the Imagex/apply command, you can use BCDBoot to prepare the VHD image to boot inside a virtual machine.
To prepare an attached VHD image to boot inside a virtual machine
-
Open an elevated Command Prompt window.
-
Use the BCDBoot /s<volume> command to specify which volume you want to use as the System volume for the Windows Boot Manager and boot configuration data. For example, if the VHD is attached and assigned volume V:, run the following command:
V:\windows\system32\bcdboot V:\windows /s V:
This command creates the boot configuration data on the partition inside the VHD that is used to boot Windows 7 in a virtual machine. You do not need to perform any other steps to prepare the image to boot in a virtual machine. Optionally, you can prepare the same VHD file to boot inside a virtual machine or for native VHD boot.
-
To view the BCD entry that was created by BCDBoot inside the VHD, run the bcdedit /store <path> option to specify the BCD file inside the VHD. For example:
bcdedit /store v:\boot\BCD
Note |
| You can specify the /store<path> option with a BCDEdit command to update a BCD store other than the current store. Note that when you are running Windows in a virtual machine, you do not need to specify the BCDEdit /store option to update a configuration store for the running virtual machine. |
Deploying a bootable VHD by using Xcopy
The following section provides step-by-step instructions for deploying a bootable VHD without using a managed deployment solution. This is useful for customers who want to develop a custom deployment solution.
To deploy a bootable VHD
-
Save a bootable VHD on a computer or network share.
-
Insert a Windows 7 or Windows Server 2008 R2 product DVD into the target computer and boot to the DVD.
-
Configure the disk and select where to install Windows by using the disk configuration screen.
-
Press Shift+F10 to launch a Command Prompt window.
-
In the Command Prompt window, run Startnet.cmd to start networking.
-
To copy the VHD from the file share to a destination on the local computer prepared in step 3, run xcopy <source> <destination>.
-
Use Diskpart to attach the VHD (for instructions, see Creating, attaching, and detaching VHDs by using DiskPart earlier in this document).
-
Prepare the boot environment by following the steps in the Preparing a VHD image for boot section of this document.
Deploying VHDs by using Windows Deployment Services
You can deploy bootable VHDs by using Windows Deployment Services. To do this, you must first install and configure the Windows Deployment Services server role on a computer that is running Windows Server 2008 R2. For instructions, see the Windows Deployment Services Getting Started Guide (http://go.microsoft.com/fwlink/?LinkId=84628).
For additional information about configuring Windows Deployment Services to catalog and deploy VHDs, see Deploying Virtual Hard Disk Images (http://go.microsoft.com/fwlink/?LinkId=146973).
You use the WDSUTIL command line tool to catalog VHDs to the Windows Deployment Services image library.
Migrating VHDs between physical and virtual environments
The following section provides step-by-step instructions for how to migrate a bootable VHD image between physical and virtual environments. This process relies on using the Sysprep tool. For more information, see the Sysprep Technical Reference (http://go.microsoft.com/fwlink/?LinkID=155027).
Move from a virtual to a physical environment
To migrate a VHD that is using Hyper-V to a physical environment
-
Boot the VHD image.
-
Double-click Sysprep to prepare and generalize the operating system.
-
In System Cleanup Action, select Enter System Out-of-Box Experience (OOBE).
-
Select the Generalize check box.
-
In Shutdown Options, click Shutdown.
Now you are ready to configure the VHD for native boot or to boot in a virtual machine by following the instructions in the Preparing a VHD image for boot section.
-
To deploy the image, follow the instructions in the Deploying a bootable VHD by using Xcopy section earlier in this document.
Move from a physical to a virtual environment
To migrate a VHD that is running on a physical computer to a Hyper-V environment
-
Boot into the VHD on the computer.
-
Double-click Sysprep to prepare and generalize the operating system.
-
In System Cleanup Action, select Enter System Out-of-Box Experience (OOBE).
-
Select the Generalize check box.
-
In Shutdown Options, click Shutdown.
-
Boot Windows PE (or another instance of Windows) on the computer.
-
Copy the image that you prepared using Sysprep to the server running Hyper-V.
-
On the Hyper-V server, launch Hyper-V Manager.
-
Click Action, click New, and then click Virtual Machine.
-
Specify a Name and Location for the new virtual machine.
-
Assign resources to the virtual machine.
-
Configure the new virtual machine to boot from the VHD that you prepared with Sysprep.
-
Now you are ready to configure the VHD for native boot or to boot in a virtual machine by following the instructions in the Preparing a VHD image for boot section.
Servicing images
You can service a VHD offline or online using command-line tools such as Deployment Image Servicing and Management (DISM.exe).
Add drivers
To add drivers to a VHD image
-
Attach the VHD. For instructions, see Creating, attaching, and detaching VHDs by using DiskPart earlier in this document.
-
To add a single driver, run the following command. In this example, the VHD is assigned drive letter Z::
Dism /image:Z:\ /Add-Driver /driver:C:\drivers\OEM.INF
Alternatively, to add multiple drivers to the VHD image, run:
Dism /image:Z:\ /Add-Driver /driver:C:\drivers\OEM.INF
/driver:c:\drivers\OEM1.inf /driver:c:\drivers\OEM2.inf
-
To confirm that the drivers were added to the image, view the output of the following command:
Dism /image:Z:\ /Get-Drivers
Add Windows features
To enable server roles and features in a VHD image
-
Attach the VHD. For instructions, see Creating, attaching, and detaching VHDs by using DiskPart earlier in this document.
-
Run the following command to list all the features in the VHD. The following example assumes that the VHD is assigned drive letter Z::
Dism /image:Z:\ /Get-Features
-
To display information about the state of a specific Windows role or feature, run:
Dism /image:Z:\ /Get-FeatureInfo /FeatureName:DHCPServer
-
To enable a specific Windows role or feature, run the following command (this example installs the DHCP Server role):
Dism /image:Z:\ /Enable-Feature /FeatureName:DHCPServer
For additional information about using DISM for servicing VHDs, see the following references:
Backing up images
Windows Server Backup is a backup and recovery solution for computers that are running the Windows Server 2008 R2 operating system. You can use Windows Server Backup to back up VHD volumes with some restrictions.
Performing advanced tasks by using DiskPart
This section shows the commands for performing the following operations:
- Expand vdisk. Expands the maximum size available in a VHD, including the steps to extend a partition that is contained with a VHD.
- Compact vdisk. Compacts or reduces the size of a VHD. This is useful if you need to reduce the size of a dynamic VHD because these files increase in size as you add files, but they do not automatically reduce in size when you delete files.
- Merge vdisk. Merges a differencing disk with its parent.
- Detail vdisk. Displays detailed information about a VHD, including the path, file name, state, virtual size, physical size, associated disk, whether the VHD is a differencing disk, and the path and file name of the parent.
Expand VHD
The following screenshot shows a series of commands that expand a VHD from 2 GB to 3 GB.
Extend partition
In the following example, the VHD contains a 1 GB partition (M:) and the entire VHD is 3 GB in size. The screenshot shows a series of commands that increases the size of M: from 1 GB to 2 GB.
Compact a VHD
The following screenshot shows a series of commands that perform the following tasks:
- Display information about the virtual and physical size of a VHD. For dynamic VHDs, the virtual size is the maximum size of the VHD (specified when you create the VHD), and the physical size is the actual size. For fixed VHDs, these values are the same.
- Attach the VHD as a read-only file.
- Reduce the size of (that is, compact) the VHD.
- Display information about the new physical size of a VHD.
Merge VHD
The following screenshot shows a series of commands that perform the following tasks:
- Attach the selected differencing VHD.
- Display the parent VHD (this is optional).
Detach the selected differencing VHD.
- Merge the differencing disk with the parent. In this step, note that Depth=1 is indicates that 1 level of the differencing chain will be merged. If you specify a number larger than 1, the VHD must have a differencing chain that is more than 2.
Display VHD information
The following screenshot shows a series of commands that perform the following tasks:
- Attach the VHD.
- Display information about the VHD.