OSX-KVM

KVM

  • 物理机系统openSUSE Tumbleweed
  • 装了个OSX准备试试看编译效果

项目地址

安装依赖

1
2

sudo zypper in libvirt libvirt-daemon libvirt-client qemu uml-utilities qemu-audio-pa

下面这些会自动安装上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
libvirglrenderer1 qemu qemu-audio-spice qemu-block-curl qemu-block-rbd qemu-chardev-spice
qemu-hw-display-qxl qemu-hw-display-virtio-gpu qemu-hw-display-virtio-gpu-pci qemu-hw-display-virtio-vga
qemu-hw-usb-redirect qemu-hw-usb-smartcard qemu-ipxe qemu-ksm qemu-lang qemu-microvm qemu-ovmf-x86_64
qemu-seabios qemu-sgabios qemu-tools qemu-ui-curses qemu-ui-gtk qemu-ui-opengl qemu-ui-spice-app
qemu-ui-spice-core qemu-vgabios qemu-x86 system-user-qemu
qemu-block-curl qemu-hw-display-qxl qemu-hw-display-virtio-gpu qemu-hw-display-virtio-gpu-pci
qemu-hw-display-virtio-vga qemu-hw-usb-redirect qemu-hw-usb-smartcard qemu-ksm qemu-microvm qemu-ovmf-x86_64
qemu-tools qemu-ui-curses qemu-ui-gtk qemu-ui-spice-app qemu-x86
qemu-arm qemu-block-dmg qemu-block-gluster qemu-block-iscsi qemu-block-nfs qemu-block-ssh qemu-chardev-baum
qemu-extra qemu-ppc qemu-s390x qemu-skiboot qemu-vhost-user-gpu

gnutls libgnutls-dane0 libopts25 libprotobuf-c1 libunbound8 libvirt-client libvirt-libs unbound-anchor

libiscsi9 liblvm2cmd2_03 libnetcontrol0 libopeniscsiusr0_2_0 libtpms0 libvirt-daemon-driver-interface
libvirt-daemon-driver-network libvirt-daemon-driver-nodedev libvirt-daemon-driver-nwfilter
libvirt-daemon-driver-qemu libvirt-daemon-driver-secret libvirt-daemon-driver-storage
libvirt-daemon-driver-storage-core libvirt-daemon-driver-storage-disk libvirt-daemon-driver-storage-iscsi
libvirt-daemon-driver-storage-iscsi-direct libvirt-daemon-driver-storage-logical
libvirt-daemon-driver-storage-mpath libvirt-daemon-driver-storage-rbd libvirt-daemon-driver-storage-scsi
libvirt-daemon-qemu lvm2 lzop mdevctl nfs-kernel-server open-iscsi radvd swtpm systemd-container
system-user-tss trousers

libvirt libvirt-daemon-config-network libvirt-daemon-config-nwfilter libvirt-daemon-driver-libxl
libvirt-daemon-driver-lxc

kvm配置文件

第一条暂时 第二条长久有效

1
2
echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs
sudo cp kvm.conf /etc/modprobe.d/kvm.conf

克隆镜像

1
2
3
cd ~
git clone --depth 1 https://github.com/kholia/OSX-KVM.git
cd OSX-KVM

获取镜像

1
2
3
./fetch-macOS-v2.py
qemu-img convert BaseSystem.dmg -O raw BaseSystem.img
qemu-img create -f qcow2 mac_hdd_ng.img 128G

生成配置文件

1
2
3
sed "s/CHANGEME/$USER/g" macOS-libvirt-Catalina.xml > macOS.xml
virt-xml-validate macOS.xml
virsh --connect qemu:///system define /home/xuan/OSX-KVM/macOS.xml

配置链接

1
2
3
sudo virsh net-list
sudo virsh net-start default
sudo virsh net-autostart default
1
2
3
4
sudo ip tuntap add dev tap0 mode tap
sudo ip link set tap0 up promisc on
sudo ip link set dev virbr0 up
sudo ip link set dev tap0 master virbr0

设置开机启动

1
2
3
systemctl start libvirtd.service
systemctl status libvirtd.service
systemctl enable libvirtd.service

系统安装

安装


识别USB设备

OpenCore-Boot.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash

# Special thanks to:
# https://github.com/Leoyzen/KVM-Opencore
# https://github.com/thenickdude/KVM-Opencore/
# https://github.com/qemu/qemu/blob/master/docs/usb2.txt
#
# qemu-img create -f qcow2 mac_hdd_ng.img 128G
#
# echo 1 > /sys/module/kvm/parameters/ignore_msrs (this is required)

############################################################################
# NOTE: Tweak the "MY_OPTIONS" line in case you are having booting problems!
############################################################################

MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"

# This script works for Big Sur, Catalina, Mojave, and High Sierra. Tested with
# macOS 10.15.6, macOS 10.14.6, and macOS 10.13.6

ALLOCATED_RAM="4096" # MiB
CPU_SOCKETS="1"
CPU_CORES="2"
CPU_THREADS="4"

REPO_PATH="."
OVMF_DIR="."

# This causes high cpu usage on the *host* side
# qemu-system-x86_64 -enable-kvm -m 3072 -cpu Penryn,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,hypervisor=off,vmx=on,kvm=off,$MY_OPTIONS\

# shellcheck disable=SC2054
args=(
-enable-kvm -m "$ALLOCATED_RAM" -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,"$MY_OPTIONS"
-machine q35
-usb -device usb-kbd -device usb-tablet
-smp "$CPU_THREADS",cores="$CPU_CORES",sockets="$CPU_SOCKETS"
-device usb-ehci,id=ehci
-usb -device usb-host,productid=0x1234,vendorid=0xabcd # 这里用dmesg或者lsusb看vid pid
# -device usb-kbd,bus=ehci.0
# -device usb-mouse,bus=ehci.0
# -device nec-usb-xhci,id=xhci
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
-drive if=pflash,format=raw,readonly=on,file="$REPO_PATH/$OVMF_DIR/OVMF_CODE.fd"
-drive if=pflash,format=raw,file="$REPO_PATH/$OVMF_DIR/OVMF_VARS-1024x768.fd"
-smbios type=2
-device ich9-intel-hda -device hda-duplex
-device ich9-ahci,id=sata
-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file="$REPO_PATH/OpenCore/OpenCore.qcow2"
-device ide-hd,bus=sata.2,drive=OpenCoreBoot
-device ide-hd,bus=sata.3,drive=InstallMedia
-drive id=InstallMedia,if=none,file="$REPO_PATH/BaseSystem.img",format=raw
-drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2
-device ide-hd,bus=sata.4,drive=MacHDD
# -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27
-netdev user,id=net0 -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27
-monitor stdio
-device VGA,vgamem_mb=512
)

qemu-system-x86_64 "${args[@]}"

111.png

推荐文章