Using a Remote Host's Usb Port as Local Usb (Linux and Windows)

can local usb device be used by remote application through X11 forwarding?

This should do the work if you just need to read/write files on a USB drive.

You could mount your local usb on the remote computer using sshfs:

You need to install ssh on both computers:

$sudo apt-get install ssh

Plug your usb stick. You will probably have automount, if not, mount the usb drive manually:

$sudo mkdir /media/localUSB
$sudo shown YOUR_LOCAL_USER /media/localUSB
#replace YOUR_LOCAL_USER with your current user name of the local machine
$sudo mount /dev/sdbX /media/localUSB
#replace X with your usb device number

Then you need to install sshfs on the remote computer:

$sudo apt-get install sshfs

Create a mount point for your usb stick on the remote computer:

$sudo mkdir /media/remoteUSB
$sudo shown YOUR_REMOTE_USER /media/remoteUSB
#replace YOUR_REMOTE_USER with your current user name of the remote machine

Finally, mount it with sshfs:

$sshfs LOCAL_COMPUTER_ADRESS:LOCAL_USB_MOUNT_POINT /media/remoteUSB  -o ssh_command="ssh -l YOUR_REMOTE_USER" #l is L, not one
#replace LOCAL_COMPUTER_ADRESS with your local computer ip or host name
#replace LOCAL_USB_MOUNT_POINT with the directory whre the usb is mounted. If you made de manual mounting process, it should be: /media/localUSB
#replace YOUR_REMOTE_USER with your current user name of the remote machine

I dont know if you can remote mount /dev/sdbX using sshfs. If you need direct access to the USB port you should try it, but I never did it.

Docker - a way to give access to a host USB or serial device?

There are a couple of options. You can use the --device flag that use can use to access USB devices without --privileged mode:

docker run -t -i --device=/dev/ttyUSB0 ubuntu bash

Alternatively, assuming your USB device is available with drivers working, etc. on the host in /dev/bus/usb, you can mount this in the container using privileged mode and the volumes option. For example:

docker run -t -i --privileged -v /dev/bus/usb:/dev/bus/usb ubuntu bash

Note that as the name implies, --privileged is insecure and should be handled with care.

KGDB remote debugging connection issue via USB and Serial connection

The setup of remote kgdb debug is a bit tedious. There are several prerequisites/limitations for the kgdb to work. I will try to break it down.

You have to prepare two machines in this setup.

HOST: Where the agent-proxy & GDB installed.

TARGET: The Linux system being debugged.

Connection Setup

[Host /dev/ttyUSB0] USB to Serial --------- COM port [Target /dev/ttyS0]

On the TARGET side, it's not possible to use the USB interface with kgdb. This is because all the USB-Serial driver (CP210x, PL2303, ...etc) did not implement the polling hook. You have to connect the COM port with a serial cable directly. It is ok to use the USB interface on the HOST side. Since it is a serial connection, you have to use a USB-to-Serial converter and install the proper driver on HOST.

Set the proper baud rate on both sides:

[Target] stty -F /dev/ttyS0 115200
[Host] stty -F /dev/ttyUSB0 115200

Make sure the serial connection works on both direction. You can use:

[Host] cat /dev/ttyUSB0
[Target] echo 'from TARGET to HOST' > /dev/ttyS0

[Target] cat /dev/ttyS0
[Host] echo 'from HOST to TARGET' > /dev/ttyUSB0

You should see the messages on both side of machine. If not, there might be some problems on the cable or driver.

Compile Kernel

Enable KGDB* , KGDB_SERIAL*, KGDB_USB*, DEBUG_INFO, DEBUG_INFO_DWARF4, MAGIC_SYSRQ in the kernel config. Compile and install on the TARGET.

The main purpose here is to enable KGDB feature & preserve debug information in vmlinux.

agent-proxy Setup

agent-proxy acts as a proxy for the TARGET's serial port. It splits up the serial port for multiplexing. One for primary console I/O, the other for GDB session. Thus, we can work on both simultaneously. You should run the agent-proxy on HOST machine.

git clone http://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
cd agent-proxy ; make
./agent-proxy 5550^5551 0 /dev/ttyUSB0,115200

This will redirect:

  • TARGET's console to HOST:5550
  • TARGET's kgdb listening port to HOST:5551

Start To Debug

First, open the primary console:

[Host] telnet localhost 5550

Entering the kdb mode, either by:

[Target] echo ttyS0,115200 > /sys/module/kgdboc/parameters/kgdboc
[Target] dmesg | tail
(you should see KGDB: Registered I/O driver kgdboc, otherwise it failed)

