昨天朋友問我把 USB 裝置停電的實際命令,Google 了一下找到了方法,筆記一下。
首先要知道你的 USB 裝置代號,可以在插入後使用 dmesg 查看[?]。例:
[ 8944.330557] usb 1-8: USB disconnect, address 8 [ 9023.580525] usb 1-8: new high speed USB device using ehci_hcd and address 9 [ 9023.714733] usb 1-8: New USB device found, idVendor=0b27, idProduct=0163 [ 9023.714737] usb 1-8: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 9023.714739] usb 1-8: Product: USB Mass Storage Device [ 9023.714741] usb 1-8: Manufacturer: USBest Technology [ 9023.714743] usb 1-8: SerialNumber: 000000000016F3 [ 9023.714828] usb 1-8: configuration #1 chosen from 1 choice [ 9023.715549] scsi7 : SCSI emulation for USB Mass Storage devices [ 9023.715694] usb-storage: device found at 9 [ 9023.715696] usb-storage: waiting for device to settle before scanning [ 9028.712208] usb-storage: device scan complete [ 9028.713173] scsi 7:0:0:0: Direct-Access Ut163 USB2FlashStorage 0.00 PQ: 0 ANSI: 2 [ 9028.717275] sd 7:0:0:0: [sdd] 1974271 512-byte logical blocks: (1.01 GB/963 MiB) [ 9028.718294] sd 7:0:0:0: [sdd] Write Protect is off [ 9028.718299] sd 7:0:0:0: [sdd] Mode Sense: 00 00 00 00 [ 9028.718301] sd 7:0:0:0: [sdd] Assuming drive cache: write through [ 9028.725637] sd 7:0:0:0: [sdd] Assuming drive cache: write through [ 9028.725645] sdd: sdd1 [ 9028.837666] sd 7:0:0:0: [sdd] Assuming drive cache: write through [ 9028.837672] sd 7:0:0:0: [sdd] Attached SCSI removable disk [ 9149.868714] Shorewall:net2fw:DROP:IN=eth0 OUT= MAC=00:1f:d0:37:37:0a:00:30:88:12:54:d6:08:00 SRC=189.1.169.123 DST=123.205.248.119 LEN=40 TOS=0x00 PREC=0x00 TTL=92 ID=256 PROTO=TCP SPT=6000 DPT=1433 WINDOW=16384 RES=0x00 SYN URGP=0 [ 9231.369074] sd 7:0:0:0: [sdd] 1974271 512-byte logical blocks: (1.01 GB/963 MiB) [ 9231.369566] sd 7:0:0:0: [sdd] Assuming drive cache: write through [ 9231.370687] sd 7:0:0:0: [sdd] Assuming drive cache: write through [ 9231.370690] sdd: sdd1因為它寫
usb 1-8
,所以要控制的 USB 接口代號就是 1-8,很簡單吧?反正找有 usb 字樣的就對了。底下的 sd 是表示它被分配到哪個磁區代號,因為這支是隨身碟才會是這樣,其他類型的裝置會有不同的訊息,不過這不是重點,所以沒差啦。
然後請到
以本例來說是 1-8 所以是:
噢,當然你要有相當於 root 的權限。
/sys/bus/usb/devices
裡找剛剛的接口代號的資料夾,在那裡面找 power/level
,該檔是一個文字檔,或者說看起來是文字檔,內容應該是 on。只要把 on 改成 suspend 就可以把電源切斷。注意不是 off,如果輸入錯誤的字串它會無法存檔,不用擔心會改錯。以本例來說是 1-8 所以是:
# echo suspend > /sys/bus/usb/devices/1-8/power/level電源燈就會熄了。
噢,當然你要有相當於 root 的權限。