Advertisement
Guest User

Untitled

a guest
May 14th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.07 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. check_sudo() {
  4.     if [ "$EUID" -ne 0 ]; then
  5.         echo "This script must be executed as root. Please run with sudo."
  6.         exit 1
  7.     fi
  8. }
  9.  
  10. detach_gpu() {
  11.     echo "Detaching GPU from host..."
  12.  
  13.     # Stop display manager
  14.     systemctl stop display-manager
  15.  
  16.     # Unbind VTconsoles
  17.     for F in /sys/class/vtconsole/vtcon*; do
  18.         echo 0 > "$F/bind"
  19.     done
  20.  
  21.     # Unbind EFI Framebuffer
  22.     for F in /sys/bus/platform/drivers/efi-framebuffer/efi-framebuffer.*; do
  23.         test ! -d "$F" && continue
  24.         echo "$(basename "$F")" > /sys/bus/platform/drivers/efi-framebuffer/unbind
  25.     done
  26.  
  27.     # Unload AMD kernel module
  28.     lsof | grep amdgpu | awk '{print $2}' | xargs sudo kill -9
  29.     fuser -k /dev/dri/card1
  30.     modprobe -r amdgpu
  31.  
  32.     echo "Unbinding GPU from current driver..."
  33.     echo "0000:0d:00.0" > /sys/bus/pci/devices/0000:0d:00.0/driver/unbind
  34.  
  35.     echo "Unbinding GPU audio from current driver..."
  36.     echo "0000:0d:00.1" > /sys/bus/pci/devices/0000:0d:00.1/driver/unbind
  37.  
  38.     echo "Binding GPU to vfio-pci driver..."
  39.     modprobe vendor-reset
  40.     modprobe vfio-pci
  41.     echo "1002 73ff" > /sys/bus/pci/drivers/vfio-pci/new_id
  42.  
  43.     echo "Binding GPU audio to vfio-pci driver..."
  44.     echo "1002 ab28" > /sys/bus/pci/drivers/vfio-pci/new_id
  45.  
  46.     echo "Rescanning PCI bus..."
  47.     echo 1 > /sys/bus/pci/rescan
  48. }
  49.  
  50. check_sudo
  51.  
  52. detach_gpu
  53.  
  54. echo "Starting the macOS VM..."
  55.  
  56. MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"
  57.  
  58. ALLOCATED_RAM="8192" # MiB
  59. CPU_SOCKETS="1"
  60. CPU_CORES="4"
  61. CPU_THREADS="8"
  62.  
  63. REPO_PATH="."
  64. OVMF_DIR="."
  65. GPU_ROM_FILE="./RX6600.rom"
  66.  
  67.  
  68. # shellcheck disable=SC2054
  69. args=(
  70.   -enable-kvm -m "$ALLOCATED_RAM" -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,"$MY_OPTIONS"
  71.   -machine q35
  72.   -device qemu-xhci,id=xhci
  73.   -device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0
  74.   -smp "$CPU_THREADS",cores="$CPU_CORES",sockets="$CPU_SOCKETS"
  75.   -device vfio-pci,host=0d:00.0,multifunction=on,x-vga=on,romfile="$GPU_ROM_FILE"
  76.   -device vfio-pci,host=0d:00.1
  77.   -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
  78.   -drive if=pflash,format=raw,readonly=on,file="$REPO_PATH/$OVMF_DIR/OVMF_CODE.fd"
  79.   -drive if=pflash,format=raw,file="$REPO_PATH/$OVMF_DIR/OVMF_VARS-1920x1080.fd"
  80.   -smbios type=2
  81.   -device ich9-intel-hda -device hda-duplex
  82.   -device ich9-ahci,id=sata
  83.   -drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file="$REPO_PATH/OpenCore/OpenCore.qcow2"
  84.   -device ide-hd,bus=sata.2,drive=OpenCoreBoot
  85.   -device ide-hd,bus=sata.3,drive=InstallMedia
  86.   -drive id=InstallMedia,if=none,file="$REPO_PATH/BaseSystem.img",format=raw
  87.   -drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2
  88.   -device ide-hd,bus=sata.4,drive=MacHDD
  89.   -netdev user,id=net0,hostfwd=tcp::2222-:22 -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27
  90.   -monitor telnet:127.0.0.1:55555,server,nowait
  91.   -monitor stdio
  92.   -global ICH9-LPC.acpi-pci-hotplug-with-bridge-support=off
  93. )
  94.  
  95. qemu-system-x86_64 "${args[@]}"
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement