2017年11月25日星期六

Configure Storage Quality of Service (QoS)

If multiple virtual disks stored on a single physical disk, these virtual machines running simultaneously and accessing their virtual disks from the same physical disk,one virtual disk possible monopolize the physical disk's I/O,causing the other virtual disks to slow down. To help prevent this,you can control the Quality of Service(QoS)for a virtual hard disk.

You can open the Settings dialog box for a virtual machine in Hyper-V Manager, expand a hard drive component, select Quality Of Service, and select the Enable Quality Of Service Management check box on the Quality Of Service page. Now, you can specify minimum and maximum IOPS values for the virtual disk.





























Note: Minimum and maximum IOPS are measured in 8 KB increments.

You can use the Set-VMHardDiskDrive cmdlet on Windows PowerShell to configure these setting.
VMName: virtual machine name
ControllerType: virtual hard disk controller type
ControllerNumber:  virtual hard disk controller number, Starting from 0


Resize a virtual hard disk for Hyper-v Server

Open the Hyper-v Manager, right-click Hyper-v Server and select Edit Disk; or in the Actions pane,select Edit Disk.



















Click Next


























Click Browse to select the virtual disk you want to change, then click Next.























Select the action you want to perform. You can do the following:
Compact: Reduces the size of a dynamically expanding or differencing disk by deleting empty space, while leaving the disk’s capacity unchanged.
Note: After the file is delete in the dynamic hard disk, the size of the hard disk file will not chang. For example,a dynamic hard disk file has 20GB, I copied a 10GB file to the hard disk, this moment the size of the hard disk file is 30GB, when I delete the 10GB file in this hard disk, the hard disk file size still 30GB. At this point you need to use Compact.
Convert: Creates a copy of the disk image file, enabling you to change the format (VHD or VHDX) or the type (fixed size or dynamically expanding) in the process.
Expand: Increases the capacity of the disk. 
Shrink: Reduces the capacity of the disk by deleting empty storage space from the file. The option only appears when there is unpartitioned space available at the end of the virtual disk.
Note: When the virtual machine is running only Expand and shrink options are available.
Merge: combine the data on the differencing disk and its parent disk to form a new file. The option only appear when you select a Differencing disk.
In this example, I chose Expand. Then click Next.























Type new virtual disk size in the New Size text box. Then click Next.























Click Finish























You can use the Optimize-VHD cmdlet on Windows PowerShell to compact a virtual hard disk file.






You can use the Convert-VHD cmdlet on Windows PowerShell to convert a virtual hard disk file. Form a VHD file to a VHDX file, from a fixed size file to a dynamic file or from a fixed size VHD file to a dynamic VHDX file.










You can use the Resize-VHD cmdlet on Windows PowerShell to expand or shrink a virtual hard disk size.









You can use the Merge-VHD cmdlet on Windows PowerShell to merge a differencing disk into its parent disk.

Adding virtual disks to virtual machines for Hyper-v Server

On Hyper-V Manager, right-click a virtual machine of you want to add virtual disk and select setting.






















Select IDE Controller 0, one the IDE Controller page, select Hard Drive, and click Add.
Note: Generation 2 is  SCSI Controller.





























You can select New to open a New Virtual Hard Disk Wizard or select Browse to add a existing virtual disk.
Then click OK.





























Note: Generation 1 virtual machines need to be shut down to add virtual disks

2017年11月18日星期六

Using an existing Virtual Hard Disk when creating a virtual machine

When you create a new Virtual Machine in Hyper-V Manager, the New Virtual Machine Wizard includes a Connect Virtual Hard Disk page. This page contains the following content:
Create A Virtual Hard Disk: You can specify the name,location,and size for a new Virtual Hard Disk. But this option can only create a dynamically expanding VHDX format virtual Hard disk.
Use An Existing Virtual Hard Disk: Enable you to specify an existing Virtual Hard Disk as the Virtual Machine's system disk.
Attach A Virtual Hard Disk Later: Skip this step now and add an existing virtual Hard Disk later。

Select use an existing virtual hard disk, and specify the location of the virtual disk in the location text box.

Creating virtual disk in the Hyper-V Server

Understanding virtual disk formats
Windows Server 2016 Hyper-V supports two kinds ofVirtual Disk:VHD and VHDX.

VHD

  • Maximum support to 2TB
  • Compatible with all versions of hyper-v

VHDX
  • Only support Windows Server 2012 R2 or later and Windows 8.1 or later
  • Maximum support to 64TB
  • Support 4KB logical sector
  • larger block(Up to 256 MB)


Creating a Virtual Disk
Windows Server 2016 Hyper-V provides several ways to create virtual disk files. You can create them while create a new Virtual Machine. Or you can also create them using the New Virtual Disk Wizard. Or you can create them using Windows PowerShell.

Creating a new virtual disk in Hyper-V Manager
Open Hyper-v Manager, Right-click the Hyper-v Server,Select New | Hard Disk. Or from the Action menu,select New | Hard Disk.

















Click Next























Select one of the following disk format options:
VHD: Create a virtual hard disk with less than 2TB and highly compatibility
VHDX: Create a virtual hard disk with greater than 2TB
VHD SetIt's a share Virtual Hard Disk. You can share virtual disk files between multiple virtual machines. Used for failover clustering.
Then Click Next























Select one of the following disk type options:
Fixed Size:The Virtual Hard Disk file size is the same as the Virtual Hard Disk space size. Such as, a Virtual Hard Desk size is 50G,the VHD or VHDX file size is 50G.
Dynamically Expanding: Virtual hard disk file starts small, with more and more data written, virtual hard disk file is also growing, until it reaches the size of the virtual hard disk space.
Differencing: It is a child virtual hard disk file that is associated with a specific parent virtual hard disk file. All system changes will be written to the child virtual hard disk file.
Then Click Next.























