Linux 下关闭USB端口(U盘)电源

U盘卸载之后,U盘的电源并没有关闭。如果想关闭U盘电源,可以打开“磁盘”这个工具,它有关闭U盘电源的按钮。

如果不想打开图形工具操作,可以使用命令行操作内核参数,达到相同效果

lsusb

——————————-示例————–

Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 2232:1041
Bus 001 Device 035: ID 0cf3:3004 Atheros Communications Inc.
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 017: ID 046d:c016 Logitech Inc. Optical Wheel Mouse
Bus 003 Device 009: ID 046d:c52e Logitech Inc.
Bus 003 Device 016: ID 058f:6387 Alcor Micro Corp. Flash Drive
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

这个是U盘的 信息 Bus 003 Device 016: ID 058f:6387 Alcor Micro Corp. Flash Drive

设备号是 16
——————————————————

lsusb  -t

(以树形方式显示)
/:  Bus 04.Port 1: Dev 1 Class=root_hub Driver=xhci_hcd/4p 5000M
/:  Bus 03.Port 1: Dev 1 Class=root_hub Driver=xhci_hcd/4p 480M
|__ Port 1: Dev 16 If 0 Class=Mass Storage Driver=usb-storage 480M
|__ Port 2: Dev 9 If 0 Class=Human Interface Device Driver=usbhid 12M
|__ Port 2: Dev 9 If 1 Class=Human Interface Device Driver=usbhid 12M
|__ Port 4: Dev 17 If 0 Class=Human Interface Device Driver=usbhid 1.5M
/:  Bus 02.Port 1: Dev 1 Class=root_hub Driver=ehci-pci/2p 480M
|__ Port 1: Dev 2 If 0 Class=Hub Driver=hub/6p 480M
/:  Bus 01.Port 1: Dev 1 Class=root_hub Driver=ehci-pci/2p 480M
|__ Port 1: Dev 2 If 0 Class=Hub Driver=hub/6p 480M
|__ Port 3: Dev 35 If 0 Class=Wireless Driver=btusb 12M
|__ Port 3: Dev 35 If 1 Class=Wireless Driver=btusb 12M
|__ Port 4: Dev 4 If 0 Class=Video Driver=uvcvideo 480M
|__ Port 4: Dev 4 If 1 Class=Video Driver=uvcvideo 480M

以设备号找到系统分配的端口号,可以看到设备号16 的系统分配端口是   ‘3-1’

sudo su  进入root模式

eject  sdb       (弹出U盘,回写数据。下面这一步是直接断电,请先umount 保存数据,弹出U盘!)

echo ‘3-1’ > /sys/bus/usb/drivers/usb/unbind     (断开连接,直接断电)

恢复电源、连接:

echo ‘3-1’ > /sys/bus/usb/drivers/usb/bind

上面的方法也能操作其它USB设备

发表评论

电子邮件地址不会被公开。 必填项已用*标注

跳至工具栏