Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.5-pro-exp-03-25-grounding· GoogleHugging Face LMArena Search Arena 24K

How do I power cycle a usb port on Fedora? I want to turn off power for a specific USB…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.0-flash-grounding’s answer.
  1. User

    How do I power cycle a usb port on Fedora? I want to turn off power for a specific USB port and then enable it again.

  2. Gemini Assistant

    Okay, power cycling a specific USB port programmatically in Linux (like Fedora) can be tricky and highly dependent on your hardware (specifically the USB hub controller). Not all hardware supports per-port power switching [1, 10].

    Here are the common methods, ranging from the most direct (if supported) to more indirect approaches:

    1. Using uhubctl (Recommended if your hardware is compatible)[1]

    uhubctl is a command-line tool designed specifically to control power on individual ports of USB hubs that support this feature [1, 10]. Many modern hubs, including some integrated into motherboards or laptops, might be compatible.

    • Check Hardware Support: First, you need a "smart" USB hub that allows per-port power switching[2]. Many hubs do not support this [10].
    • Install uhubctl on Fedora:
      sudo dnf install uhubctl
      
      [11]
    • List Available Hubs and Ports: Run uhubctl without arguments to see detected controllable hubs and their ports, along with their current power status and location IDs [1, 9].
      sudo uhubctl
      
      The output will show hubs and their ports, like location 1-4.1 or similar.
    • Turn Power Off: Use the location (-l), port number (-p), and action off (-a off) [1, 9][3].
      # Example: Turn off port 2 on hub at location 1-4
      sudo uhubctl -l 1-4 -p 2 -a off
      
    • Turn Power On: Use the same command but with action on (-a on) [1].
      # Example: Turn on port 2 on hub at location 1-4
      sudo uhubctl -l 1-4 -p 2 -a on
      

    Important: If uhubctl doesn't list your hub or ports, your hardware likely doesn't support per-port power control via this method [10]. Some hardware (like Raspberry Pi internal hubs) might turn off all ports even when targeting one [10][2].

    2. Using the sysfs Filesystem (More Manual, Less Direct Power Control)

    Linux exposes USB device information and some controls via the /sys/bus/usb/devices/ directory[4][5][7]. You can sometimes influence power states or reset devices here, but direct power cutting isn't always possible [1, 5].

    • Identify the Device Path:
      • First, find the Bus and Device number using lsusb[6].
      • Then, locate the corresponding directory in /sys/bus/usb/devices/[1]. The directory names often correspond to the bus-port path (e.g., 1-2, 2-3.1). You might need to explore subdirectories or check files like idVendor and idProduct to confirm you have the right device.
    • Method A: Unbind/Bind (Simulates unplug/replug logically): This resets the device driver's connection but doesn't guarantee a power cycle [5, 8].
      • Find the device's bus ID (e.g., 1-2).
      • Unbind: echo '1-2' | sudo tee /sys/bus/usb/drivers/usb/unbind
      • Bind: echo '1-2' | sudo tee /sys/bus/usb/drivers/usb/bind
    • Method B: Port Disable (Newer Kernels, Requires Hardware Support): Some newer kernels (around v6+) might expose a disable control file directly on the port [5].
      • Navigate to the specific port's directory within the hub's device path (e.g., /sys/bus/usb/devices/usbX/X-Y/X-Y:1.0/X-Y-portZ/). You'll need to figure out the exact path.
      • Disable: echo 1 | sudo tee disable
      • Enable: echo 0 | sudo tee disable
      • Caveat: Actual power off still depends on hardware support. For USB3 ports, you might need to disable the 'peer' USB2 port as well [5][1].
    • Method C: Control Device Power State (Autosuspend): This usually puts the device into a low-power state or suspend, not a full power off, and depends on driver cooperation [1, 5, 7].
      • Find the device directory (e.g., /sys/bus/usb/devices/1-2/power/).
      • Force suspend (if supported): echo "auto" | sudo tee control (or echo "suspend" > level on older kernels) and potentially echo 0 | sudo tee autosuspend_delay_ms [5][1].
      • Wake up/force on: echo "on" | sudo tee control

    3. Using usbreset (Sends Reset Signal, Not Power Cycle)[6]

    There's a common C utility (usbreset.c) or pre-built tools that send the USBDEVFS_RESET ioctl command [8]. This asks the device to reset itself, similar to a warm reboot for the device, but doesn't cut power [5, 8].

    • Compile (if needed): You can find the C code online [8] and compile it:
      cc usbreset.c -o usbreset
      chmod +x usbreset
      
    • Identify Device: Use lsusb to find the bus and device number (e.g., Bus 002 Device 005).
    • Execute:
      sudo ./usbreset /dev/bus/usb/002/005
      
      Replace 002/005 with your actual bus/device numbers [8]. Some packaged versions might allow using the device name [8]. A Python tool usb_resetter also exists [6][9].

    4. Reloading the USB Controller Driver (Drastic)

    You can unload and reload the kernel module for the entire USB controller (e.g., xhci_hcd for USB3, ehci_hcd or uhci_hcd for USB2). This resets the controller and all devices attached to it [13].

    • Identify Driver: Use lspci -nnk and look for your USB controllers to see the "Kernel driver in use" [13].
    • Unload: sudo modprobe -r xhci_hcd (or ehci_hcd, uhci_hcd). Warning: This will disconnect all devices on that controller (keyboard, mouse included if they use it!).
    • Reload: sudo modprobe xhci_hcd (or the one you removed).

    In Summary:

    1. Try uhubctl first. It's the cleanest method if your hardware supports per-port power switching.
    2. If uhubctl doesn't work, explore the /sys filesystem methods like unbind/bind or port disable (newer kernels) for a logical reset.
    3. Use usbreset if you just need to reinitialize the device without cutting power.
    4. Reloading the kernel module (modprobe -r / modprobe) is a last resort as it affects multiple ports/devices.

    Remember to use sudo for most of these commands as they require root privileges.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.