当我暂停笔记本电脑时,如何关闭鼠标的USB电源?

我的老鼠的LED灯在睡觉时会让我神经紧张。 我通常在晚上关闭我的笔记本,Ubuntu打电话给pm-suspend 。 无论如何,USB插头仍然供电。 我甚至可以为智能手机充电。 这对我来说有两个原因。 我必须拔掉我的鼠标,笔记本电池组[akku]持续时间更少。 当笔记本电脑进入挂起模式时,有没有办法自动关闭USB设备或所有USB设备?

如何配置?

编辑:根据评论中的要求,我添加此信息:我使用的是联想G550。

编辑:在这里请求我的lsusb输出

 Bus 002 Device 019: ID 1058:25a3 Western Digital Technologies, Inc. Bus 002 Device 017: ID 1b1a:7001 Bus 002 Device 009: ID 2109:2812 VIA Labs, Inc. VL812 Hub Bus 002 Device 008: ID 2109:2812 VIA Labs, Inc. VL812 Hub Bus 002 Device 003: ID 0402:5608 ALi Corp. Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 006: ID 046d:c52b Logitech, Inc. Unifying Receiver Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 

编辑:我认为这些信息也会导致答案。

 root@localhost:/sys/bus/usb/devices# ls -al insgesamt 0 drwxr-xr-x 2 root root 0 Okt 6 10:56 . drwxr-xr-x 4 root root 0 Okt 6 10:56 .. lrwxrwxrwx 1 root root 0 Okt 6 10:56 1-0:1.0 -> ../../../devices/pci0000:00/0000:00:1a.7/usb1/1-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-3 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-3 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-3:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-3/2-3:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-3:1.1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-3/2-3:1.1 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5.1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5.1 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5.1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5.1/2-5.1:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5.1.2 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5.1/2-5.1.2 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5.1.2:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5.1/2-5.1.2/2-5.1.2:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5.1.2:1.1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5.1/2-5.1.2/2-5.1.2:1.1 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5.2 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5.2 lrwxrwxrwx 1 root root 0 Okt 6 10:56 2-5.2:1.0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5.2/2-5.2:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 3-0:1.0 -> ../../../devices/pci0000:00/0000:00:1a.0/usb3/3-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 4-0:1.0 -> ../../../devices/pci0000:00/0000:00:1a.1/usb4/4-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 5-0:1.0 -> ../../../devices/pci0000:00/0000:00:1a.2/usb5/5-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 6-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb6/6-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 6-1 -> ../../../devices/pci0000:00/0000:00:1d.0/usb6/6-1 lrwxrwxrwx 1 root root 0 Okt 6 10:56 6-1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb6/6-1/6-1:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 6-1:1.1 -> ../../../devices/pci0000:00/0000:00:1d.0/usb6/6-1/6-1:1.1 lrwxrwxrwx 1 root root 0 Okt 6 10:56 6-1:1.2 -> ../../../devices/pci0000:00/0000:00:1d.0/usb6/6-1/6-1:1.2 lrwxrwxrwx 1 root root 0 Okt 6 10:56 7-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.1/usb7/7-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 8-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.2/usb8/8-0:1.0 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb1 -> ../../../devices/pci0000:00/0000:00:1a.7/usb1 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb2 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb3 -> ../../../devices/pci0000:00/0000:00:1a.0/usb3 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb4 -> ../../../devices/pci0000:00/0000:00:1a.1/usb4 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb5 -> ../../../devices/pci0000:00/0000:00:1a.2/usb5 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb6 -> ../../../devices/pci0000:00/0000:00:1d.0/usb6 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb7 -> ../../../devices/pci0000:00/0000:00:1d.1/usb7 lrwxrwxrwx 1 root root 0 Okt 6 10:56 usb8 -> ../../../devices/pci0000:00/0000:00:1d.2/usb8 

