在macos使用qemu安裝windows

安裝Qemu

brew install qemu

建立硬碟

qemu-img create -f raw ~/qemu/disk.img 20G
qemu-img info ~/qemu/disk.img

修正Qemu錯誤

原生安裝好的qemu執行虛擬機時,會出現qemu-system-x86_64: Error: HV_ERROR的錯誤,
修正方式如下:

# 參考 https://stackoverflow.com/a/64993771/4802467
cat << EOF > app.entitlements
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.hypervisor</key>
    <true/>
</dict>
</plist>
EOF
md5 $(which qemu-system-x86_64)
codesign -s - --entitlements app.entitlements --force $(which qemu-system-x86_64)
md5 $(which qemu-system-x86_64)
rm -f app.entitlements

開啟虛擬機

qemu-system-x86_64 \
  -m 4G \
  -vga virtio \
  -display default,show-cursor=on \
  -usb \
  -device usb-tablet \
  -machine type=q35,accel=hvf \
  -smp 2 \
  -drive file=/Users/slanla/qemu/disk.img,index=0,format=raw,if=virtio \
  -drive file=windows.iso,index=1,media=cdrom \
  -drive file=virtio-win-drivers-20120712-1.iso,index=2,media=cdrom \
  -cpu Nehalem

資源下載

virtio-win-drivers-20120712-1.iso