# 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 winguest
Are you sure you want to completely remove this virtual machine (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 interface
ahci_device_limit="8"
# ideally this should be changed to virtio-net and drivers installed in the guest
# e1000 works out-of-the-box
network0_type="e1000" # 开箱即用的虚拟网卡
network0_switch="public" # 虚拟交换机
disk0_type="ahci-hd"
disk0_name="disk0.img"
# windows expects the host to expose localtime by default, not UTC
utctime="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 # 替换成你自己的路径
Starting winguest
* found guest in /home/ykla/vm/winguest
* booting...
从 VNC 访问 Win11
当出现Press any key to boot from a CD/DVD时,请快速地按几次回车键。
终止虚拟机:如果虚拟机卡死该命令无效,请自行 kill -9 以免影响关机,如果真的阻碍了物理机关机,可以在 tty 按 Ctrl+ C 跳过等待虚拟机,强制关机
root@ykla:~ # vm list
NAME DATASTORE LOADER CPU MEMORY VNC AUTO STATE
winguest default uefi 2 4G 0.0.0.0:5900 No Running (2072)
root@ykla:/usr/home/ykla # vm stop winguest
Sending ACPI shutdown to winguest
如果无效:
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
tap0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
description: vmnet/winguest/0/public
options=80000<LINKSTATE>
ether 58:9c:fc:10:ff:d6
groups: tap vm-port
media: Ethernet autoselect
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
Opened by PID 2519
可选配置
查看所有虚拟机状态:
root@ykla:/usr/home/ykla # vm list
NAME DATASTORE LOADER CPU MEMORY VNC AUTO STATE
winguest default uefi 2 4G - No Stopped