编辑:

 tokam@localhost:~$ lsusb -t /: Bus 08.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M /: Bus 07.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M /: Bus 06.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 1: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 1: Dev 2, If 2, Class=Human Interface Device, Driver=usbhid, 12M /: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M |__ Port 3: Dev 3, If 0, Class=Video, Driver=uvcvideo, 480M |__ Port 3: Dev 3, If 1, Class=Video, Driver=uvcvideo, 480M |__ Port 5: Dev 51, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 1: Dev 52, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 2: Dev 54, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 2: Dev 54, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 2: Dev 53, If 0, Class=Mass Storage, Driver=usb-storage, 480M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M 

OP链接的当前绊脚石,后续评论和建议的答案是产品ID是静态1b1a:7001但总线和设备号码不断变化。

解决方案

在目录/etc/pm/sleep.d/创建一个脚本(您想要的任何名称),并将以下内容放入其中:

 #!/bin/bash ZeroBUS=$(lsusb | grep 1b1a:7001 | cut -c 5-7 ) # Strip leading zeros BUS=$(echo $ZeroBUS | sed 's/^0*//') # Build "usbX" usb number USB=usb$BUS case $1 in suspend|suspend_hybrid|hibernate) echo "Powering off: " $USB echo $USB | sudo tee /sys/bus/usb/drivers/usb/unbind ;; resume|thaw) # No need to do anything here, kernel unsuspends USB devices # Show how to power on for interest sake but since device is # powered off the usb number will be blank. echo "Powering on: " $USB echo $USB | sudo tee /sys/bus/usb/drivers/usb/bind ;; esac 

使用sudo chmod +x file_name将文件标记为可执行文件,其中“file_name”是您选择的名称。

说明

此解决方案关闭整个USB集线器,在我的情况下,这意味着电话,无线鼠标,无线键盘等。当从终端提示调用脚本时,需要输入sudo密码。 希望从systemd调用时sudo权力是inheritance的。 我无法测试这个,因为我没有有线鼠标。 因此,对于sudo权力可能需要额外的细化。

当BIOS提供恒定的5V电源时,电源不会被物理切断,而是告知总线上的设备自动关闭。 在我的情况下,无线键盘和鼠标停止工作,不得不求助于笔记本电脑键盘和触摸板重新打开电源。

您可以通过调用脚本并传递参数“suspend”来手动测试。 传递参数“resume”没有任何结果,因为设备已关闭,它没有设备ID可以重新打开它。

通过发出命令lsusb (插入和不插入)找到鼠标的总线和设备#,你想要插入插入时只有那里的那个。记下数字。 在你的情况下,他们似乎是6和6

发出命令sudo cp /etc/pm/sleep.d/novatel_3g_suspend /etc/pm/sleep.d/mouse_suspend (我们必须这样做,因为当我以超级用户身份启动时, gedit不再具有“另存为”选项。)

发出命令gksu gedit /etc/pm/sleep.d/mouse_suspend更改总线和设备编号以匹配您之前记录的编号。 保存生成的文件。 它将在您暂停笔记本电脑时执行。

在您的情况下,您应该将BUS = X和DEVICE = Y更改为与相关鼠标匹配的总线和设备编号。 这将一直有效,直到您将设备移动到另一个端口,在这种情况下,您将不得不再次找到该设备并相应地调整该文件。

 BUS=X DEVICE=Y if [ ! -x /sys/bus/usb/devices/${BUS}-${DEVICE}/power/level ]; then exit 0 fi case $1 in suspend|suspend_hybrid|hibernate) echo suspend > /sys/bus/usb/devices/${BUS}-${DEVICE}/power/level ;; resume|thaw) # No need to do anything here, kernel unsuspends USB devices : ;; esac 

文件中的注释(以#开头的行)无关紧要,可以安全地忽略。

注意:我在桌面上通过Suspend进行了测试,并按宣传方式工作。 我无法访问您拥有的相同硬件,但我必须通过电源按钮恢复系统,所以我相当确定这对您有用。

根据评论和问题扩展进行编辑:

看来这是您需要继续的信息: Bus 006 Device 006: ID 046d:c52b Logitech, Inc. Unifying Receiver