When using your Ubuntu device as a USB tethering point, you may encounter a situation where your device starts to charge instead of simply transferring data. While this can be convenient for some, it can also drain the battery of the tethered device. Fortunately, there are methods to disable charging via the USB port while tethering. This article will guide you through the process, provide insights, and share practical examples.
The Problem Scenario
The issue arises when an Ubuntu system is used for USB tethering to share internet connectivity with another device. By default, the USB port may enable charging, causing the tethered device to charge while being connected. This can lead to unintended battery usage for devices that rely on the USB connection solely for data transfer.
Here’s an illustrative example of the code you might encounter or need when setting up your tethering configuration:
sudo nmcli device set <device-name> managed no
This command is typically used to manage network connections but does not address the issue of disabling charging while tethering.
Disabling USB Charging
To disable charging through the USB port on Ubuntu, you can make use of specific configurations in your system. Follow these steps to achieve this:
-
Check Kernel Parameters: Some Linux distributions provide a way to control USB power settings via kernel parameters. You can check if your system supports this by looking at the
/sys/bus/usb/devices/
directory. -
Modify the USB Power Configuration:
- Navigate to the USB device directory using:
cd /sys/bus/usb/devices/usbX/ # Replace 'X' with the specific bus number of your USB device
- You can write to
power/control
to change the power mode. Set it to 'suspend':echo 'suspend' | sudo tee power/control
- Note that not all devices may support this and results can vary.
- Navigate to the USB device directory using:
-
Using Udev Rules: Creating a udev rule can help automate this process. Create a new file in the udev rules directory:
sudo nano /etc/udev/rules.d/99-usb-tethering.rules
Add the following line to disable charging:
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="XXXX", ATTR{idProduct}=="YYYY", RUN+="/bin/sh -c 'echo '0' > /sys/bus/usb/devices/$kernel/power/control'"
Replace
XXXX
andYYYY
with your USB device’s vendor ID and product ID, which can be found using the commandlsusb
.
Practical Example
For instance, if you are tethering an Android smartphone to your Ubuntu laptop, and you want to prevent the phone from charging, you might want to check the vendor and product IDs first:
lsusb
Assuming the output shows:
Bus 001 Device 002: ID 18d1:4ee0 Google Inc.
You would replace XXXX
with 18d1
and YYYY
with 4ee0
in your udev rule.
Conclusion
Disabling charging while tethering on Ubuntu is achievable through careful configuration and modification of system parameters. By implementing the steps outlined above, you can enhance your tethering experience without worrying about draining the battery of the tethered device.
Additional Resources
By keeping these configurations in mind, you’ll be better equipped to manage your devices while utilizing USB tethering efficiently.
Feel free to share your experiences or reach out if you have additional questions regarding USB tethering or managing power settings in Ubuntu!