How to Use the Command 'usbip' (with Examples)

How to Use the Command 'usbip' (with Examples)

The usbip command is a powerful Linux utility that allows you to share and access USB devices over a network, enabling remote usage of USB devices connected to a different machine. This is particularly useful in scenarios where physical access to a USB device is not feasible, or when you want to centralize device management. It works by transmitting USB I/O data over the IP network enabling the client and server systems to treat the remote USB devices as if they were locally connected.

Use Case 1: List All Local USB Devices and Their Bus IDs

Code:

usbip list --local

Motivation:

You often need to know which USB devices are connected to your local system and their bus IDs to configure or share them over the network. This command provides you with a list that allows you to identify each device.

Explanation:

  • usbip: The command used to interact with USB over IP.
  • list: The action to list USB devices.
  • --local: This option specifies that the listing should be done for devices on the local machine only.

Example Output:

- busid 1-1 (1a86:7523)
  1-1: CH340 serial converter
- busid 2-1 (0781:5567)
  2-1: SanDisk Ultra

Use Case 2: Start a usbip Daemon on the Server

Code:

systemctl start usbipd

Motivation:

Before you can share USB devices over the network, the usbip daemon needs to be running on the server machine. The daemon manages the sharing of USB devices by making them accessible over the network.

Explanation:

  • systemctl: A tool to examine and control the systemd system and service manager.
  • start: The action to initiate the specified service.
  • usbipd: The USB/IP daemon service, which must be started to facilitate communication.

There is no conventional output for this command unless there’s an error. You can verify success by checking service status.

Use Case 3: Bind a USB Device to usbip on the Server

Code:

sudo usbip bind --busid=bus_id

Motivation:

Binding a USB device is essential to make it available for export over the network. This step ensures that the specified USB device is connected to the usbip framework and is ready for remote usage.

Explanation:

  • sudo: This part of the command is used when you need administrative privileges for binding operations.
  • usbip: The command utility.
  • bind: The function to prepare the USB device for network sharing.
  • --busid=bus_id: This specifies the unique bus ID of the USB device to bind.

Example Output:

Bind device on busid 1-1: successful

Use Case 4: Load the Kernel Module Required by usbip on the Client

Code:

sudo modprobe vhci-hcd

Motivation:

On the client-side, you must load the necessary kernel module to enable virtual USB host controller support. This step is crucial to receive and interact with USB devices from the server machine.

Explanation:

  • sudo: Used to run commands with superuser privileges, necessary when manipulating kernel modules.
  • modprobe: A command to add or remove a module from the Linux kernel.
  • vhci-hcd: The Virtual Host Controller Interface Host Controller Driver, which manages the received USB devices over IP.

There is no conventional output for this command unless there’s an error.

Use Case 5: Attach to the usbip Device on the Client

Code:

sudo usbip attach -r ip_address --busid=bus_id

Motivation:

This command allows clients to establish a connection to the USB devices shared by the server. It effectively maps the remote USB device to the client, making it usable as if it were locally connected.

Explanation:

  • sudo: Needed for permission to attach USB devices.
  • usbip: The command utility for USB over IP operations.
  • attach: The function to connect to a remote device.
  • -r ip_address: Specifies the IP address of the server sharing the USB device.
  • --busid=bus_id: Uniquely identifies the USB device on the server.

Example Output:

usbip: info: attached to 1-1 on 192.168.1.10

Use Case 6: List Attached Devices

Code:

usbip port

Motivation:

This command provides a quick overview of all USB devices presently attached to the client system, allowing you to efficiently manage device connections.

Explanation:

  • usbip: The command utility for USB over IP operations.
  • port: Lists devices currently connected via USB/IP.

Example Output:

Port 00: <Port in Use> at High-Speed - SanDisk Ultra
    1-1 -> usbip://192.168.1.10:3240/1-1

Use Case 7: Detach from a Device

Code:

sudo usbip detach --port=port

Motivation:

When you are done using a USB device or need to reconfigure connections, detaching ensures that the client disconnects properly, preventing potential data loss or corruption.

Explanation:

  • sudo: Provides the necessary permissions.
  • usbip: The command utility to manage USB devices over the network.
  • detach: The function to disconnect from the attached USB device.
  • --port=port: Specifies the port number of the device to detach.

Example Output:

usbip: info: Port 00 detached

Use Case 8: Unbind a Device

Code:

usbip unbind --busid=bus_id

Motivation:

You may need to unbind a USB device when it is no longer required to be shared over the network, enhancing security and reducing unnecessary network traffic.

Explanation:

  • usbip: The command utility for managing USB over IP.
  • unbind: Removes the specified device from the usbip framework.
  • --busid=bus_id: The unique bus ID of the USB device to unbind.

Example Output:

Unbind device on busid 1-1: successful

Conclusion

The usbip command facilitates a unique capability to employ USB devices remotely through a network. By utilizing a series of operations, both on the server and client sides, any USB device can be virtually transported over distances, making them invaluable in distributed computing environments or centralized device management systems. Whether it’s listing devices, binding, attaching, or detaching them, each step is crucial for specific scenarios requiring USB access without physical proximity.

Related Posts

How to Use the 'unimatrix' Command (with Examples)

How to Use the 'unimatrix' Command (with Examples)

The unimatrix command is a fascinating tool for those who love the Matrix movie series or anyone interested in visualizing data streams in a unique and aesthetically pleasing manner.

Read More
Harnessing the Power of Mokutil for Secure Boot Management (with examples)

Harnessing the Power of Mokutil for Secure Boot Management (with examples)

Mokutil is a versatile command-line utility specifically designed for systems using UEFI firmware to manage Machine Owner Keys (MOK) associated with Secure Boot.

Read More
How to Use the Command 'bzegrep' (with Examples)

How to Use the Command 'bzegrep' (with Examples)

The bzegrep command combines the capabilities of egrep and bzip2 to allow users to search for extended regular expressions within bzip2 compressed files.

Read More