Friday, 1 January 2016

Configuring Dynamic Memory in Hyper V (Windows Server 2012 R2)

In this article, we will discuss about Dynamic Memory in Hyper-V. We will see what the use cases are and how to configure it.

Dynamic Memory is a Hyper-V memory management features starting from Windows Server 2008 R2, it automatically reallocates the memory among the virtual machines efficiently. When enabled on a virtual machine, the memory of that virtual machine is considered as a shared resource. This means that other virtual machines can also use that memory, if required.

For example, when a virtual machine needs more memory due to performance reasons or for any other factor and if the Hyper-V host sees a virtual machine with idle memory and if dynamic memory is enabled on both the virtual machines (the one that requires more memory and also the one that has idle memory) then the host can easily adjust the amount of memory needed to the virtual machine based on the demand and available memory on the host.
This is true with almost all virtual machines running in any environment. When a virtual machine is idle their current memory usage will be very low against their startup memory. But when it is performing some job then tend to use more memory and sometimes more than the startup memory.

With the help of Dynamic Memory, you can now over-provision with respect to the memory available on the host and this means you can run more virtual machines. It is very beneficial in environment that have many idle or low-load virtual machines such as pooled VDI environments. It saves cost if you start using dynamic memory on the virtual machines.

Below are the guest operating systems that supports Dynamic Memory.

  • Linux Distributions
  • Windows Server 2003 SP2, Windows Server 2003 R2 SP2, Windows Vista SP1, Windows Server 2008 SP2, Windows 7, Windows Server 2008 R2, Windows Server 2008 R2 SP1, Windows 8 and Windows 8.1, Windows Server 2012 and Windows Server 2012 R2.

Note – Install the latest integration services after you set up the operating system in the virtual machine.

Let’s see how to configure Dynamic Memory on a virtual machine.

In this settings of a VM, below are the options you would see when you click on Memory.
Startup RAM
For this virtual machine, the startup RAM has been configured with 2 GB. When this VM powers on, 2 GB of RAM is reserved for this VM on the hosts, regardless of what the actual RAM demand is.

Enable Dynamic Memory
This is a checkbox where you can enable or disable dynamic memory. If the virtual machine is up and running then you need to shut down the virtual machine to enable this option. After enabling Dynamic Memory, you would be able to specify the minimum and maximum RAM for a virtual machine.
  • Minimum Memory - You can specify how much of minimum memory your virtual machine need to have. In this example, it is set to 512 MB. I know we said we need 2 GB of startup memory. But in minimum memory we are saying that we just need 512 MB of RAM. The logic is that when an operating system starts up initially, it requires certain amount of memory. But when it has actually started, up and running, then it doesn’t require that much. Once the virtual machine notifies the host that its RAM requirement has decreased the host can start reducing the idle memory allocated to the virtual machine. But from the operating system’s perspective running on the virtual machine, the amount of visible RAM will never drop below the Startup RAM amount. If the virtual machine is configured with 2 GB of startup RAM then the operating system running on this virtual machine will also show 2 GB as the total RAM.
  • Maximum Memory - By default, maximum memory will be set to 1 TB.  But it is not recommended to leave this value set to the default. In this example, I’ve specified the maximum RAM that this VM can have is 4 GB. The good thing is that you can increase the maximum RAM while the virtual machine is running. You can now do this in Windows Server 2012 Hyper-V or later but it was not possible in Windows Server 2008 R2 Hyper-V or prior. But you cannot increase the minimum RAM when the virtual machine is running and with maximum RAM, you can increase it but you cannot decrease it when the virtual machine is running.
  • Memory Buffer - Memory Buffer, by default, is set to 20%. We can always change that and by changing the value Hyper-V host will reserve 20% of configured memory of the VM as a buffer. For example, if this virtual machine is configured memory with 2 GB of startup RAM then the Hyper-V host will reserve 20% of 2 GB which is 400 MB of memory. In this example, we will leave this to default.
  • Memory Weight - Memory Weight option is useful if there is memory contention among the virtual machines running on the host. With this option, you can specify which virtual machine gets more or less priority during memory contention. If I specify low as the memory weight priority for the virtual machine then it might not startup if the available memory on the host is low and other virtual machines are running and it is also used for taking memory away.  The lower the weight, the most likely that machine is to lose memory when the host needs it. The higher the weight, the higher the priority when it comes time to give out memory.

