LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Give QEMU's guest (Win XP) USB access... (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/give-qemus-guest-win-xp-usb-access-4175604510/)

edbarx 04-24-2017 10:12 AM

Give QEMU's guest (Win XP) USB access...
 
I would like to ask how I can further optimize QEMU to run Windows XP as guest. I am using QEMU version 1:2.8+dfsg-3. To start the guest (Windows XP), I use the command:
Code:

/usr/bin/qemu-system-i386 -drive format=raw,file=win_xp.img -enable-kvm -machine type=pc,accel=kvm &
I need the VM to have access to a USB oscilloscope. I used:
Code:

-usb -device usb-host,usbbus=1,usbaddr=3
together with the parameter list.

The guest's performance is quite a good but it says no graphics drivers are being used. Can I further improve the graphics performance?

I am on Devuan ASCII (equivalent to Debian Testing).

With the latter, the host OS denied the VM access to USB telling me libusb couldn't grant permission.

!!! 04-24-2017 01:35 PM

What EXACTLY is the error? (for Goog!e) http://www.linuxquestions.org/questi...emu-4175492519 ?
Can you strace it, to see where it fails? root privs?
+1 for latest devuan! ;) Maybe Edit Title to include PRECISE error plus libusb version.

edbarx 04-25-2017 02:49 AM

I hit that thread before writing this new question. The decision as to why I am using a virtual machine to run Windows XP, stems from two limitations: a) my hardware is too new to be compatible with XP, b) I want to avoid accessing the internet or any network through Windows, any version. The reason is to free myself from having to have an antivirus running all the time eating precious CPU and RAM resources, and also, I do not want to update Windows. On this same machine I have a partition with Windows 8.1 installed that I can boot to use my USB oscilloscope.

Running a virtual machine as root is not attractive to me as it would mean having an aggregate of executables running with root privileges. To me it is the same as running XFCE or a heavier desktop as root.

In short, when I try to run QEMU to virtualise Windows XP, I get the error:
Code:

qemu-system-i386: -device usb-host,hostbus=2,hostaddr=3: failed to find host usb device 2:3
Running lsusb yeilds:
Code:

$ lsusb
Bus 004 Device 005: ID 0cf3:311d Atheros Communications, Inc.
Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 003: ID 1e3d:2093 Chipsbank Microelectronics Co., Ltd CBM209x Flash Drive (OEM)
Bus 002 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

EDIT to add more information:
Reading the man page I changed the qemu-system-i386 command to:
Code:

$ /usr/bin/qemu-system-i386 -drive format=raw,file=/home/edbarx/qemu/win_xp.img -enable-kvm -machine type=pc,accel=kvm -usb -usbdevice host:0002.0003 -usbdevice host:0001.0003 &
qemu-system-i386 failed complaining:
Code:

[1] 6024
edbarx@edbarx-pc3:~$ libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/002/003: Permission denied
libusb: error [_get_usbfs_fd] libusb requires write access to USB device nodes.
qemu-system-i386: -usbdevice host:0002.0003: Failed to initialize USB device 'usb-host': failed to open host usb device 2:3
qemu-system-i386: -usbdevice host:0002.0003: could not add USB device 'host:0002.0003'

It seems this is a permissions issue. I have to in some way give libusb permission to access USB devices but I have to do it minimally.

EDIT 2: The Cause.
The following shows I do not have enough privileges to write to usb devices. Just inspect the permissions.
Code:

edbarx@edbarx-pc3:/dev/bus/usb$ ls -l
total 0
drwxr-xr-x 2 root root  80 Apr 25 10:27 001
drwxr-xr-x 2 root root 100 Apr 25 10:43 002
drwxr-xr-x 2 root root  60 Apr 25 10:27 003
drwxr-xr-x 2 root root 100 Apr 25 10:28 004
edbarx@edbarx-pc3:/dev/bus/usb$ cd 002
edbarx@edbarx-pc3:/dev/bus/usb/002$ ls -l
total 0
crw-rw-r-- 1 root root 189, 128 Apr 25 10:27 001
crw-rw-r-- 1 root root 189, 129 Apr 25 10:28 002
crw-rw-r-- 1 root root 189, 130 Apr 25 10:43 003


edbarx 04-25-2017 07:50 AM

The reason was device file name permissions which udev assigns as o664 i.e. rw-rw-r--. For testing puposes, I changed that to rw-rw-rw-. Bringing up the virtual machine with the command:
Code:

/usr/bin/qemu-system-i386 -drive format=raw,file=/home/edbarx/qemu/win_xp.img -enable-kvm -machine type=pc,accel=kvm -usb -usbdevice host:001.009 &
allowed me to recognise the USB oscilloscope as new hardware in Windows XP and install its drivers. Notwithstanding the success, the speed of communication between the oscilloscope and the client was unsatisfactory. Unupdated Windows XP as far as I can tell only supports USB 1.0 which drastically reduces speed.

The udev device file I had to modify is under /dev/bus/usb/00x/.

Hopefully this is enough to help anyone reading this thread.

d9961876 12-29-2019 11:12 AM

Thank you for the fix. This is still a problem with ASCII at the end of 2019.

For me, the solution was:

Code:

chmod a+w /dev/bus/usb/003/064
And then adding the related line in my Qemu command line fixed things with my Windows 7 guest:

Code:

-usb -device usb-host,hostbus=3,hostaddr=64
Admittedly this is not a permanent fix as it has to be run every hotplug, but it will do for now.

d9961876 12-29-2019 11:23 AM

Actually, a longer term solution is as follows:

1. Edit /etc/udev/rules.d/flash.rules. Add this:
Code:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", GROUP="users", MODE="0666"
You need to look at the output of lsusb and replace the XXXX and YYYY with what you see either side of the colon in lsusb output
e.g.
Code:

Bus 003 Device 001: ID XXXX:YYYY Linux Foundation 2.0 root hub
2. Add the bus and device IDs to your Qemu command line. This could be scripted to handle dynamic IDs:
Code:

qemu ....... -usb -device usb-host,hostbus=3,hostaddr=1 .....
Hope this helps some noob somewhere.


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