kvm 的macos虚拟主机下,加装一个win10系统,为方便改oc和测试硬件直通

kvm下Windows的硬件直通,还是很简单的。macos 不容易。所以,先同环境弄一个win

已经基本完成了一个macos的安装:https://dev.leiyanhui.com/kvm/install-macos-base/ 但是 卡到爆炸 先做好基本的优化,比如:打开屏幕共享 ssh,汉化,关机 然后尝试先从windows下完成这部分硬件的直通。

先安装一个windows

qemu-img create -f raw  -o size=15G /mnt/ext4/win10-q35-efi.img

把前面的shell命令稍微修改一下

  • 临时去掉macos的盘
  • 挂上win10安装iso
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sudo pacman -S screen
screen -S win

qemu-system-x86_64 -enable-kvm -machine pc-q35-7.1  -m 4G \
-boot menu=on \
-usb -device usb-kbd -device usb-tablet \
-netdev user,id=net0,hostfwd=tcp::13389-:3389 \
-device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
-device usb-ehci,id=ehci \
-device nec-usb-xhci,id=xhci \
-global nec-usb-xhci.msi=off \
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
-smbios type=2  \
-device ich9-intel-hda -device hda-duplex \
-device ich9-ahci,id=sata \
-smp 8,sockets=1,cores=4 \
-cpu host,kvm=on,vendor=GenuineIntel,+kvm_pv_unhalt,+kvm_pv_eoi,+hypervisor,+invtsc \
-bios /usr/share/edk2-ovmf/x64/OVMF.fd \
-drive index=2,media=disk,format=raw,if=virtio,file=/mnt/ext4/win10-q35-efi.img \
-drive index=3,media=cdrom,file=/mnt/hdd/iso/virtio-win-0.1.225.iso \
-drive index=5,media=cdrom,file=/mnt/ext4/Win10LTSC2021x64.ISO \
-vga vmware \
-vnc  :2

vnc链接上 宿主IP:5902 后,开机按esc 从 cd启动,正常安装window10. 过程略

win10 打开远程桌面后 关机,再创建一个 临时磁盘文件 格式化为exfat 方便 win10和macos 交换文件

qemu-img create -f qcow2  -o size=10G /mnt/ext4/temp.qcow2

最后启动 干净的macos+win

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
screen -S mac

qemu-system-x86_64 -enable-kvm -machine pc-q35-7.1  -m 4G \
-boot menu=on \
-usb -device usb-kbd -device usb-tablet \
-netdev user,id=net0,hostfwd=tcp::13389-:3389,hostfwd=tcp::15900-:5900,hostfwd=udp::15900-:5900,hostfwd=tcp::13283-:3283,hostfwd=udp::13283-:3283,hostfwd=tcp::1222-:22 \
-device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
-device usb-ehci,id=ehci \
-device nec-usb-xhci,id=xhci \
-global nec-usb-xhci.msi=off \
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
-smbios type=2  \
-device ich9-intel-hda -device hda-duplex \
-device ich9-ahci,id=sata \
-smp 8,sockets=1,cores=4 \
-cpu host,kvm=on,vendor=GenuineIntel,+kvm_pv_unhalt,+kvm_pv_eoi,+hypervisor,+invtsc \
-bios /usr/share/edk2-ovmf/x64/OVMF.fd \
-drive id=OpenCoreBoot,if=none,snapshot=on,format=raw,file="/mnt/ext4/OpenCore-V19.img" \
-device ide-hd,bus=sata.2,drive=OpenCoreBoot \
-drive index=1,media=disk,format=raw,if=virtio,file=/mnt/ext4/macos-13.img \
-drive index=2,media=disk,format=raw,if=virtio,file=/mnt/ext4/win10-q35-efi.img \
-drive index=3,media=disk,format=qcow2,if=virtio,file=/mnt/ext4/temp.qcow2 \
-vga vmware \
-vnc  :1

# kvm 进阶和相关小问题处理

查看这里 https://dev.leiyanhui.com/kvm/all_list/

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计