Monitoring Dynamic Memory Usage
It is also important that you monitor the Dynamic Memory in Hyper-V and there are quite few ways for that.

System Center Virtual Machine Manager
SCVMM gives the most complete view of the Dynamic RAM picture. 
In this image, you can see there are varying amounts of assigned RAM to the three virtual machines.
  • Fastvue01 is currently demanding 2GB of RAM. The assigned amount is the demand plus the Memory buffer.
  • FastVue02 is currently only demanding 1.28GB since it has a smaller workload. The assigned memory however is still 2GB because this is the specified Minimum RAM amount.
  • Fastvue03 is currently only assigned 1.2GB since it has the smallest workload of all. The difference is that the Minimum RAM specified is 512MB.
The SCVMM view is great because it is complete and provides you with the total picture. It does however lag a little behind. The best place for more ‘live statistics’ are in the Hyper-V Management Console.

Hyper-V Management Console
The Hyper-V Management Console provides a simple and convenient real time view of the RAM assignment. As such, is it not a great tool to determine the minimum baseline for your virtual machines? But it can show you things like how much is your Startup Memory? Whether Dynamic Memory is enabled or not? The Minimum and Maximum Memory configured for the virtual machine, assigned memory allocated to the virtual machine by the host, the current memory demand by the virtual machine and whether the memory status is OK or not.
 
Performance Monitor
By using Performance Monitor (Perfmon) on the host itself, you can get a very detailed live view of the Dynamic Memory picture. The key counters to use are:
  • Hyper-V Dynamic Memory Balancer - The Hyper-V Dynamic Memory Balancer counter gives you a view of how the host is doing from a memory perspective. In the image below, the host still has 4.5 of RAM available to allocate based on demand. The current demand or ‘pressure’ from the virtual machines is 80. When the pressure gets to 100, the host is essentially out of RAM. If you need to do capacity planning and would like to know how much memory is available on the host then you need to use the performance counter \\Hyper-V Dynamic Memory Balancer\Available Memory\ which determines how much memory you can safely allocate to create new virtual machines.
  • Hyper-V Dynamic Memory VM - The Dynamic Memory VM counter gives you a view very similar to what we have seen from the SCVMM and Hyper-V Management consoles. One counter that is very useful here is the Guest Visible Physical Memory. This indicates how much RAM the virtual machine has visible, and it also indicates the RAM demand. Perfmon also gives us the advantage of being able to track the RAM allocation on a graph.

Monitoring Dynamic Memory Usage in Virtual Machine
I’ve a VM with Windows 8.1 on it and the startup memory is configured with 2 GB. Dynamic Memory is also enabled on the VM with minimum of 512 MB and a maximum of 4 GB. 
When the VM is powered on, in the task manager, the memory usage is around 25% (0.5 GB) and in the RamMap, the unused memory is around 1.1 GB.


When the Hyper-V host sees that there is some idle memory on the host, it starts reclaiming it and the memory usage goes to 75 % and when you analyse the processes running the virtual machine, you will not be able to find any process eating up all that memory. The reason why the memory usage went high after some time from 25% to 75% is because of Dynamic Memory which has been enabled. The host saw that there is some idle memory, so it reclaimed around 1 GB of memory and locked it. If you refresh in RamMap, you can see around 1.1 GB of RAM has been locked and you can see that under Driver Locked.