[Target] echo g >/proc/sysrq-trigger

Or, by adding the following kernel parameters in TARGET's bootloader (for early kernel debug):

console=tty0 console=ttyS0,115200 kgdbwait kgdboc=ttyS0,115200

The TARGET machine will halt immediately once it breaks into the kdb.

At the same time, you will see a kdb prompt on the primary console:

....
Entering kdb (current=0xcb846c80, pid 2301) on processor 3 due to Keyboard Entry
[3]kdb>

Type kgdb then enter. The TARGET is now pending for remote GDB's connection. We will connect it from the HOST.

Host> gdb vmlinux
(gdb) target remote localhost:5551
Remote debugging using localhost:5551
kgdb_breakpoint () at kernel/debug/debug_core.c:1072
1072 wmb(); /* Sync point after breakpoint */
(gdb)

Enjoy your kernel debugging!

How to enable USB Redirection in Windows 10

I too have had problems using RemoteFX USB Redirection on a Windows 7 Client to a remote host on Azure running Windows 10, while the same machine configuration would successfully redirect USB to a Windows 8.1 Azure VM.

To be clear I've not had issues with the USB redirection for common devices (Flash drives, Printers, etc) that are supported with the vanilla setup of Remote Desktop. This type of USB redirection, for example, allowing me to see a Flash drive that I plug in to my Windows 7 client is working perfectly for me as I can see it in Explorer in the Azure VM.

A comparison of standard RDP redirection and RemoteFX redirection is detailed in this blog entry.

My particular USB redirection problem relates to the classes of devices not handled by the basic RDP high-level redirection, and for that I've enabled RemoteFX USB redirection on previous releases of Windows. When this is functioning correctly the computer icon (computer icon) appears in the Remote Desktop title bar allowing me to select which device should be redirected to the VM.

Titlebar when RemoteFX USB Redirection is working
Titlebar when RemoteFX USB Redirection is working

Following the instructions on numerous web resources for enabling RemoteFX USB redirection worked for me for earlier OS versions (i.e. Windows 8.1 on a Azure VM), but would not work for any Windows 10 VM I created. The titlebar stubbornly remained without the RemoteFX USB redirection feature.

Titlebar when RemoteFX USB Redirection was not working
Titlebar when RemoteFX USB Redirection was not working

I finally stumbled across this thread which solved my problem.

It seems there is one more step needed on a Windows 10 host compared to previous OS versions and that is:

  1. Run gpedit.msc on the target VM (the target windows 10 Virtual Machine) to start the Group Policy Editor. gpedit.msc can be typed in from a run dialog (use WinKey+R) if you have administrator access, or start an elevated CMD.EXE and type gpedit.msc from the command line.

  2. Locate the item Computer Configuration \ Administrative Templates \ Windows Components \ Remote Desktop Services \ Remote Desktop Session Host \ Device and Resource Redirection\ Do not allow supported Plug and Play device redirection from the treeview of the Group Policy Editor.

  3. Bizarrely set this item to Disabled.

  4. Run gpupdate /force from an elevated command prompt.

  5. At least disconnect RDP session and connect again, if this does not work reboot target VM.

USB device is not visible inside Vagrant

I found a solution. Here is short PowerShell script which is based on using devcon tool.

# Set location where devcon tool is placed

Set-Location "D:\MSSDK\Tools\x64"

# Disconnect USB from host machine

.\devcon.exe remove *VID_096E*

# Reconect USB to virtual machine

.\devcon.exe rescan

devcon.exe is a part of MS SDK toolkit. You can remove and connect any USB device even without its physical disconnection. After USB is disconnected from host machine I do rescan and after USB device is visible inside VirtualBox.

Accessing localhost of PC from USB connected Android mobile device

I finally solved this problem. I used Samsung Galaxy S with Froyo. The "port" below is the same port what you use for the emulator (10.0.2.2:port).
What I did:

  1. first connect your real device with the USB cable (make sure you can upload the app on your device)
  2. get the IP address from the device you connect, which starts with 192.168.x.x:port
  3. open the "Network and Sharing Center"
  4. click on the "Local Area Connection" from the device and choose "Details"
  5. copy the "IPv4 address" to your app and replace it like: http://192.168.x.x:port/test.php
  6. upload your app (again) to your real device
  7. go to properties and turn "USB tethering" on
  8. run your application on the device

It should now work.



Related Topics



Leave a reply



Submit