Planning deployment for Windows Server 2012 (Part 3) - Installing Features in an Offline VHD

by [Published on 30 Oct. 2012 / Last Updated on 30 Oct. 2012]

This article explains how you can install or remove features for a Windows Server 2012 installation on an offline VHD.

If you would like to read the other parts in this article series please go to:

Introduction

Deploying Windows operating systems to target systems involves applying Windows images to those systems. But images need to be maintained once they are created, and this is called servicing the image. An image can be in one of two states:

  • Online - The Windows image is installed and running.
  • Offline - The Windows image is either not installed, or is installed but not running.

Examples of online images might be:

  • The image on a physical Windows server running in your datacenter.
  • The image on a running virtual machine that has Windows installed.

Examples of offline images might be:

  • The images in the Install.wim file in the \Sources folder on your Windows installation DVD.
  • The image in a custom WIM file that has been captured from a reference computer.
  • The image on the virtual hard disk (VHD) of a stopped virtual machine on which Windows has been installed.

As you can see, both WIM and VHD files can contain images of Windows Server 2012 or Windows 8. And while a WIM file can contain multiple Windows images (e.g. for different editions, architectures, or installation options) a VHD file can contain only one Windows image (i.e. the one that has been applied to the VHD).

Because Windows images can be either online or offline, there are likewise two different ways you can service an image:

  • Online servicing - This refers to updating a Windows installation on either a running physical system or a running virtual machine.
  • Offline servicing - This refers to updating either (a) a Windows image contained in a mounted WIM file or (b) a Windows image has been applied to a VHD but the virtual machine is not currently running.

Examples of tasks you might perform during servicing of an image might include:

  • Installing or removing roles, role services or features
  • Adding device drivers needed for certain hardware
  • Adding packages such as language packs or hotfixes
  • Adding application files (but not installing applications themselves)
  • Performing various customizations (for example, customizing the Start screen)

For the remainder of this article we’ll focus on installing or removing roles and features, which is a key aspect of servicing images for Windows Server deployment. Servicing an online installation of Windows Server 2012 by adding or removing roles or features can be done in two ways:

  • By launching the Add (or Remove) Roles and Features Wizard from Server Manager
  • By using the Install-WindowsFeature or Uninstall-WindowsFeature cmdlets of Windows PowerShell

Both methods can be used to add or remove features on remotely managed servers running Windows Server 2012, but the PowerShell approach has the additional advantage that you can it to service both online and offline images of Windows Server 2012. This capability can be especially useful in datacenter environments where server workloads are running in virtual machines.

Converting an offline VHD of Server Core to Server With A GUI

To demonstrate how you can add features to an offline VHD that has Windows Server 2012 installed on it, let’s take a virtual machine that has a clean install of the Server Core installation option of Windows Server 2012, turn off the virtual machine, and add the necessary features to convert the Windows installation to the Server With A GUI installation option.

Figure 1 shows a clean install of the Server Core installation option of Windows Server 2012 in a virtual machine running on a Hyper-V host.


Figure 1: A clean install of Server Core.

Type powershell in the command prompt window to change it to a PowerShell console:


Figure 2: Switching to Windows PowerShell.

The difference between a Server Core installation and a Server With A GUI installation is that the following two features are installed in Server With A GUI but are not installed in Server Core:

  • Graphical Management Tools And Infrastructure This feature includes infrastructure and a minimal server interface that supports GUI management tools.
  • Server Graphical Shell This feature provides the full Windows graphical user interface for server, including Windows Explorer and Internet Explorer.

On a Server With A GUI installation, both of these are sub-features of the User Interfaces And Infrastructure feature shown in Figure 3:


Figure 3: Server With A GUI has two features installed that are not installed on Server Core.

The PowerShell names of these two features are:

  • Server-Gui-Mgmt-Infra
  • Server-Gui-Shell

Let's use the Get-WindowsFeature cmdlet to display the install state of these two features in our running Server Core installation:

PS C:\> Get-WindowsFeature Server-Gui-* | Format-Table Name,InstallState

Name                                        InstallState
----                                        ------------
Server-Gui-Mgmt-Infra                       Removed
Server-Gui-Shell                            Removed

Features can have three possible install states in Windows Server 2012:

  • Installed - The feature has been installed
  • Available - The feature is not installed but its installation binaries are present in the side-by-side store (the C:\Windows\WinSxS folder)
  • Removed - The feature is not installed and its binaries are not present in the side-by-side store

As you can see from the above command output, the Server-Gui-Mgmt-Infra and Server-Gui-Shell features are not present in the side-by-side store on a clean install of Server Core. This means that if you want to install these features (i.e. convert your Server Core installation to Server With A GUI) you must provide a source for the missing binaries. For a running Windows Server 2012 installation, the missing binaries can be supplied in any of the following ways:

  1. By downloading them from Windows Update.
  2. By mounting a WIM image of the Install.wim file in the \Sources folder of your Windows Server 2012 product media.
  3. By mounting a VHD that has a Windows Server 2012 installation of the same edition and service pack level.
  4. By copying the entire WinSxS folder from a Windows Server 2012 installation of the same edition and service pack level.
  5. From a network share containing the missing binaries or the entire WinSxS folder from a Windows Server 2012 installation of the same edition and service pack level (requires configuring permissions appropriately).

If you don't specify a source for the missing binaries for features you want to install on a running Windows installation, then by default the binaries will be downloaded from Windows Update when you try to install the feature. This can take some time however, so it's generally best to specify a local or network source for the binaries.

We'll be using method 2 from the above list in a moment, but first let's shut down our virtual machine that has Windows Server 2012 installed and try running the Get-WindowsFeature cmdlet from our host machine (Hyper-V host) instead of within the virtual machine itself. To use Get-WindowsFeature on the host to display installed and available features on an offline VHD that has Windows installed on it, we need to include the -Vhd parameter in our command to specify the local path to the VHD file on the host machine. This path can be found in the Hard Drive properties in the virtual machine's settings as shown in Figure 4.


Figure 4: Determining the local path to a virtual machine's VHD file on a Hyper-V host.

Now let's use Get-WindowsFeature to view the install state of the Server-Gui-Mgmt-Infra and Server-Gui-Shell features in our offline VHD:

PS C:\> Get-WindowsFeature Server-Gui-* -Vhd "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\ch02 vhd inst feat test.vhdx" | ft Name,InstallState

Name                                                     InstallState
----                                                     ------------
Server-Gui-Mgmt-Infra                                    Removed
Server-Gui-Shell                                         Removed

As you can see, you can use Get-WindowsFeature to view the install state of features on both online and offline images of Windows Server 2012. We can find out more about the Windows installation on our offline VHD by using the dism /get-imageinfo command as follows:

PS C:\> dism /get-imageinfo /imagefile:"C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\ch02 vhd inst feat test.vhdx" /index:1

Deployment Image Servicing and Management tool
Version: 6.2.8400.0

Details for image : C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\ch02 vhd inst feat test.vhdx

Index : 1
Name : <undefined>
Description : <undefined>
Size : 8,325,693,440 bytes
Architecture : x64
Hal : acpiapic
Version : 6.2.8400
ServicePack Build : 0
ServicePack Level : 0
Edition : ServerDatacenter
Installation : Server Core
ProductType : ServerNT
ProductSuite : Terminal Server
System Root : Windows
Directories : <undefined>
Files : <undefined>
Created : 7/26/2012 - 2:24:30 PM
Modified : 7/26/2012 - 2:24:30 PM
Languages :
        en-US (Default)

From the above command output we can see that our offline VHD has a Server Core installation of ServerDataCenter edition installed.

Note also that whenever you specify a path to a VHD using the /imagefile parameter, you must always include /index:1 in your command since there can only be one installed image on a VHD.