Back to Task Manager, you can see that it is intelligent enough to identity the maximum memory specified for the virtual machine and because of that it shows up the maximum memory that this VM can have. Hence the startup memory is 2 GB and the maximum memory is 4 GB. Next, I’ll use a tool called TestLimit which can leak the memory you specify in MB. In command prompt, I’ll type testlimit64 –m 2048 which will leak 2 GB of memory.


As soon as I do that, you notice, in the task manager there is sudden dip with respect to memory usage, the usage comes down and it is now showing that the memory of the VM is 4 GB which is actually the maximum memory that we specified for the VM in Dynamic Memory settings. In RamMap, the driver that had locked around 1 GB of memory has been released and the unused space has become around 3 GB because we had specified 4 GB of memory in maximum memory setting of Dynamic Memory.


If I cancel the memory leak, the load will be removed, but the installed memory still reports 4 GB. This is because the visible amount of RAM will never drop below the highest allocated amount and the highest allocated amount is defined by the maximum memory value of Dynamic Memory setting for the virtual machine. If you let this virtual machine run for some time then the host will see some idle memory and it will lock it and if you go back to the task manager the memory usage will be around 75% and in the RamMap would have locked around 3 GB or memory.

Youtube Video




Thursday, 24 December 2015

Migrating a spanned volume to another server

Have you ever been in a situation where you need to move a spanned volume from one Windows server to another? Well, it can be done using the "Import foreign disk" feature in Disk Management.

Caution - Drives with Bit Locker Drive encryption cannot be moved using this technique. Windows Vista Enterprise and Ultimate editions include Bit Locker Driver Encryption that wraps drives in a protected seal so that any offline tampering is detected and results in the disk being unavailable until an administrator unlocks it.

In my example lab, I've three dynamic disks that needs to be moved from Windows Server 2008 R2 to Windows Server 2012.

These three dynamic disks are spanned and the size of each disk is 1 GB.


Before you move the disks, it is always recommended that you have a very good backup of the drive and also ensure that the disk status is "Healthy". If they are not healthy, you should repair the volumes before you move them.

Microsoft recommends that you uninstall the disks from Device Manger and then remove the disks from the Disk Management. But it is not required to do that. 

You can simply shutdown your source server and remove the disks from them. You need to remove all disks which makes up the spanned volume and attach them together to the destination server.

You may need to power off your destination server, if it doesn't support hot-plug.

After you attach the disks together and power on the destination server, open Disk Management and bring the new disks online.


When the disks are online, they show up as foreign disks, right-click on one of them and click "Import Foreign Disks..."

Ensure that the foreign disk group is selected and also ensure that it lists all the disks of your spanned volume.
Click OK on Import and click OK again on the window where it shows spanned volume information. 
Your spanned volume should get mounted without any errors. You should also be able to see all your data.
Below are the official documentation from Microsoft to move a dynamic disk to another server.

https://technet.microsoft.com/en-us/library/cc779854(v=ws.10).aspx
https://technet.microsoft.com/en-us/library/cc753750.aspx

Note - The volumes on the dynamic disks should retain the drive letters that they had on the original computer. If a drive letter is already used on the destination computer, a volume receives the next available drive letter. If a dynamic volume previously did not have a drive letter, it does not receive a drive letter when moved to another computer. Additionally, if auto-mounting is disabled, the volumes aren't automatically mounted and you must manually mount volumes and assign drive letters.

The same above procedure can be followed if you performing these steps on a physical or virtual server.

Youtube Video




Migrate Printers from Windows Server 2008 R2 to Windows Server 2012 R2

In this article, I'll walk you through the process of migrating printers from a Windows Server 2008 R2 to Windows Server 2012 R2.

If you are planning to migrate printers from  Windows Server 2003 to a newer version of Windows operating system then you need to use a tool called PRINTMIG.exe which is a free tool from Microsoft. This tool is built into the newer operating system starting from Windows Server 2008. If you are planning to move printers from Server 2008 to a newer operating system then you can use the built-in print migration tool.

