Qemu USB passthrough with specifics for iphone
Posted 09-05-2018 at 01:39 PM by kingbeowulf
Tags iphone, pasthrough, qemu, usb, windows
Qemu still befuddles me at times. It doesn't help when various command line options are deprecated and changes. For qemu-3.xx, there have been some changes to setting up USB passthrough. This all all came to a head when I needed to restore an iphone. The powermac G5 is dismantled at the moment, so I thought, why not use the Windows 10 VM? After letting Win10 grind along updating itself (I don't fire it up very often), I installed itunes (win10 has an "app store"? ugh.), the fun began.
Since qemu runs as a regular user, it cannot connect to hot-plug USB devices unless you change permssions on the host. Being in group plugdev might be sufficient for standard USD block devices. For others, such as an iphone, you need to manually change the /dev/bus/usb/xxx/yyy to group users or create
/etc/udev/rules.d/97-iphone.rules
0x05ac vendor ID in this case is for an Apple iPhone 5C. For iphones specifically, it can help to disable usbmuxd with an empty /etc/udev/rules.d/39-usbmuxd.rules
Now, either reboot (ha! this ain't windows!) or run as root
to relaoad the new udev rules. Next run qemu. My qemu Win10 invocation is:
You need to specify an ehci USB hub otherwise the iphone won't connect (speed mismatch). Note the new "-device" options for all devices. The older option versions are deprecated. Also, you will need to install the windows virtio guest drivers to use virtio-net-pci. I download the iso and replace /dev/dvd to install. Using the gtk display is nice since you get a nice menu to access the qemu console. Now, plug in the iphone into the host, open the qemu console
should show the iphone entry. If not, check lsusb on the host and find out why. Next, connect the iphone to the guest:
productid=0x12a8 is for an iphone 5c, substitute as needed. If you have just the one device, you can also just:
. Note that with the second verion, the iphone can reboot/reset and still automatically attach to the windows guest. The command line version is:
The optional "id=xxxx" is important to use the command to detach the usb device.
To restore/reset the iphone via recover mode, be aware that the product ID is diferent in recovery mode. For the iphone 5c
If you leave off the product ID, qemu will reattach each time the iphone reboots.
1. https://qemu.weilnetz.de/doc/qemu-doc.html
2. https://github.com/qemu/qemu/blob/master/docs/usb2.txt
3. https://docs.fedoraproject.org/en-US...ers/index.html
Since qemu runs as a regular user, it cannot connect to hot-plug USB devices unless you change permssions on the host. Being in group plugdev might be sufficient for standard USD block devices. For others, such as an iphone, you need to manually change the /dev/bus/usb/xxx/yyy to group users or create
/etc/udev/rules.d/97-iphone.rules
Code:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="*",GROUP="users", MODE="0660"
Now, either reboot (ha! this ain't windows!) or run as root
Code:
udevadm control -R
Code:
#!/bin/sh
# MS Windows 10 VM
export QEMU_AUDIO_DRV=pa
BASE="windows10.img"
CPUS="-cpu host -smp 4"
RAM="8G"
qemu-system-x86_64 -enable-kvm -machine accel=kvm -m $RAM -hda $BASE -cdrom /dev/dvd -boot order=cd $CPUS \
-name "Windows10" -soundhw hda -device usb-ehci,id=ehci -usb -device usb-tablet -vga std -display gtk \
-netdev user,id=mynet1,hostname=win10vm,smb=/games/win32/ -device virtio-net-pci,netdev=mynet1,mac=52:54:00:35:a6:50
Code:
(qemu) info usbhost
Code:
(qemu) device_add usb-host,bus=ehci.0,port=1,vendorid=0x05ac,productid=0x12a8,id=iphone
Code:
(qemu) device_add usb-host,bus=ehci.0,port=1,vendorid=0x05ac,id=iphone
Code:
-device usb-host,bus=ehci.0,port=1,vendorid=0x05ac,id=iphone
Code:
(qemu) device_del iphone
Code:
05ac:1281 Apple, Inc. Apple Mobile Device [Recovery Mode] 05ac:12a8 Apple iPhone 5C
1. https://qemu.weilnetz.de/doc/qemu-doc.html
2. https://github.com/qemu/qemu/blob/master/docs/usb2.txt
3. https://docs.fedoraproject.org/en-US...ers/index.html
Total Comments 2
Comments
-
testPosted 10-19-2024 at 06:38 PM by jailbait
-
Hello, I have followed all your steps but it behaves the same as I would just open virt-manager, start the vm and go to
"Virtual Machine" > "Redirect USB device".
It's just redirecting PTP (Picture Transfer Protocol). I can see and access my photos through Windows Explorer, but iTunes isn't seeing the device, because (I assume) it isn't redirecting the "Apple Mobile Device" protocol, which is needed for iTunes (according to ChatGPT, ik not very reliable but still better than no info ig).
ChatGPT:
Quote:Your iPhone has 4 configurations, which indicate the different "modes" or sets of features it can present over USB:
Configuration 1: PTP (Picture Transfer Protocol) — for transferring photos.
Configuration 2: iPod USB Interface — likely for media sync and audio streaming.
Configuration 3: PTP + Apple Mobile Device — this is for iTunes syncing.
Configuration 4: PTP + Apple Mobile Device + Apple USB Ethernet — adds a virtual network interface for tethering.
Apple USB Multiplexor (in Configurations 3 and 4):
This is the core Apple protocol that iTunes needs to interact with your device (Configuration 3 and 4 both present this).
This is likely why you can't sync with iTunes if your VM doesn’t see the correct USB interface.
I have changed your run script a little so it fits for me. (Removed the audio because of this error that I got in terminal:
)Quote:qemu-system-x86_64: warning: '-soundhw hda' is deprecated, please use '-device intel-hda -device hda-duplex' instead
Code:#!/bin/sh # MS Windows 10 VM BASE="/var/lib/libvirt/images/win10.qcow2" CPUS="-cpu host -smp 6" RAM="6G" qemu-system-x86_64 -enable-kvm -machine accel=kvm -m $RAM -hda $BASE \ -cdrom ~/VMs/virtio-win-0.1.262.iso -boot order=cd $CPUS \ -name "Windows10" \ -device usb-ehci,id=ehci -usb \ -device usb-host,bus=ehci.0,port=1,vendorid=0x05ac,id=iphone \ -device usb-tablet \ -vga std -display gtk \ -netdev user,id=mynet1,hostname=win10vm \ -device virtio-net-pci,netdev=mynet1,mac=52:54:00:51:d6:f9lsusb output on my host OS: lsusb -v -d 05ac: (link expires in a week)Code:(qemu) info usbhost Bus 3, Addr 41, Port 1, Speed 480 Mb/s Class 00: USB device 05ac:12a8, iPhone
And inxi -Fxxxrz (link expires in a week)
iTunes in Guest OSPosted 10-19-2024 at 07:41 PM by LinuxNoobi