Now let's use the Install-WindowsFeature cmdlet to install the Server-Gui-Mgmt-Infra and Server-Gui-Shell features on our offline VHD of Server Core. Doing this should convert our Server Core installation to a Server With A GUI installation. But before we do this, we need to provide the missing binaries for these two features as these binaries are not currently in the side-by-side store on the VHD (i.e. that's what the install state Removed means in the above command output). As we indicated previously, the method we'll use to provide these binaries is to mount a WIM image of the Install.wim file in the \Sources folder of the Windows Server 2012 product media. Here is the procedure:

  1. Insert the product media into the DVD drive on the Hyper-V host, which for this walkthrough will be D: drive.
  2. Create a new directory named C:\mountdir (or anything else) on the host machine.
  3. Open the PowerShell console and run the dism /get-wiminfo command to display the names and index numbers of all the images contained in the install.wim file in the \Sources folder on the product media:
PS C:\> dism /get-wiminfo /wimfile:D:\sources\install.wim

Deployment Image Servicing and Management tool
Version: 6.2.8400.0

Details for image : D:\sources\install.wim

Index : 1
Name : Windows Server 8 Beta SERVERSTANDARDCORE
Description : Windows Server 8 Beta SERVERSTANDARDCORE
Size : 7,054,646,034 bytes

Index : 2
Name : Windows Server 8 Beta SERVERSTANDARD
Description : Windows Server 8 Beta SERVERSTANDARD
Size : 11,849,571,677 bytes

Index : 3
Name : Windows Server 8 Beta SERVERDATACENTERCORE
Description : Windows Server 8 Beta SERVERDATACENTERCORE
Size : 7,050,514,952 bytes

Index : 4
Name : Windows Server 8 Beta SERVERDATACENTER
Description : Windows Server 8 Beta SERVERDATACENTER
Size : 11,854,358,781 bytes

The operation completed successfully.

Since our offline VHD has SERVERDATACENTERCORE installed, we should provide the missing binaries from a SERVERDATACENTER edition, which is the corresponding Server With A GUI installation option. We can see from the above command output that 4 is the index number of the SERVERDATACENTER image in the Install.wim file, and we'll use this info in the next step.

  1. Next, use the dism /mount-wim command to mount the image in the Install.wim file that you identified in step 3 to the empty directory on the host machine in step 2:
PS C:\> dism /mount-wim /wimfile:D:\sources\install.wim /index:4 /mountdir:C:\mountdir /readonly

Deployment Image Servicing and Management tool
Version: 6.2.8400.0

Mounting image
[==========================100.0%==========================]
The operation completed successfully.

Note that we've mounted the image as read-only since we won't be modifying it.

  1. Now use the Install-WindowsFeature cmdlet to install the Server-Gui-Mgmt-Infra and Server-Gui-Shell features on the offline VHD. Include the -Source parameter to specify the side-by-side store of the mounted Windows image as the source for the missing binaries that will be needed to install these two features:
PS C:\> Install-WindowsFeature Server-Gui-Mgmt-Infra,Server-Gui-Shell -vhd "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\ch02 vhd inst feat test.vhdx" -Source C:\mountdir\Windows\WinSxS

Success Restart Needed Exit Code      Feature Result
------- -------------- ---------      --------------
True    No             Success        {Graphical Management Tools and...
  1. We're finished servicing our offline image so we can unmount the image from the directory on the host:
PS C:\> dism /unmount-image /mountdir:C:\mountdir /discard

Deployment Image Servicing and Management tool
Version: 6.2.8400.0

Unmounting image
[==========================100.0%==========================]
The operation completed successfully.
  1. Now let's start the virtual machine in Hyper-V Manager, open it in a Virtual Machine Connection window, and log on using the default Administrator account. The result is shown in Figure 5, and as you can see our Server Core installation has been successfully converted to a Server With A GUI installation while it was offline.


Figure 5: The Server Core installation in the offline virtual machine has been converted to a Server With A GUI installation.

Conclusion

By using Windows PowerShell together with the Deployment Image Servicing and Management command DISM.exe, you can perform servicing of both online and offline images of Windows Server 2012 installations on both physical servers and virtual machines.

If you would like to read the other parts in this article series please go to:

Advertisement

Featured Links