LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Register
Go Back   LinuxQuestions.org > Blogs > kingbeowulf
User Name
Password

Notices


Rate this Entry

Qemu USB passthrough with specifics for iphone

Posted 09-05-2018 at 01:39 PM by kingbeowulf

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
Code:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="*",GROUP="users", MODE="0660"
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
Code:
udevadm control -R
to relaoad the new udev rules. Next run qemu. My qemu Win10 invocation is:
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
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
Code:
(qemu) info usbhost
should show the iphone entry. If not, check lsusb on the host and find out why. Next, connect the iphone to the guest:
Code:
(qemu) device_add usb-host,bus=ehci.0,port=1,vendorid=0x05ac,productid=0x12a8,id=iphone
productid=0x12a8 is for an iphone 5c, substitute as needed. If you have just the one device, you can also just:
Code:
(qemu) device_add usb-host,bus=ehci.0,port=1,vendorid=0x05ac,id=iphone
. Note that with the second verion, the iphone can reboot/reset and still automatically attach to the windows guest. The command line version is:
Code:
-device usb-host,bus=ehci.0,port=1,vendorid=0x05ac,id=iphone
The optional "id=xxxx" is important to use the command to detach the usb device.
Code:
(qemu) device_del iphone
To restore/reset the iphone via recover mode, be aware that the product ID is diferent in recovery mode. For the iphone 5c
Code:
05ac:1281 Apple, Inc. Apple Mobile Device [Recovery Mode]
05ac:12a8 Apple 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
Posted in Uncategorized
Views 15240 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    test
    Posted 10-19-2024 at 06:38 PM by jailbait jailbait is offline
  2. Old Comment
    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:f9
    Code:
    (qemu) info usbhost
      Bus 3, Addr 41, Port 1, Speed 480 Mb/s
        Class 00: USB device 05ac:12a8, iPhone
    lsusb output on my host OS: lsusb -v -d 05ac: (link expires in a week)
    And inxi -Fxxxrz (link expires in a week)
    iTunes in Guest OS
    Posted 10-19-2024 at 07:41 PM by LinuxNoobi LinuxNoobi is offline
 

  



All times are GMT -5. The time now is 10:40 AM.

Contact Us - Advertising Info - Rules - Privacy - Donations - Contributing Member - LQ Sitemap - "Weather apps tell you it'll rain. Wyndo tells you when to go."
Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions