foxlet / macOS-Simple-KVM

Tools to set up a quick macOS VM in QEMU, accelerated by KVM.
13.61k stars 1.14k forks source link

freezes after a short time when using bridged networking #265

Open moddie666 opened 4 years ago

moddie666 commented 4 years ago

hi,

:~/macOS-Simple-KVM$ qemu-system-x86_64 --version
QEMU emulator version 5.0.0 (Debian 1:5.0-5)

on debian testing 5.7.0-1-amd64 modified basic.sh

#!/bin/bash
#

OSK="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VMDIR=$PWD
OVMF=$VMDIR/firmware
export QEMU_AUDIO_DRV=pa
QEMU_AUDIO_DRV=pa
br=mcbridge
tp=mctap
nw=mcnet
cleanup(){
          nmcli connection del $br $tp $nw
}
trap cleanup EXIT
#VGA PASSTHROUGH
#VGA="-vga none -device pcie-root-port,bus=pcie.0,multifunction=on,port=1,chassis=1,id=port.1 -device vfio-pci,host=2d:00.0,bus=port.1,multifunction=on -device vfio-pci,host=2d:00.1,bus=port.1"
VGA="-vga qxl"

#basic NETWORKING (no ICMP?)
#NET="-netdev user,id=net0"

#BRIDGED NETWORKING
nmcli connection add type bridge ifname br1 con-name $br
nmcli connection add type bridge-slave ifname enp39s0 con-name $nw master br1
nmcli connection add type tun ifname tap0 con-name $tp mode tap owner $(id -u)
nmcli connection mod $tp connection.slave-type bridge connection.master br1
nmcli connection show
NET="-netdev tap,id=net0,ifname=tap0,script=no,downscript=no"

NDV="-device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27"
#NDV="-device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27"
qemu-system-x86_64 \
    -enable-kvm \
    -m 8G \
    -machine q35,accel=kvm \
    -smp 8,cores=4 \
    -cpu Penryn,vendor=GenuineIntel,kvm=on,+sse3,+sse4.2,+aes,+xsave,+avx,+xsaveopt,+xsavec,+xgetbv1,+avx2,+bmi2,+smep,+bmi1,+fma,+movbe,+invtsc \
    -device isa-applesmc,osk="$OSK" \
    -smbios type=2 \
    -drive if=pflash,format=raw,readonly,file="$OVMF/OVMF_CODE.fd" \
    -drive if=pflash,format=raw,file="$OVMF/OVMF_VARS-1024x768.fd" \
    $VGA \
    -device ich9-intel-hda -device hda-output \
    -usb -device usb-kbd -device usb-mouse \
    $NET \
    $NDV \
    -device ich9-ahci,id=sata \
    -drive id=ESP,if=none,format=qcow2,file=ESP.qcow2 \
    -device ide-hd,bus=sata.2,drive=ESP \
    -drive id=InstallMedia,format=raw,if=none,file=BaseSystem.img \
    -device ide-hd,bus=sata.3,drive=InstallMedia \
    -drive id=SystemDisk,if=none,file=MyDisk.qcow2 \
    -device ide-hd,bus=sata.4,drive=SystemDisk \

vmxnet or not, makes no difference...

also, is it normal for time machine to not work, with "normal" networking? i can select a volume (once) never even prompts for user/pass (via netatalk/afp) then errs out with some generic message netatalk sees no connection attempt

CristianPi commented 4 years ago

i solve with this:

#!/bin/bash

OSK="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VMDIR=$PWD
OVMF=$VMDIR/firmware
#export QEMU_AUDIO_DRV=pa
#QEMU_AUDIO_DRV=pa
br=mcbridge
tp=mctap
nw=mcnet
cleanup(){
          nmcli connection del $br $tp $nw
          killall dhclient
}
trap cleanup EXIT

#BRIDGED NETWORKING
nmcli connection add type bridge ifname br1 con-name $br
nmcli connection add type bridge-slave ifname eno1 con-name $nw master br1
nmcli connection add type tun ifname tap0 con-name $tp mode tap owner $(id -u)
nmcli connection mod $tp connection.slave-type bridge connection.master br1
nmcli con up $nw
nmcli con up $br
nmcli con up $tp
dhclient br1
nmcli connection show
NET="-netdev tap,id=net0,ifname=tap0,script=no,downscript=no"
#NET="-netdev user,id=mynet0 -device rtl8139,netdev=mynet0"
#NET="-netdev tap,id=net0,ifname=tap0,netdev=net0"

NDV="-device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27"
#NDV="-device rtl8139,netdev=net0,id=net0,mac=52:54:00:c9:18:27"
#NDV= ""

qemu-system-x86_64 \
    -enable-kvm \
    -m 12G \
    -machine q35,accel=kvm \
    -smp 16,cores=8 \
    -cpu Penryn,vendor=GenuineIntel,kvm=on,+sse3,+sse4.2,+aes,+xsave,+avx,+xsaveopt,+xsavec,+xgetbv1,+avx2,+bmi2,+smep,+bmi1,+fma,+movbe,+invtsc \
    -device isa-applesmc,osk="$OSK" \
    -smbios type=2 \
    -drive if=pflash,format=raw,readonly,file="$OVMF/OVMF_CODE.fd" \
    -drive if=pflash,format=raw,file="$OVMF/OVMF_VARS-1024x768.fd" \
    -vga qxl \
    -device ich9-intel-hda -device hda-output \
    -usb -device usb-kbd -device usb-mouse \
    $NET \
    $NDV \
    -device ich9-ahci,id=sata \
    -drive id=ESP,if=none,format=qcow2,file=ESP.qcow2 \
    -device ide-hd,bus=sata.2,drive=ESP \
    -drive id=InstallMedia,format=raw,if=none,file=BaseSystem.img \
    -device ide-hd,bus=sata.3,drive=InstallMedia \
    -drive id=SystemDisk,if=none,file=MyDisk.qcow2 \
    -device ide-hd,bus=sata.4,drive=SystemDisk \

i don't use dhclient so at the script termination i kill the process so every time i boot the machine i get the same result. adjust to your use case

moddie666 commented 4 years ago

I can now confirm, this script solves the hanging problem :) also time machine and other network shares seem to work aswell.

@CristianPi would you mind elaborating on why exactly it is, that this solves the freezing problem?

is it just, that the connections weren't "UP"?

greetings /moddie

CristianPi commented 4 years ago

@moddie666

I really don't know if the crashes are caused by the qemu/kvm emulation or, more probably, by mac os (clover?), the underlying hardware (i'm using ryzen 3900x).

possible ways to explore:

replicating the problem on a real machine (legit machine) should give some confidence that this is a real bug on the drivers / kernel.

replicating the problem on a non virtualized machine only should point to clover and the underling "hacks".

moddie666 commented 4 years ago

It is possibly clover/kvm related, I think. The reason being, that the boot menu (I think thats clover) hangs aswell if I just leave it on that first screen.

Interestingly, I am using the same cpu... Version: AMD Ryzen 9 3900X 12-Core Processor
Base Board Information Manufacturer: Micro-Star International Co., Ltd. Product Name: X570-A PRO (MS-7C37)

Unfortunately I've found no log entries concerning kvm/qemu on my machine... Also I'm a complete MacOS/Hackintosh noob with no idea on how to investigate anything clover or MacOS related.

Lastly: If that part

nmcli con up $nw
nmcli con up $br
nmcli con up $tp

is necessary for the connections to be up/working it seems more like an oversight in the networking tutorial on here. And maybe a bug with KVM or clover hanging when trying to use an improperly attached bridge...

thanks for your insights!