Before you start migrating the printers from a source server to destination server, you need to ensure that the compatible printer drivers are available for the operating system running on the destination server. Upgrading from a print server that is currently on Server 2008 is much easier than if you are migrating from a server currently running Server 2003 and it is because of the lack of 64-bit driver support from most 2003 server setups. You also need to install all your 32-bit print drivers on your new 64-bit print drivers and these are the print drivers which are currently installed on your 32-bit OS of your source print server. Also you need to install all 64-bit print drivers on your destination print server which is running 64-bit OS, if your source print server is a 32-bit OS and it needs to be done by manually adding each of the 64-bit drivers before you can start the migration. For example, if you have 200 printers on your 2003 print server, you would need to add the 64-bit driver of all 200 of those printers to your new 2012 server before you can complete the migration successfully. On the source print server, ensure that all your print drivers are up-to-date and see if you can use universal drivers if possible.

If Active Directory is being used to publish printers then you need to unpublish the printers before you start the migration and it is done to avoid printers being published twice.

After performing all the above pre-checks, the next step is to install Print and Document services role on the new print server.

The next step is to export the print queues, drivers, objects and security settings into a printer data file from the source print server and import that into the destination printer server. You would then shutdown or rename the old print server and assign the old print server name to the new print server to avoid hostname duplication. Finally publish all printers back to Active Directory and testing all the print queues that have been migrated.



In my lab environment, I've a domain controller DC01 and two print servers (PRINTSERVER01 and PRINTSERVER02). PRINTSERVER01 is running Windows Server 2008R2 and it has two network printer attached to it. PRINTSERVER02 is running Windows Server 2012 R2. We will be moving the printers from PRINTSERVER01 and PRINTSERVER02. Both print servers are joined to the domain. I've done all the pre-checks with respect to print drivers. I'm going to shutdown PRINTSERVER01 and rename the new print server to take the old print server name.

To start the migration process, first I'm going to unpublish the printers from Active Directory.
  1. On PRINTSERVER01, Login as an Administration.
  2. Open Print Management from Administrative Tools, click "All Printers" and select all the printers that you want to unpublish from Active Directory and right click on them. 
  3. Click "Remove from Directory" to unpublish them from Active Directory.

Next install the "Print and Document Services" role on the new print server (PRINTSERVER02)
  1. Login as an Administrator.
  2. Open Server Manager and click Add roles and features in the Dashboard.
  3. Click Next on "Before you Begin" screen.
  4. Click "Role-based on feature-based installation" and click Next.
  5. Select the server on which you want to install the role and click Next.
  6. In Select server roles screen, select "Print and Document Services" role and click Next. Click Add Features to install the management tools and features that are required for "Print and Documents Services". Click Next.
  7. Keep the default selection in the Select features screen and click Next.
  8. Click Next on the Print and Document Services introductory screen.
  9. For the Role Services, select "Print Server" and click Next.
  10. Click Install on the Confirmation screen.
  11. Ensure that the installation has successfully completed and click close.


After installing the "Print and Document Services" role on the new print server, it is time to export the print queues, drivers, objects and security settings from the source print server (PRINTSERVER01) into a printer data file.
  1. Log back into PRINTSERVER02 as an administrator.
  2. Back in Print Management tool, right-click on the Print Management on the left side and click Migrate Printers.
  3. Select Export printer queues and printer drivers to a file and click Next.
  4. In Select a print server screen, select "A print server on the network" and type the old print server name which is PRINTSERVER01. Type the UNC path of the old print server name (\\PRINTSERVER01) and click Next.
  5. Review the list of print queues, drivers, processors and ports that will be exported and click Next.
  6. Specify a path to save the printer data file and click Next.
  7. Ensure that the export was successful with no errors and click Finish.

