quickemu-project / quickemu

Quickly create and run optimised Windows, macOS and Linux virtual machines
MIT License
9.82k stars 433 forks source link

docs: document how to connect an iPhone to a macOS virtual machine #468

Open nicolasmol opened 2 years ago

nicolasmol commented 2 years ago

Hi everyone. French here, sorry I'll do my best with English

Manajro (latest) + Gnome, on HP laptop, 3 USB port on the same bus.

It's quite strange because three days before, I installed Quickemu, Mac OS , and I was amazingly surprised that at first run, plugging my Iphone 8 made it instantly recognizes into the VM.

I mean..the goal you know, Xcode, flutter, etc...Why the hell would we need MacOS VM for anything else ? But after hours of investigations I found no solution why it disappeared.

After having struggled with the display mode (*BTW: with default mode, the area into which the mouse can mouve is smaller that the displayed screen) for which I made so many operations until I undertook that the best is to use "gtk" or "spice", it became impossible to get this f*** iphone back into the VM.

Three methods :

No config, gtk display Terminal repeatedly says ...

usb_desc_get_descriptor: 2 unknown type 33 (len 10) usb_desc_get_descriptor: 1 unknown type 33 (len 10

Host redirection, gtk display with usb_devices=("05ac:12a8")

Terminal repeatedly says ...

qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]

I see that I have on my hp popup notifications, like Manjaro is trying the re-hotplug the device. Impossible to find any simple solution to disable the service which as a kind of "fenix" mode...not sure which one, but it sounds to be usbmuxd (https://github.com/libimobiledevice/usbmuxd/issues/110)

spice image

Investigated docs without any success:

https://github.com/arindas/mac-on-linux-with-qemu/issues/25 https://null-src.com/posts/qemu-vfio-pci/post.php https://askubuntu.com/questions/1269061/qemu-kvm-with-spice-fails-to-maintain-access-to-apple-device-usb-redirection https://github.com/Silfalion/Iphone_docker_osx_passthrough

Also failed:

And may others...

==> Note also that quitting Spice window doesn't remove the process macos-catalina that has to me manually killed.

[EDIT, 1 day after]

I manage to understand that "my"rules where not in etc/udev/rules.d but in usr/lib/udev/rules.d (who can like linux for this recurrent problem...we never know where are the used files...anyway) So after commenting all rules in 39-usbmux.rules, I face a new dialog box (in spice mode)

error resetting device: LIBUSB_ERROR_NOT_FOUND

image

Conclusion

At the end some ppl says that it's impossible. Did I dream when I saw the iphone appearing first time ?

Thanks for your help

[FINAL EDIT - SOLUTION FOR DESPERATE PPL who like me spent 48h finding the fix]

ALTHOUGH I'm not sure it will work in "headless mode" (which is the goal) since it may be using "spice" ??? Keep going...

NOTE: no solution found for "spice mode"

  1. In either etc/udev/rules.d or usr/lib/udev/rules.d find a file named something like ??-usbmuxd.rules

    For example in my case 39-usbmuxd.rules

  2. Comments the following lines (adding a #)

    
    # systemd should receive all events relating to device
    #SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*", TAG+="systemd"

Initialize iOS devices into "deactivated" USB configuration state and activate usbmuxd

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*", ACTION=="add", ENV{USBMUX_SUPPORTED}="1", ATTR{bConfigurationValue}="0", OWNER="usbmux", ENV{SYSTEMD_WANTS}="usbmuxd.service"

Make sure properties don't get lost when bind action is called

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*", ACTION=="bind", ENV{USBMUX_SUPPORTED}="1", OWNER="usbmux", ENV{SYSTEMD_WANTS}="usbmuxd.service"

Exit usbmuxd when the last device is removed

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*", ACTION=="remove", RUN+="/usr/sbin/usbmuxd -x"

Note that doing this, you're iphone's content won't be accessible through whatever your use for file explorer (e.g. nautilus)... You can't have all you want, make your choice... ;-)

3. in terminal reload the rules
> sudo udevadm control --reload-rule

4. Remove if exist (gnome users only I think) : _**gvfs-gphoto2**_

5. in the _macos-catalina.conf_
- don't use display="spice", use "gtk" instead
- add the device line
the file should look like : 

guest_os="macos" disk_img="macos-catalina/disk.qcow2" img="macos-catalina/RecoveryImage.img" macos_release="catalina" display="gtk" usb_devices=("05ac:12a8")


6. ensure where is quickemu by typing in your terminal
> where quickemu
7. edit this this (in my case _/usr/bin/quickemu_)
8. search the line:
> USB_PASSTHROUGH="${USB_PASSTHROUGH} -device usb-host,bus=hostpass.0,vendorid=0x${VENDOR_ID},productid=0x${PRODUCT_ID}
9. add _,guest-reset=false_  after _{PRODUCT_ID}_ :
```      USB_PASSTHROUGH="${USB_PASSTHROUGH} -device usb-host,bus=hostpass.0,vendorid=0x${VENDOR_ID},productid=0x${PRODUCT_ID},guest-reset=false```

Hope it'll help someone.
github-actions[bot] commented 2 years ago

Hello there πŸ‘‹ Thanks for submitting your first issue to the Quickemu project πŸ› We'll try and take a look at your issue soon ⏲

In the meantime you might want to join the Wimpys World Discord πŸ—£ where we have a large community of Linux 🐧 enthusiasts and passionate open source developers πŸ§‘β€πŸ’»

You might also be interested in following Wimpys World Twitch πŸ“‘ channel where Wimpy streams let's code video, including this project, several times a week. A back catalog of past live stream and other Linux related content is available on Wimpys World YouTube πŸ“Ί channel.

sowinski commented 2 years ago

Any progress on that?

flexiondotorg commented 1 year ago

It would be good to see a definitive solution for this issue added to the documentation πŸ™‚

nicolasmol commented 1 year ago

@flexiondotorg have you seen that it requires a modification in quickemu script by adding this option : guest-reset=false

nichady commented 1 year ago

This is the only solution that works for me: https://github.com/sickcodes/Docker-OSX/tree/bb1e9929163bc515dd06a68fd92a54f06140dd8d#usbfluxd-iphone-usb---network-style-passthrough-osx-kvm-docker-osx

nobodyguy commented 2 months ago

Hope it'll help someone.

Merci. It works for me :)

