macOS-Simple-KVM icon indicating copy to clipboard operation
macOS-Simple-KVM copied to clipboard

iPhone passthrough

Open Vankata03 opened this issue 4 years ago • 37 comments

Can someone explain, how can I get my iPhone passthrough to the qemu vm? Is it possible at all? Maybe a step by step guide?

Vankata03 avatar May 13 '20 20:05 Vankata03

I have been trying to do the same, with android is super easy, but with ios there is a problem at least in my current setup, I'm using ubuntu 18.10 and the problem I'm facing is that the camera and documents get mounted on my host machine and I can't unmount them to redirect the USB, I think is more of a problem of my host, not a problem of the guest mac vm

egarim avatar May 14 '20 15:05 egarim

I struggled with udev conf for a while, trying to bypass something that looks to be an ios usb mux, and gave up :( The solution I found is to dedicated an USB controller to the VM; I followed some blogs, can't find them anymore, but I've dumped my notes here hope it can help!

note: you must hace a proc that allows io_mmu

laurentbh avatar May 14 '20 18:05 laurentbh

I struggled with udev conf for a while, trying to bypass something that looks to be an ios usb mux, and gave up :(

The solution I found is to dedicated an USB controller to the VM; I followed some blogs, can't find them anymore, but I've dumped my notes here

hope it can help!

note: you must hace a proc that allows io_mmu

So I managed to do it, but macOS does not recognize anything? They show up in the usb section in system information, but not in the finder, mouse does not work, too.

Vankata03 avatar May 15 '20 12:05 Vankata03

make sure you don't dedicated a controller used by your host and qEMU

laurentbh avatar May 15 '20 22:05 laurentbh

make sure you don't dedicated a controller used by your host and qEMU

I detach it from the host and then attach it to QEMU.

Vankata03 avatar May 17 '20 21:05 Vankata03

I'd be interested to know if someone manages too.

Julioevm avatar May 20 '20 13:05 Julioevm

The only way I've managed to get this working was adding a PCI-E USB card to my pc and passthrough it to the VM. I've been using this to develop apps for iOS without problems for about 2 years now. Obviosly, that requires a desktop instead a laptop. image

Yarkhan avatar May 21 '20 13:05 Yarkhan

Well well after a lot of tinkering I figured out a way to mount USB devices in QEMU (not virt(shit) manager). Its not just for 1 time use only. You can disconnect it, replug it and still access it. I tested it with 2 different USB drives.

As you can see in the screenshots, the USB drives show up. Still can’t get iPhone mounted though but at least USB drives mount easily now.

image

image

peterandrewd avatar Jun 16 '20 20:06 peterandrewd

Well well after a lot of tinkering I figured out a way to mount USB devices in QEMU (not virt(shit) manager). Its not just for 1 time use only. You can disconnect it, replug it and still access it. I tested it with 2 different USB drives.

As you can see in the screenshots, the USB drives show up. Still can’t get iPhone mounted though but at least USB drives mount easily now.

image

image

Could you please document how you achieved it? :)

reinismu avatar Aug 17 '20 03:08 reinismu

The only way I've managed to get this working was adding a PCI-E USB card to my pc and passthrough it to the VM. I've been using this to develop apps for iOS without problems for about 2 years now. Obviosly, that requires a desktop instead a laptop. image

Just a quick update. I've just recently migrated to AMD (ryzen 5 3600 on an asrock b450m steel legend mobo). This mobo has a usb IOMMU group that is not shared with anything else. That makes possible to passthrough it, and it makes 4 of the usb on the motherboard available to the VM. In short, no need of usb pci-e cards :)

Yarkhan avatar Aug 17 '20 14:08 Yarkhan

Well well after a lot of tinkering I figured out a way to mount USB devices in QEMU (not virt(shit) manager). Its not just for 1 time use only. You can disconnect it, replug it and still access it. I tested it with 2 different USB drives.

As you can see in the screenshots, the USB drives show up. Still can’t get iPhone mounted though but at least USB drives mount easily now.

How did you do this?

hockeymikey avatar Sep 27 '20 05:09 hockeymikey

The only way I've managed to get this working was adding a PCI-E USB card to my pc and passthrough it to the VM. I've been using this to develop apps for iOS without problems for about 2 years now. Obviosly, that requires a desktop instead a laptop. image

Just a quick update. I've just recently migrated to AMD (ryzen 5 3600 on an asrock b450m steel legend mobo). This mobo has a usb IOMMU group that is not shared with anything else. That makes possible to passthrough it, and it makes 4 of the usb on the motherboard available to the VM. In short, no need of usb pci-e cards :)

same here, lucky us

themotu avatar Sep 28 '20 07:09 themotu

how did you passtrhoguh the entire controller?

leandrobattochio avatar Oct 10 '20 21:10 leandrobattochio

@SheenBR You would need to do a PCI passthough, you would need to make it so that the IOMMU group for the controller were not taken by the host deivce. Depending on which distro you are running and what kind of motherboard you have this will be more or less difficult if your mother board has poor iommu group mapping you would need to recompile your kernel with the ACS patch. Here is some information. They explain how to do it with a graphics card but it works the same for any PCI device. https://forum.level1techs.com/t/vfio-in-2019-fedora-workstation-general-guide-though-branch-draft/145106 https://copr.fedorainfracloud.org/coprs/jlay/kernel-acspatch/

Malikiah avatar Feb 27 '21 21:02 Malikiah

I edited the basic.sh file and appended this line: -device usb-host,vendorid=0x<your-iphone-vendor-id>,productid=0x<your-iphone-product-id>,guest-reset=false \. Here, the guest-reset=false is the argument that worked for me. I hope it works for others as well. Good luck. Reference: stackoverflow answer

fahimfarhan avatar Aug 21 '21 05:08 fahimfarhan

@fahimfarhan And that works fine? The iPhone works in xcode?

hockeymikey avatar Aug 21 '21 22:08 hockeymikey

@fahimfarhan And that works fine? The iPhone works in xcode?

Yes. After connecting my iPhone, I opened a tutorial, made a sample app, and installed it on my iPhone. Here is a photo of my app.

USER_SCOPED_TEMP_DATA_MSGR_PHOTO_FOR_UPLOAD_1629525018190_6834723301900083908.jpeg

fahimfarhan avatar Aug 22 '21 02:08 fahimfarhan

@fahimfarhan And that works fine? The iPhone works in xcode?

Yes. After connecting my iPhone, I opened a tutorial, made a sample app, and installed it on my iPhone. Here is a photo of my app.)

