Skip to content

Commit

Permalink
Makefile: install/copy new macOS-kvm-utils dir to /usr/share/
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhong Yin <[email protected]>
  • Loading branch information
tcler committed Jan 16, 2023
1 parent 8cb0f6b commit 865b6d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; }
32 changes: 27 additions & 5 deletions macOS-kvm-utils/README.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,30 +19,47 @@ 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 \
-F /usr/share/macOS-kvm-utils/OpenCore.qcow2 \
--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 <pci_addr> 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

0 comments on commit 865b6d1

Please sign in to comment.