2017年10月28日星期六

Configure smart paging for Hyper-v

Smart paging allows us to temporarily use disk resources in place of physical memory.

A lot of people to have the misconception that smart paging is related to the Windows Pagefile.  In actuality, the Windows Pagefile and the Smart Paging File are very different from one another.

We have talked about dynamic memory in front, there are three values in the dynamic memory: RAM, the smallest memory and maximum memory.RAM is the starting memory, the minimum memory is the minimum memory allocated to the virtual machine, the maximum memory is allocated to the virtual machine's largest memory.

In the process of using dynamic memory, usually RAM and minimum memory have different values, the minimum memory is lower than RAM. When multiple virtual machines run at the same time, and use all physical memory. at this time the virtual machine can run normally, but when you need to restart the virtual machine, there is not enough physical memory to provide RAM set values. the virtual machine can run normally, but when you need to restart the virtual machine, there is not enough physical memory to provide RAM set values.  Once the virtual machine starts up and releases the memory, the paging stops immediately.

For example, a Hyper-v Server has 64GB of memory, which can run up to 30 virtual machines, each virtual machine RAM value of 2GB memory, the minimum memory of 512M. When the virtual machine running only 1GB of memory, then 30 virtual machines have been all started and continue to run. At this point Hyper-v will release the useless 30GB of memory, we can be used to run more virtual machines. With the increase of the virtual machine, this 30GB of memory has also been used, and suddenly there is a virtual machine need to restart, but the RAM value of 2GB, while the unused memory only the original operation of the virtual machine 1GB memory, intelligent paging will Will use the hard disk space, to replace the lack of 1GB of memory, so that the virtual machine can start normally.

So why not set the value of RAM and the minimum memory value to the same? Because some operating systems perform a check to make sure that a certain amount of memory is present,and Some operating systems consume more memory at boot time than they do when the system is idle. If you set the same value, it will cause a waste of memory.

The following criteria must be met:
The VM is restarting (not booting from an off state)
No physical memory is available or can be reclaimed from other VMs

You can configure Smart Paging on the Virtual Machine Settings page

2017年10月24日星期二

Dynamic memory settings for Hyper-v

To use dynamic memory, you select the enable Dynamic Memory check box on the Memory page of the Settings dialog box, or When creating a virtual machine, Select use the dynamic memory for this virtual machine check box on the Assign Memory page.

Then, you configure the following memory settings:
RAMThe value of memory when the virtual machine starts
Minimum RAM:Specifies the minimum amount of memory that should be allocated to the virtual machine after the virtual machine has started. The default setting is 512 MB.
Maximum RAM:Specifies the maximum amount of memory that this virtual machine is allowed to use. The value can be set from as low as the value for Startup RAM to as high as 1 TB.
Memory buffer:Specifies the percentage of the currently allocated memory that dynamic memory should retain as a buffer for future expansion. For example, if the memory committed to the guest operating system is 1000 MB and the memory buffer is 20%, Hyper-V will attempt to allocate an additional 20% (200 MB) for a total of 1200 MB of physical memory allocated to the virtual machine.

Amount of memory buffer=how much memory the virtual machine actually needs / (memory buffer value / 100).

NoteThe buffer is not maintained when there is not enough physical memory available in the computer to give every virtual machine its requested memory buffer.
Memory weight:Provides Hyper-V with a way to determine how to distribute memory among virtual machines if there is not enough physical memory available in the computer to give every virtual machine its requested amount of memory.





























Dynamic Memory Limitations:
You cannot enable or disable dynamic memory when the VM is running.
You cannot modify the RAM setting when dynamic memory is enabled.
You can reduce, but not increase, the Minimum RAM setting when the VM is running.
You can increase, but not reduce, the Maximum RAM setting when the VM is running.

Add or remove memory in running a VM

On a Windows Server 2012 R2 or earlier Hyper-v server, you can't modify the size of the virtual machine that is running, and on the physical machine, you need to shut down the virtual machine to add or remove memory.

However, on Windows Server 2016 Hyper-v Server,you can increase or decrease the assigned memory at the virtual machine that is running.

Right-click on the virtual machine that you want to change memory, select setting,on the memory page,you can change memory in running a VM.





























To change the memory allotment with PowerShell, you also can use the Set-VMMemory cmdlet

2017年10月21日星期六

Creating a Virtual Machine on Hyper-v

From the Tools menu of the Server Manager window, select Hyper-V Manager.
























In the left pane of the Hyper-V Manager console, select a Hyper-V server. Right-click this Hyper-v Server, Select New\Virtual Machine.(Or in the Actions pane, choose New\Virtual Machine.)



















Click Next


























In the Name text box, type a name for the virtual machine. Hyper-V also uses this name to create the VM files and folders. Then click Next.



























Specify the type of virtual machine you want to create. ( Generation 1 or Generation 2. ) Then click Next.


























In the Startup Memory text box, type the size of memory you want assign the virtual machine to use, and click Next.



























From the Connection drop-down list, select a virtual switch, and click Next.
Select the Create A Virtual Hard Disk option, and type the Virtual Hard Disk's Name,Location and size. Then click Next



























Select the Install An Operating System Later option,then click Next



























Click Finish.




























Creating a VM in Windows PowerShell
To create a new virtual machine with Windows PowerShell, you can use the New-VM cmdlet
New-VM –Name "Server_4" –Generation 2 –MemoryStartupBytes 2GB –NewVHDSizeBytes 127GB -NewVHDPath "C:\Hyper-v\Virtual Hard Disk\Server_4.vhdx"
Name:Name of Virtual Machine
Generation:Virtual Machine type (Generation 1 or Generation 2)
MemoryStartupBytes:Size of Startup Memory
NewVHDSizeBytes:Size Virtual Hard Disk
NewVHDPath:Path of Virtual Hard Disk(Include name of Virtual Hard Disk)