It just freezes and crashes my vm. What version are you on?

hockeymikey avatar Aug 23 '21 00:08 hockeymikey

@fahimfarhan And that works fine? The iPhone works in xcode?

Yes. After connecting my iPhone, I opened a tutorial, made a sample app, and installed it on my iPhone. Here is a photo of my app.)

It just freezes and crashes my vm. What version are you on?

@hockeymikey I am using kvm version 4.2.1 (Debian 1:4.2-3ubuntu6.17), MacOS Catalina, and Xcode version 12.4. My host OS is linux mint 20.2.

(base) soumic@Zephyrus-G14:~/Desktop$ kvm --version
QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.17)
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers
(base) soumic@Zephyrus-G14:~/Desktop$ screenfetch
                                       soumic@Zephyrus-G14
 MMMMMMMMMMMMMMMMMMMMMMMMMmds+.        OS: Linuxmint 20.2 uma
 MMm----::-://////////////oymNMd+`     Kernel: x86_64 Linux 5.13.0-1009-oem
 MMd      /++                -sNMd:    Uptime: 47m
 MMNso/`  dMM    `.::-. .-::.` .hMN:   Packages: 2841
 ddddMMh  dMM   :hNMNMNhNMNMNh: `NMm   Shell: bash 5.0.17
     NMm  dMM  .NMN/-+MMM+-/NMN` dMM   Resolution: 1920x1080
     NMm  dMM  -MMm  `MMM   dMM. dMM   DE: Cinnamon 5.0.5
     NMm  dMM  -MMm  `MMM   dMM. dMM   WM: Muffin
     NMm  dMM  .mmd  `mmm   yMM. dMM   WM Theme: Mint-Y (Mint-Y)
     NMm  dMM`  ..`   ...   ydm. dMM   GTK Theme: Mint-Y [GTK2/3]
     hMM- +MMd/-------...-:sdds  dMM   Icon Theme: Paper
     -NMm- :hNMNNNmdddddddddy/`  dMM   Font: Ubuntu 10
      -dMNs-``-::::-------.``    dMM   Disk: 208G / 529G (42%)
       `/dMNmy+/:-------------:/yMMM   CPU: AMD Ryzen 9 4900HS with Radeon Graphics @ 16x 3GHz
          ./ydNMMMMMMMMMMMMMMMMMMMMM   GPU: NVIDIA GeForce RTX 2060 with Max-Q Design
             \.MMMMMMMMMMMMMMMMMMM     RAM: 9776MiB / 31525MiB
                                      
(base) soumic@Zephyrus-G14:~/Desktop$ 

fahimfarhan avatar Aug 23 '21 05:08 fahimfarhan

@hockeymikey I am using kvm version 4.2.1 (Debian 1:4.2-3ubuntu6.17), MacOS Catalina, and Xcode version 12.4. My host OS is linux mint 20.2.

Probably a G14 then right? I'm using an Omen 15 so you're not passing through any controllers then, just the device. Can I see your startup script if you don't mind? Just wanna double check and rule everything out.

