#!/bin/bash echo "🔄 Resetting USB system..." # Step 1: Unmount the drive if it's mounted MOUNT_POINT="/mnt/my-drive" if mountpoint -q "$MOUNT_POINT"; then echo "⚡ Unmounting $MOUNT_POINT..." sudo umount "$MOUNT_POINT" else echo "⚠ No drive mounted at $MOUNT_POINT" fi # Step 2: Unload USB storage module echo "⚡ Unloading usb_storage module..." sudo rmmod usb_storage 2>/dev/null || sudo modprobe -r usb_storage sleep 2 # Step 3: Reset the USB controller echo "🔄 Unbinding USB controller..." echo -n "0000:00:14.0" | sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind sleep 2 echo "🔄 Binding USB controller..." echo -n "0000:00:14.0" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind sleep 2 # Step 4: Reload USB storage module echo "⚡ Reloading usb_storage module..." sudo modprobe usb_storage echo "✅ USB reset complete! Run 'lsusb' to verify."