Now that we have exported all the printers as a printer data file, we can now import them to our new print server (PRINTSERVER02).
  1. Back in PRINTSERVER02, I've logged in as an admin.
  2. Back in Print Management tool, right-click on the Print Management on the left side and click Migrate Printers.
  3. Select Import printer queues and printer drivers to a file and click Next.
  4. Locate the printer data file and click Next.
  5. Review the list of print queues, drivers, processors and ports that will be imported and click Next.
  6. In Select a print server screen, select "This print server" and click Next.
  7. In Select import options, for Import mode, select "Keep existing printers" which will keep the existing printers on the destination print server and the other option "Overwrite existing printers" will overwrite the existing printers. You have 3 options for "List in the directory". The first one "List printers that were previously listed" will publish the printers back to Active Directory where were publish before but not now and second option is to list all printers which will publish all printers to Active Directory regardless of whether they are already published or not. Third option is "Don't list any printers" which will not publish any printers. In my case, I'll select Don't list any printers. There is another option to covert LPR ports to Standard Port Monitors which I'll not select and I'll click Next.
  8. Ensure that the import was successful with no errors and click Finish.
  9. Go into "All Printers" and see if the printers have been imported.

Below are the few last steps that you need to perform.
  1. Shutdown or rename the old print server. Assign the old print server name to the print server to avoid hostname duplication.
  2. Publish all printers back to Active Directory, if required. The process of publishing the printers back to Active Directory is similar, you just need to right-click on the printer(s) and click "List in Directory".

Expected Error during Migration
Some errors are to be expected, if you have TYPE 2 drivers, they will not be imported because Windows Server 2012 or Windows Server 2012 R2 only supports TYPE 3 and TYPE 4 drivers.


Below are the few post checks that you need to perform after migration.
  1. View event log messages about the migration.
  2. Manually check the destination print server for each printer migrated from the source print server.
  3. Verify that the printer associated with each printer queue is online.
  4. Confirm that a printer queue’s special settings, permissions, or drivers were preserved during the migration.
  5. Check the properties for each queue on the destination server and verify that any special settings are still applicable.
  6. If the driver installs any non-standard settings that have been altered as a result of the migration, verify those as well.
  7. Make any necessary changes, such as adding a port monitor or a new driver.

Youtube Video


Sunday, 20 December 2015

Backup a Windows Server 2012 R2 Domain Controller

In this article, I'll walk you through with the simple procedure of backing up a Windows Server 2012 R2 domain controller using native backup tool of Windows Server 2012 which is Windows Backup. Windows Backup tool is a good enough tool to backup a domain controller. Unlike other third-party backup solutions, Windows backup tool no longer supports backup to tape feature, so you'll need a disk available that doesn't host the operating system files or the Active Directory NTDS database and log files.

In my lab environment, I've a domain controller running Windows Server 2012 R2 with two disks.
  • C:\ - Windows operating system (Also contains NTDS database and log files of Active Directory)
  • D:\ - A dedicated drive used for backups.
Before we can start the backup on a domain controller or on any Windows Server, we need to install Windows Backup feature. You can follow the below procedure to install the Windows Backup feature on a domain controller and to backup a domain controller.
  1. Log on to the domain controller (DC01) with a domain admin credentials.
  2. Open Powershell and type Add-Windowsfeature windows-server-backup and press Enter
  3. Open Server and click Tools to select Windows Server Backup \
  4. In the Windows Server Backup console, click Local Backup in the left pane.
  5. Select Backup Once under Actions in the right pane. If required, you can create a backup schedule to backup the server on a regular basis.
  6. In the Backup Once Wizard, select Different Options and click Next.
  7. On the Select Backup Configuration screen, select Full server (recommended) and click Next.
  8. On the Specify Destination Type screen, select Local drives and click Next. 
  9. On the Select Backup Destination screen, select your dedicated backup volume in the Backup destination drop-down menu. My dedicated backup volume is D:\
  10. Click OK to confirm that you want to exclude the selected drive from the backup items.
  11. Click Backup on the confirmation screen.
  12. Now the domain controller will be backed up. Once the backup is successful. You can close the Backup Once Wizard.
To check the last successful backup of AD, you can run repadmin /showbackup


Youtube Video