Using usbip Command (with examples)
- Linux
- November 5, 2023
USBIP is a command-line tool that allows USB devices to be used remotely. This can be useful in scenarios where a USB device needs to be accessed by multiple computers or when a device needs to be accessed over a network. In this article, we will explore various use cases of the usbip command and provide code examples for each scenario.
Use Case 1: Listing Local USB Devices
To list all local USB devices and their bus IDs, you can use the following command:
usbip list --local
Motivation: This command is useful for identifying all the USB devices connected to your system and their corresponding bus IDs. This information is required for other usbip commands.
Explanation: The usbip list
command lists all USB devices that are currently attached to the local system. The --local
option restricts the listing to only local USB devices.
Example Output:
- busid 1-1.1:1.0 (0403:6001)
Generic USB IO Board (usb234705271)
1-1.1:1.0
- busid 1-1.3:1.0 (041e:403a)
Creative Technology, Ltd (usb234705272)
1-1.3:1.0
Use Case 2: Starting usbip Daemon on the Server
To start the usbip daemon on the server, you can use the following command:
systemctl start usbipd
Motivation: The usbip daemon needs to be running on the server for USB devices to be accessible remotely. This command starts the usbip daemon and allows USB devices to be shared.
Explanation: The systemctl start
command is used to start a system service, in this case, the usbipd daemon. The usbipd daemon is responsible for managing USB devices and allowing remote access to them.
Example Output: No output will be displayed if the daemon starts successfully.
Use Case 3: Binding a USB Device to usbip on the Server
To bind a USB device to usbip on the server, you can use the following command:
sudo usbip bind --busid=bus_id
Motivation: This command is used to make a USB device available for remote access. Binding a USB device to usbip enables other machines to access the device over the network.
Explanation: The usbip bind
command binds the specified USB device to usbip on the server. The --busid
argument is used to specify the bus ID of the USB device, which can be obtained from the “List Local USB Devices” command.
Example Output: No output will be displayed if the binding is successful.
Use Case 4: Loading Kernel Module on the Client
To load the kernel module required by usbip on the client, you can use the following command:
sudo modprobe vhci-hcd
Motivation: The vhci-hcd kernel module is needed on the client to support the virtual USB host controller. Loading this module enables the client machine to attach to usbip devices.
Explanation: The modprobe
command is used to load kernel modules. In this case, the vhci-hcd
module is loaded on the client machine, allowing it to emulate a USB host controller.
Example Output: No output will be displayed if the module is loaded successfully.
Use Case 5: Attaching to a usbip Device on the Client
To attach to a usbip device on the client, you can use the following command:
sudo usbip attach -r ip_address --busid=bus_id
Motivation: This command is used to establish a connection with a remote USB device. Attaching to a usbip device allows the client machine to access the USB device remotely.
Explanation: The usbip attach
command is used to attach to a usbip device on the client. The -r
option specifies the IP address of the server where the USB device is shared. The --busid
argument specifies the bus ID of the USB device.
Example Output: No output will be displayed if the attachment is successful.
Use Case 6: Listing Attached Devices
To list all attached devices, you can use the following command:
usbip port
Motivation: This command is useful for checking the status of currently attached USB devices. Listing attached devices allows you to verify if the USB devices are successfully attached to the client machine.
Explanation: The usbip port
command lists all USB devices that are currently attached to the client machine. This command provides information about the attached devices, such as the bus ID, device ID, and status.
Example Output:
Port 1: <Remote USB Device: busid 1-1.1>
Port 2: <Remote USB Device: busid 1-1.3>
Use Case 7: Detaching from a Device
To detach from a usbip device, you can use the following command:
sudo usbip detach --port=port
Motivation: This command is used to release a previously attached usbip device. Detaching from a device allows other clients to access the USB device.
Explanation: The usbip detach
command is used to detach from a usbip device on the client. The --port
argument specifies the port number of the device to be detached, which can be obtained from the “List Attached Devices” command.
Example Output: No output will be displayed if the detachment is successful.
Use Case 8: Unbinding a USB Device
To unbind a USB device from usbip, you can use the following command:
usbip unbind --busid=bus_id
Motivation: This command is used to remove the binding of a USB device from usbip. Unbinding a USB device releases it from remote access, making it available for local use.
Explanation: The usbip unbind
command unbinds the specified USB device from usbip. The --busid
argument is used to specify the bus ID of the USB device.
Example Output: No output will be displayed if the unbinding is successful.
Conclusion
In this article, we explored various use cases of the usbip command and provided code examples for each scenario. The usbip command allows USB devices to be used remotely, enabling remote access to USB devices over a network. By following the provided code examples and explanations, you can leverage the usbip command to manage and share USB devices effectively.