SiBurgmaier commented 1 month ago

Hello,

the solution above doesn't work for me. After I connect the iPhone, I get the message where I can choose "trust the computer" or I "don't trust the computer". I choose trust, but on the macOS Sonoma VM changes nothing. The iPhone is not listed in the finder and is not chooseable in Xcode.

I tried to use spice but not I get the error: usb_redirection error libusb_error_not_found More information here: https://chatgpt.com/share/759bdff2-e230-492e-bc28-04d0498881df

It worked one time and only one time with that solution from chatgpt. I can't reproduce it.

With lsusb I can see, that the iPhone is disconnecting and reconnecting very often. The device number is rising and the error-message, mentioned above, reopens every few seconds. This is because the option in spice "auto redirect newly plugged in USB devices.

This is my config:

!/usr/bin/quickemu --vm

guest_os="macos" disk_img="macos-sonoma/disk.qcow2" img="macos-sonoma/RecoveryImage.img" macos_release="sonoma" extra_args="-cpu host -usb -device usb-ehci,id=spiceusb -device usb-host,vendorid=0x05ac,productid=0x12a8" display="spice" cpu_cores=8 ram="8G"

Thanks for the mentioned solution above. I hope to find a solution for this problem and I am thankfull for every anwser.

nobodyguy commented 1 month ago

@SiBurgmaier Yeah, it worked for me only once, so I ended up buying 2018 mac mini instead just to get the initial ios development stages done.