了解如何使用 Hyper-V 管理器和 Windows PowerShell 创建虚拟机,以及在 Hyper-V 管理器中创建虚拟机时可以使用哪些选项。
创建虚拟机
Open Hyper-V Manager.
In the left pane, under Hyper-V Manager, select your server.
From the Actions pane, select New, and then select Virtual Machine.
从新建虚拟机向导中,选择下一步。
在每个页面上为虚拟机做出适当的选择。 有关详细信息,请参阅 Hyper-V 管理器中的新虚拟机选项和默认值。
After verifying your choices in the Summary page, select Finish.
In Hyper-V Manager, right-click the virtual machine and select Connect....
In the Virtual Machine Connection window, select Action>Start.
On the Windows desktop, select the Start button and type Windows PowerShell.
Right-click on Windows PowerShell and select Run as administrator.
Get the name of the virtual switch that you want the virtual machine to use by using the Get-VMSwitch cmdlet:
Get-VMSwitch * | Format-Table Name
Use the New-VM cmdlet to create the virtual machine. 请参阅以下示例:
Note
If you move this virtual machine to a Hyper-V host that runs Windows Server 2012 R2, use the -Version parameter with New-VM to set the virtual machine configuration version to 5. Windows Server 2012 R2 或更早版本不支持 Windows Server 2016 的默认虚拟机配置版本。 创建虚拟机后,无法更改虚拟机配置版本。 有关详细信息,请参阅支持的虚拟机配置版本。
现有虚拟硬盘 - 若要创建具有现有虚拟硬盘的虚拟机,可以使用以下命令,其中,
-Name is the name that you provide for the virtual machine that you're creating.
-MemoryStartupBytes is the amount of memory that is available to the virtual machine at start up.
-BootDevice is the device that the virtual machine boots to when it starts like the network adapter (NetworkAdapter) or virtual hard disk (VHD).
-VHDPath is the path to the virtual machine disk that you want to use.
-Path is the path to store the virtual machine configuration files.
-Generation is the virtual machine generation. 对于 VHD,请使用第 1 代;对于 VHDX,请使用第 2 代。 请参阅是否应在 Hyper-V 中创建第 1 代或第 2 代虚拟机?。
-Switch is the name of the virtual switch that you want the virtual machine to use to connect to other virtual machines or the network. 请参阅为 Hyper-V 虚拟机创建虚拟交换机。
New-VM -Name <Name> -MemoryStartupBytes <Memory> -BootDevice <BootDevice> -VHDPath <VHDPath> -Path <Path> -Generation <Generation> -Switch <SwitchName>
For example:
New-VM -Name TestVM -MemoryStartupBytes 4GB -BootDevice VHD -VHDPath .\VMs\Test.vhdx -Path .\VMData -Generation 2 -Switch ExternalSwitch
这会创建名为 TestVM 且内存为 4 GB 的第 2 代虚拟机。 它从当前目录中的 VMs\Test.vhdx 文件夹引导,并使用名为 ExternalSwitch 的虚拟交换机。 虚拟机配置文件存储在 VMData 文件夹中。
新的虚拟硬盘 - 若要使用新的虚拟硬盘创建虚拟机,请将上一示例中的 -VHDPath 参数替换为 -NewVHDPath,并添加 -NewVHDSizeBytes 参数。 For example,
New-VM -Name TestVM -MemoryStartupBytes 4GB -BootDevice VHD -NewVHDPath .\VMs\Test.vhdx -Path .\VMData -NewVHDSizeBytes 20GB -Generation 2 -Switch ExternalSwitch
引导到操作系统映像的新虚拟硬盘 - 若要使用新的虚拟磁盘创建引导到操作系统映像的虚拟机,请参阅为 Windows 10 上的 Hyper-V 创建虚拟机演练中的 PowerShell 示例。
Start the virtual machine by using the Start-VM cmdlet. 运行以下 cmdlet,其中 Name 是创建的虚拟机的名称:
Start-VM -Name <Name>
For example:
Start-VM -Name TestVM
使用“虚拟机连接”(VMConnect) 连接到虚拟机:
VMConnect.exe <ServerName> <VMName>
For example:
VMConnect.exe localhost "TestVM"
Hyper-V 管理器新建虚拟机向导中的选项
下表列出了在 Hyper-V 管理器中创建虚拟机时可以选取的选项以及每个选项的默认值。
Page |
Windows Server 2016、Windows 10 及更高版本的默认设置 |
Other options |
指定名称和位置 |
名称:新虚拟机。 Location: C:\ProgramData\Microsoft\Windows\Hyper-V\. |
还可以输入自己的名称,并为虚拟机选择另一个位置。 这是虚拟机配置文件的存储位置。 |
Specify Generation |
Generation 1 |
还可以选择创建第 2 代虚拟机。 有关详细信息,请参阅应该在 Hyper-v 中创建第 1 代还是第 2 代虚拟机?。 |
Assign Memory |
启动内存:1024 MB Dynamic memory: not selected |
可以在 32 MB 到 5902 MB 范围内设置启动内存。 还可以选择使用动态内存。 有关详细信息,请参阅 Hyper-V 动态内存概述。 |
Configure Networking |
Not connected |
可以从现有虚拟交换机的列表中选择供虚拟机使用的网络连接。 请参阅为 Hyper-V 虚拟机创建虚拟交换机。 |
连接虚拟硬盘 |
创建虚拟硬盘 Name: <vmname>.vhdx Location: C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\ Size: 127 GB |
也可选择使用现有虚拟硬盘或稍后再附加虚拟硬盘。 |
Installation Options |
稍后安装操作系统 |
这些选项会更改虚拟机的引导顺序,以便你可以从 .iso 文件、可引导软盘或网络安装服务(如 Windows 部署服务 (WDS))进行安装。 |
Summary |
显示所选选项,以便可以验证它们是否正确。 - Name - Generation - Memory - Network - 硬盘 - 操作系统 |
Tip: You can copy the summary from the page and paste it into e-mail or somewhere else to help you keep track of your virtual machines. |
Related content