diff --git a/Makefile b/Makefile index 9b2438f..d085d9e 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ ifeq (, $(shell which sudo)) SUDO= endif -i in ins inst install: +i in ins inst install: _install_macos_kvm_utils $(SUDO) cp -af utils/* $(_bin)/. @$(SUDO) rm -f $(_bin)/install-sbopkg.sh /usr/local/bin/port-available.sh $(SUDO) cp -af kiss-vm $(_bin)/vm @@ -36,5 +36,8 @@ p pu pull u up update: git pull --rebase || : @echo +_install_macos_kvm_utils: + $(SUDO) cp -r macOS-kvm-utils /usr/share/. + _isroot: @test `id -u` = 0 || { echo "[Warn] need root permission" >&2; exit 1; } diff --git a/macOS-kvm-utils/README.txt b/macOS-kvm-utils/README.txt index 38182cf..54f5d8a 100644 --- a/macOS-kvm-utils/README.txt +++ b/macOS-kvm-utils/README.txt @@ -1,4 +1,9 @@ +# ------------------------------------------------------------------------------ # All files in this dir come from https://github.com/kholia/OSX-KVM +# I just tried converting the xml template macOS-libvirt-Catalina.xml +# into command line arguments for virt-install/kiss-vm, thus simplifying the +# steps of making macOS-in-KVM +#------------------------------------------------------------------------------- ## here, we assuming the macOS-kvm-utils directory has been installed to /usr/share eval img_download_dir=~/myimages/download @@ -14,19 +19,30 @@ mkdir -p $img_download_dir macos_image=BaseSystem-mac-$macos_release -#if [[ ! -f $img_download_dir/${macos_image}.img ]]; then +if [[ ! -f $img_download_dir/${macos_image}.img ]]; then /usr/share/macOS-kvm-utils/fetch-macOS-v2.py -o $img_download_dir -n ${macos_image} -s $macos_release command -v dmg2img || { echo "{ERROR} command dmg2img is required."; exit 1; } (cd $img_download_dir; dmg2img -i ${macos_image}.dmg) -#fi +fi macos_image_path=$img_download_dir/${macos_image}.img +#qemu cpu options +cpu_vendor=$(awk '/vendor_id/{print $NF; exit}' /proc/cpuinfo) +case $cpu_vendor in +*Intel) + #verified on host(thindpad-T460P: {CPU: Intel i7-6700HQ, OS: fedora-37}) with all macOS version + qemucpu_opt="-cpu host,vendor=GenuineIntel,+hypervisor,+invtsc,kvm=on,+fma,+avx,+avx2,+aes,+ssse3,+sse4_2,+popcnt,+sse4a,+bmi1,+bmi2";; +*AMD) + #verified on host(deskmini-x300: {CPU: AMD R7-5700G, OS: fedora-36}) with catalina, high-sierra + #yes, we need emulate Intel CPU on AMD cpu. here we use model: Haswell[2013](or Broadwell[2015]) for better compatible + qemucpu_opt="-cpu Haswell,vendor=GenuineIntel,+hypervisor,+invtsc,kvm=on,+fma,+avx,+avx2,+aes,+ssse3,+sse4_2,+popcnt,+sse4a,+bmi1,+bmi2";; +esac + #note1: --virt-install-opts=--controller=type=usb,model=none is for avoid controller conflict #note2: address.bus=0x00,address.slot=0x0a, because if bus!=0x00 the nic will not be recognized #note3: qemu-options come from https://github.com/kholia/OSX-KVM/blob/master/macOS-libvirt-Catalina.xml -vm create macOS \ - -n $macos_vmname \ +vm create macOS -n $macos_vmname \ --machine q35 \ --osv $(osinfo-query os|awk '/macos/{osv=$1} END{print osv}') \ --boot loader=/usr/share/macOS-kvm-utils/OVMF_CODE.fd,loader.readonly=yes,loader.type=pflash,nvram=/usr/share/macOS-kvm-utils/OVMF_VARS-1024x768.fd \ @@ -34,10 +50,16 @@ vm create macOS \ --disk $macos_image_path \ --qemu-opts "-device isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \ --qemu-opts "-smbios type=2 -usb -device usb-tablet -device usb-kbd" \ - --qemu-opts "-cpu host,vendor=GenuineIntel,+hypervisor,+invtsc,kvm=on,+fma,+avx,+avx2,+aes,+ssse3,+sse4_2,+popcnt,+sse4a,+bmi1,+bmi2" \ + --qemu-opts "${qemucpu_opt}" \ --net=default,model=vmxnet3,address.type=pci,address.bus=0x00,address.slot=0x0a \ --virt-install-opts=--controller=type=usb,model=none \ --msize 8192 \ --dsize 128 \ --diskbus sata \ --noauto --force --vncwait="...,key:right key:enter" + #--hostdev if want passthru host device into VM, add this option + #you could get iommu-group info by using command: iommu-groups.sh + +#note4: see: https://www.quora.com/What-should-I-do-if-my-MacBook-is-stuck-on-Less-than-a-minute-remaining-updating-Big-Sur +#note4: if get stuck on "Less than a minute remaining", just reboot. and most of the time, the problem will be solved. +#note4: vm reboot $vmname; vm viewer $vmname