Note
It is recommended to use the Fixed Size in production environment. While the Fixed Size allocates all size all at once, waste of disk space, but it provides the best performance.
The Dynamically Expanding while saving space, but their continued growth will have an impact on performance,and also Over-allocation physical disk space.
The Differencing is more suitable for scenes that require frequent return to a certain state of the system.

But it is useful to have Dynamically Expanding and Differencing in test environments


Specify a filename for the Virtual Hard Disk in the Name text box,If necessary, Specify a Non-default location for the file.























Select and configuration one of the following options:
Create A New Blank Virtual Hard Disk: Create a new Virtual Hard Disk and specifie the size.
Copy The Contents Of The Specified Physical Disk: Select one of the physical hard disk in the computer and copy its contents to the new Virtual Hard Disk.
Copy The Contents Of The Specified Virtual Hard Disk: Select an existing Virtual Hard Disk file and copy its contents to the new Virtual Hard Disk.
Then Click Next























Click Finish
























Creating a new virtual disk using Windows PowerShell
You can create a new virtual hard disk files using New-VHD cmdlet in Windows PowerShell
Path: The store path of the Virtual Hard Disk
Test.VHDX: The Name and format of the Virtual Hard Disk. The extension name you specify for the filename determines the format(VHD or VHDX of the virtual disk.
Dynamic: Create a dynamic extended virtual disk.You can use Fixed and Differentiating to create a virtual disk of Fixed size or difference.
SizeBytsSpecify size of Virtual Hard Disk 












You can also specify block and logical sector size using BlockSizeBytes and LogicalSectorSizeBytes parameters


2017年11月9日星期四

The virtual machine configuration is not compatible while importing the virtual machine in Hyper-v server

The following error occurred while importing the virtual machine:
Unable to import virtual machine due to configuration errors.  Please use Compare-VM to repair the virtual machine.





This issue is due to the configuration of the virtual machine is not compatible with the existing Hyper-V host.

Solution:
Get a compatibility report for this virtual machine.


Displays the compatibility report.  the virtual network adapter was connected to switch RDS Natwork, but the Hyper-V host has no switch by that name.




Disconnects the virtual network adapter.


Review the compatibility report again to determine whether the virtual machine is compatible with the hyper-v host.






Import the Virtual Machine.
You can also add parameters to define the imported virtual machine.
 Such as, you can add -Copy and -GenerateNewId parameters, copying the Virtual Machine's files to the default virtual machine and virtual hard drive storage locations of the Hyper-V host, and generate a new Virtual Machine ID.





Export and import VMs in Hyper-v Server

Importing and exporting virtual machines in hyper-v is a way to move virtual machines to other servers.

When you export a VM, You need to specify a path. The system will create a copy of all the files of the virtual machine to this path, including configuration files, virtual hard disk and checkpoint. Ceckpoint also call snapshot. You can export a Virtual Machine while it is running or stopped.

Export Virtual Machine using Hyper-v Manager
Open Hyper-v Manager, Right-Click the Virtual Machine you want to export, and select Export.


















Specify a location store Virtual Machine files and click Export



















You can see the Virtual Machine Export progress in the status bar



















When exporting a virtual machine, you can select Cancel Exporting in the Action pane cancel the export








You can also export Virtual Machine using Export-VM cmdlet in Windows PowerShell
Name: VM's Name
Path: Path of VM export






Import Virtual Machine using Hyper-V Manager
Open Hyper-v Manager, Select Import Virtual Machine in Action pane.

















Click Next
























Browse to the folder containing the exported files.
























Click Next
























Chose you want to import VM's type:
  • Register The Virtual Machine In Place: Store the exported file where you want and register the virtual machine on the Hyper-V server with the same virtual machine ID.
  • Restore The Virtual Machine: Assuming your exported files that are stored in a removable storage, you can choose this option to move the files to the right place,then register the virtual machine on the Hyper-V server with the same virtual machine ID.
  • Copy The Virtual Machine: If you want to import this virtual machine many times, for example, you want to use this virtual machine as a template, you can choose this option. Copy the virtual machine to the right place, and generate a new ID, then register this virtual machine.
I select Copy The Virtual Machine in here. Then click Next.
























Specify the store location of the configuration file, checkpoint file, and smart page file of the virtual machine. Then click Next
























Specify the store location of the Virtual Hard Disk
























Click Finish























When Exported Virtual machine is saved state,you need to delete the saved state to run the virtual machine.
Right-Click the Virtual MachineSelect Delete Saved State.




















Click Delete























When the names of the virtual switches on two Hyper-V hosts do not match, you will get an error like a following.
Solution:Select the available virtual switch in the connection option
























You can also import Virtual Machine using Import-VM cmdlet in Windows PowerShell
Copy: Copying the Virtual Machine's files to the default virtual machine and virtual hard drive storage locations of the Hyper-V host.
GenerateNewId: Generate a new Virtual Machine ID






Note: When importing a virtual machine, you need to enter the full path of the virtual machine's configuration file.

If you want to import the Virtual Machine from it's configuration file, and the Virtual Machine is registered in-place. You can use following command:
Import-VM -Path 'the full path to the virtual machine's configuration file' -Register

To specify different locations for the copied files, you can add the following parameters to the command line:
  • VirtualMachinePath
  • VhdDestinationPath
  • SnapshotFilePath
  • SmartPagingFilePath