Archive

Posts Tagged ‘Lab’

Preparing a VM Server Image for Hyper-V Lab Environment

June 21st, 2012 2 comments

 

Few days back I had to reset my lab environment and first thing I had to do was to create a Windows 2008 R2 Virtual Machine Image.  The purpose was to have a readily configured and to an extend customized windows image which can be just copied whenever I have to create a virtual machine of that OS.  In this post I will describe the high level steps on how I did it.

 Its done is three stages, at first creation of a VM with minimal settings, Installing the base OS and initial configuration, and customizing the image for sysprep.

 Creating a VM is the first step, I don’t want to describe the steps or walk through the Hyper-V new virtual machine wizard, there is enough articles out there for that. Below are the points I did consider while creating the VM.

  • Naming the VM: provide a meaning full name, I used Win2K8R2SP1Template
  • Storage: Store this VM in a separate Folder
  • Network Adapter – Choose “Not Connected”
    • Some time back when I did similar setup, I had issues with hidden cards when  image was used, so I prefer not to have any cards connected to the master image
  • Set Automatic Start and Stop Actions to the VM as per your preference

The second step is to install Windows 2008 R2 and perform initial configuration, use an ISO and start installation of the OS.  Once operating system installation is complete you can perform basic setting you want to give for your image, its purely up to your preference and once completed restart the VM. I did the following settings:

  • Rename Computer Name and Give a description to the server  – E.g.,  WIN2K8R2SP1 – “W2K8R2SP1 Template”
  • From System Properties – Advanced Tab, select “Adjust for Best Performance” Option
  • Configure “Remote Desktop” settings from the Remote tab of the system properties
  • You can Stop + Disable any services which are not needed in your server infrastructure
  • Disable Automatic Update, Opt out from Error Reporting, Opt Out from Customer Experience Program
  • Disable Windows Firewall (do not go and stop the service) from Server Manager – Windows Firewall -  Advanced Security Properties
  • Update the Profile Pic (of the Administrator Account currently logged in)
  • Install updated Hyper-V Integration Services Component  and Restart the VM

Customizing the Desktop Profile for default users:

For all the customization files, create a folder in C Drive and keep those files in there, I have the folder called C:\Data .  Next is some customization to the Windows Profile Desktop, so Download and Install BGInfo . Have a BackGround Image for the Desktop Background ( my Pic is shown below), this can be replaced when the image Is later deployed.

Create a Config file from the BGInfo Tool by choosing the information you want to put on the desktop, I choose the below information for my lab image:

 Set the Background image in BGInfo as seen below

 Now Apply and see the preview, then from File Menu save the configuration as BGInfoConfig.bgi in C:\Data Folder

 Open notepad and create a auto run file named backinfo.cmd and have the below lines in it

CD C:\Data

Bginfo.exe C:\Data\BGInfoConfig.bgi /silent /timer:0

EXIT

 Copy the backinfo.cmd and put it in Startup folder of the Administrator(currently logged on user)

 

Any other customization you have in mind, configure it and next step is to create an answer file for image deployment customization.

Next – On a separate VM, download and  install Windows AIK (Automated Installation Kit).  Copy Install.wim from the source folder under Windows 2008 R2 Install Media (CD/DVD or ISO) to a folder inside VM.  Open Windows System Image Manager from Start Menu and from its file menu choose “Select Windows Image File” and locate Install.wim which was copied to a local folder inside VM. Click on YES when prompted to create a Catalogue file, this step will take some time to complete.

Now click on the Answer File Pane and create a new answer file. From the left pane by right click or drag option add settings to each passes of the OS Deployment, Understand More About Passes of Deployment here.  after its done (with what configurations I wanted to customize the screen looked like below):

The CopyProfile option is used to copy the profile where sysprep will be run as the default windows desktop profile.

 FirstLogonCommands are used to run any scripts when any user is first logged onto the server.

*  Admin password will show here  in plain text so take care of security., in the output xml anyways it will be encrypted. See the xml showing the Admin Password below:

You can read this TechNet Article – to have a basic understanding some useful image deployment options.

Now save the XML from the file menu, name it as Unattend.xml , there will be a validation done automatically, check for any errors.  Warnings can be ignored.

Get this Unattend.xml file and copy it to our Template VM under C:\Data folder, we are now almost done, below are the snapshot of my C:\Data folder and here is a copy of my xml answer file – A Sample XML File

Remove any Attached ISO or Additional VHDs from the VM, Set the memory to static (if you have set dynamic the Export VM will fail in later step)  and then run the Sysprep command as below (all in one line):

%sysprep%\system32\sysprep\sysprep.exe /oobe /shutdown /generalize /unattend:C:\Data\Unattend.xml

 Once sysprep is completed, the VM is shutdown automatically. Now you can Export the VM and keep it in your Templates location. Whenever a new VM is required from this template follow below steps:

  • Import VM using Hyper-V Import Virtual Machine Wizard, locate the folder of the Exported VM
  • Select options as seen below and import the VM
  •  Rename the VM to the desired name of the new VM
  • The VHD is imported to the default VHD location of the Hyper-V Host
    • Rename the VHD and Move the VHD to your Desired Storage Location
    • Update VHD Name and Location in VM Settings Page
  • Update the Desktop Background Image as per your need (its in c:\data\backimage.bmp)
  • Rename the Windows System Name
  • Shutdown VM and Attach to a Network Adapter
  • Start the VM 

                        

  • Your new VM from the Template is ready to use.

I hope this will be of help to someone.

Please drop your comments or feedbacks

Categories: Virtualization Tags: ,