Nested virtualization for Hyper-v

Nested virtualization is a feature that allows you to run Hyper-V inside of a Hyper-V virtual machine.

Prerequisites
A Hyper-V host running Windows Server 2016 or Windows 10 Anniversary Update.
A Hyper-V VM running Windows Server 2016 or Windows 10 Anniversary Update.
A Hyper-V VM with configuration version 8.0 or greater.
An Intel processor with VT-x and EPT technology.


Configure Nested Virtualization
While the virtual machine is in the OFF state, run the following command on the physical Hyper-V host.
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true





After, you must make the following configuration changes on the VM that function as a Hyper-V host.
On the Memory page, disable Dynamic Memory. Or using PowerShell cmdlet.
set-vmmemory -vmname server1 -dynamicmemoryenabled $false








On the Processor page, or using PowerShell cmdlet set Number Of Virtual Processors to 2 or more.
set-vmprocessor -vmname server1 -count 8





On the Network Adapter/Advanced Features page, turn on MAC Address Spoofing.
Set-VMNetworkAdapter -VMName Server_1 -Name "NetworkAdapterName" -MacAddressSpoofing On











If you do not know Network Adapter Name, you can using Get-VMNetworkAdapter command to view.

Now, you can start the VM, install the Hyper-V role, and create nested virtual machines. While the VMs run on the nested host, there are some Hyper-V features that do not work, such as live memory resizing, checkpoints, Live Migration, and Save/Restore.

Remote management of Hyper-V hosts

Remote management using Hyper-V Manager in domain environment
Open Hyper-V Manager, Then, In the left pane, right-click Hyper-V Manager, and select Connect To Server.
























Select Another Computer,and type the Name or IP of the computer you want to manage.












You can also click Browse to open a standard Select Computer search box,in wich you can search for a computer name.






















Click OK,The computer you want to manage will be appears in the left pane. In the left pane, select the computer you want to manage. The virtual machines on that computer appear in the center pane.



































Remote management using Hyper-V Manager in WorkGroup environment
Connecting to a remote Hyper-V server when both computers are joined to the same AD DS domain is easy. The computers use Kerberos for authentication, which is brokered by a domain controller. When the computers are not in the same domain, or not in any domain, the authentication process is more complicated, because the computers cannot use Kerberos. Therefore, you must configure them to use the Credential Security Support Provider (CredSSP) authentication protocol instead.

On the remote (managed) server:
Creates the firewall rules needed to allow the incoming management traffic using enable-psremoting cmdlet
Enables the use of CredSSP for authentication using enable-wsmancredssp cmdlet













On the local (managing) computer:
Add the fully-qualified domain name of the Hyper-V server to be managed to the local system's WSMan trusted hosts list.
set-item wsman:\localhost\client\trustedhosts -value "hypervserver.domain.com"
enables CredSSP on the client
enable-wsmancredssp -role client -delegatecomputer "hypervserver.domain.com"
Note:hypervserver.domain.com" is Hyper-v Server's FQDN

















On the Select Computer page, Select you want connetc to Hyper-v Server, and check Connect as another user: <none>. Then Select Set User












Type the user name and password with administrative privileges.
















Select OK,Connect to Hyper-v.














Remote management using PowerShell
To connect to the remote Hyper-V server from an administrative PowerShell session, you must first create a session, using the New-PSSession cmdlet











To enter the session, you use the Enter-PSSession cmdlet
Note:1 is session ID












If you are not currently logged on with an account that has administrative privileges on the remote server, you can enter a session using another account with the following command:
enter-pssession # -credential DomainName\UserName


















Now you can use the relevant PowerShell command to manage Hyper-v. Such as displays the virtual machine running on the Hyper-v Server using Get-VM















Exit the session using Exit cmdlet


Hyper-v Introduction and Install

Introduction
Hardware requirements:
  • 64-bit processor
  • Support hardware-assisted virtualization(Intel VT;AMD AMD-v)and has been enabled
  • Hardware-enforced Data Execution Prevention (DEP)
  • Intel eXecuted Disable (XD) and AMD No eXecute (NS).
  • Enough memory - plan for at least 4 GB of RAM. More memory is better.

To determine whether the computer meets the hardware requirements of the Hyper-v role, you can run the Systeminfo.exe command on PowerShell. At the bottom of the results, the Hyper-v requirements item lists the computer's hypervisor capability.




























Hyper-V hardware limitations
  • support up to 512 logical processors
  • support up to 2,048 virtual CPUs
  • support up to 24 terabytes (TB) of physical memory

 Virtual Machine limit
  • per host can support as many as 1024 active virtual machine
  • each Generation 2 virtual machine can support up to 240 virtual machine and 12 TB of memory
  • each Generation 1 VMs can support up to 64 virtual CPUs and up to 1 TB of memory


Install Hyper-v
Select Add Roles And Features in the Server Manager console
















Click Next



























Select Role-Based or Feature-Based Installation and click Next



























Select the server on which you want to install Hyper-V and click Next



























Select the Hyper-V role check box. And in the pop-up Add Roles and Features wizard dialog box, select Add Feature. Then click Next.



























Click Next



























Click Next



























Select a network adapter as a Virtual switch and click Next



























Click Next



























specify the default locations for virtual hard disk and virtual machine configuration files, and click Next



























Click Install



























After installed, Click Close and restart computer




























You can also install the Hyper-V role with the Install-WindowsFeature cmdlet in PowerShell
Install-WindowsFeature –Name hyper-v -Includemanagementtools –restart