# cd /usr/ports/sysutils/bhyve-firmware/ && make install clean
# cd /usr/ports/sysutils/vm-bhyve/ && make install clean
# cd /usr/ports/net/tigervnc-viewer/ && make install clean
注意,如果你运行的是 Windows 10 之前的旧版本或当你想在 Windows 系统上安装 Microsoft SQL Server 时,你需要使用参数 disk0_opts="sectorsize=512" 把磁盘扇区大小设置成 512。
根据模板创建 windows 虚拟机,磁盘占用 40GB:
# vm create -t windows -s 40G winguest
技巧
销毁虚拟机的命令:
root@ykla:/usr/home/ykla# vm destroy winguestAreyousureyouwanttocompletelyremovethisvirtualmachine (y/n)? Are you sure you want to completely remove this virtual machine (y/n)?# 这里输入 y 回车即可删除
loader="uefi"# 不支持 UEFI 的 windows 不能够启动,例如 XP 操作系统,但是请注意 win7 是支持 UEFI 的graphics="yes"# 指定暂停虚拟机直至 VNC 链接。xhci_mouse="yes"cpu=2# CPU,这个最好多给一些memory=4G# 内存# put up to 8 disks on a single ahci controller.# without this, adding a disk pushes the following network devices onto higher slot numbers,# which causes windows to see them as a new interfaceahci_device_limit="8"# ideally this should be changed to virtio-net and drivers installed in the guest# e1000 works out-of-the-boxnetwork0_type="e1000"# 开箱即用的虚拟网卡network0_switch="public"# 虚拟交换机disk0_type="ahci-hd"disk0_name="disk0.img"# windows expects the host to expose localtime by default, not UTCutctime="no"# 指定 windows 使用 UTC 时间,避免时间差 8 个小时graphics_res="1920x1080"# 指定 VNC 链接的屏幕分辨率,可用数值在下文列出uuid="af86e094-56da-11ed-958f-208984999cc9"network0_mac="58:9c:fc:0c:5e:bb"root@ykla:/usr/home/ykla#
安装系统
指定 Windows iso 文件开始正常安装。当在安装模式下运行时,vm-bhyve 将等待,直到 VNC 客户端连接后再启动虚拟机。这能让你抓住 Windows 可能显示的提示“Press any key to boot from a CD/DVD“。你能在 vm list 中看到,在此时,虚拟机将显示为锁定:
# vm install winguest /home/ykla/en-us_windows_11_iot_enterprise_ltsc_2024_x64_dvd_f6b14814.iso # 替换成你自己的路径Startingwinguest*foundguestin/home/ykla/vm/winguest*booting...
从 VNC 访问 Win11
当出现Press any key to boot from a CD/DVD时,请快速地按几次回车键。
终止虚拟机:如果虚拟机卡死该命令无效,请自行 kill -9 以免影响关机,如果真的阻碍了物理机关机,可以在 tty 按 Ctrl+ C 跳过等待虚拟机,强制关机
root@ykla:~# vm listNAMEDATASTORELOADERCPUMEMORYVNCAUTOSTATEwinguestdefaultuefi24G0.0.0.0:5900NoRunning (2072)root@ykla:/usr/home/ykla# vm stop winguestSendingACPIshutdowntowinguest
如果无效:
root@ykla:~ # ps -el
UID PID PPID C PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
0 1858 1 1 68 0 16388 4 wait IW 3 0:00.00 () /bin/sh /usr/local/sbin/vm _run winguest /home/ykla/zh-cn_windows_11_business_editions_version_24h2_x64_dvd
root@ykla:~ # kill -9 1858
root@ykla:/usr/home/ykla# vm listNAMEDATASTORELOADERCPUMEMORYVNCAUTOSTATEwinguestdefaultuefi24G-NoStopped
查看指定的虚拟机状态:
root@ykla:/usr/home/ykla# vm info winguest------------------------VirtualMachine:winguest------------------------state:stoppeddatastore:defaultloader:uefiuuid:af86e094-56da-11ed-958f-208984999cc9cpu:2memory:4Gnetwork-interfacenumber:0emulation:e1000virtual-switch:publicfixed-mac-address:58:9c:fc:0c:5e:bbfixed-device:-virtual-disknumber:0device-type:fileemulation:ahci-hdoptions:-system-path:/home/ykla/vm/winguest/disk0.imgbytes-size:42949672960 (40.000G)bytes-used:23557898240 (21.940G)