hockeymikey avatar Aug 23 '21 15:08 hockeymikey

@hockeymikey Yes, a G14. Sure! This is my basic.sh script:

#!/bin/bash

OSK="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VMDIR=$PWD
OVMF=$VMDIR/firmware
#export QEMU_AUDIO_DRV=pa
#QEMU_AUDIO_DRV=pa

qemu-system-x86_64 \
    -enable-kvm \
    -m 20G \
    -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 \
    -netdev user,id=net0 \
    -device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
    -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=catalina.qcow2 \
    -device ide-hd,bus=sata.4,drive=SystemDisk \
    -device usb-host,vendorid=0x05ac,productid=0x12a8,guest-reset=false \

Here, the last line (-device usb-host,vendorid=0x05ac,productid=0x12a8,guest-reset=false \) is for the iPhone 8.

fahimfarhan avatar Aug 26 '21 06:08 fahimfarhan

@fahimfarhan Strange... I have a similar basic.sh but no luck on my end

hockeymikey avatar Aug 30 '21 14:08 hockeymikey

I still can't get this to work. My basic.sh is identical to @fahimfarhan 's and I've tried different ones such as using an ehci host defined. Tried every port on my laptop too. So what happens is that whenever I plug it into my laptop while the vm is running, it freezes up and the macos system crashes and reboots. If I start the vm with the device plugged in, it doesn't see it either but boots all the way up. The iphone reboots when it gets unplugged from the laptop.

hockeymikey avatar Nov 19 '21 22:11 hockeymikey

I finally got passthrough working!!!! I used https://github.com/sickcodes/Docker-OSX#usbfluxd-iphone-usb---network-style-passthrough-osx-kvm-docker-osx to do it, works like a charm. Only issue I ran into is that as an Arch user I was compiling from git from the AUR for usbfluxd, usbmuxd, etc so on the MacOS vm I had to do the same compiling from git everything. It was alittle tricky getting the paths right and what not, but works like a charm now. Guest needs to be reachable by the host, I use virt-manager's NAT (which I could never get working in basic.sh), but can just have it bridged directly to whatever network you are on too.

hockeymikey avatar Nov 20 '21 17:11 hockeymikey

@hockeymikey Yes, a G14. Sure! This is my basic.sh script:

#!/bin/bash

OSK="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VMDIR=$PWD
OVMF=$VMDIR/firmware
#export QEMU_AUDIO_DRV=pa
#QEMU_AUDIO_DRV=pa

qemu-system-x86_64 \
    -enable-kvm \
    -m 20G \
    -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 \
    -netdev user,id=net0 \
    -device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
    -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=catalina.qcow2 \
    -device ide-hd,bus=sata.4,drive=SystemDisk \
    -device usb-host,vendorid=0x05ac,productid=0x12a8,guest-reset=false \

Here, the last line (-device usb-host,vendorid=0x05ac,productid=0x12a8,guest-reset=false \) is for the iPhone 8.

After messing with my vfio and kernel still got nothing done, I saw this thread. This works for me just fine! Thanks!

413ph avatar Jan 23 '22 19:01 413ph

-device usb-host,vendorid=0x05ac,productid=0x12a8,guest-reset=false doesn't work for me either, verified with lsusb that those are correct. I wonder if usbmuxd could cause issues?

Midar avatar Apr 25 '22 11:04 Midar

I finally got passthrough working!!!! I used https://github.com/sickcodes/Docker-OSX#usbfluxd-iphone-usb---network-style-passthrough-osx-kvm-docker-osx to do it, works like a charm. Only issue I ran into is that as an Arch user I was compiling from git from the AUR for usbfluxd, usbmuxd, etc so on the MacOS vm I had to do the same compiling from git everything. It was alittle tricky getting the paths right and what not, but works like a charm now. Guest needs to be reachable by the host, I use virt-manager's NAT (which I could never get working in basic.sh), but can just have it bridged directly to whatever network you are on too.

Wait so you just used the AUR version of usbfluxd? I've been trying that but my iPhone won't show up in iTunes or Finder. I even tried compiling usbfluxd and I keep getting configure: error: The file /libplist-2.0.a passed to --with-static-libplist does not exist. Any ideas?

simmons2714 avatar May 04 '22 04:05 simmons2714

@simmons2714 I think you can just pass through the usb port to the VM in Virt-Manager

notAperson535 avatar May 04 '22 11:05 notAperson535

@notAperson535 I've tried that and with iphones sometimes that works and sometimes it doesn't.

simmons2714 avatar May 04 '22 19:05 simmons2714

@simmons2714 No idea. Try compiling them all. I think I use git versions for all of them from AUR.

hockeymikey avatar May 04 '22 19:05 hockeymikey