设为首页 收藏本站
查看: 1540|回复: 0

[经验分享] Power OFF and ON USB device in linux (ubuntu)

[复制链接]

尚未签到

发表于 2017-11-23 10:34:22 | 显示全部楼层 |阅读模式
Power OFF and ON USB device in linux (ubuntu)
  http://loginroot.com/power-off-and-on-usb-device-in-linux-ubuntu/

  There are two methods of doing this. So first method is for kernels after 2.6.32, and second for older ones.
  To view kernel version, simply enter:







Shell



1
2


> uname -r
3.8.0-29-generic
  find Your USB device, no mather what it is USB flash drive, Yubikey, USB disk drive:







Shell



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


> lsusb
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 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 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 005: ID 12d1:14db Huawei Technologies Co., Ltd.
Bus 002 Device 006: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub

> lsusb -t
/:  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
        |__ Port 1: Dev 5, If 0, Class=comm., Driver=cdc_ether, 480M
        |__ Port 1: Dev 5, If 1, Class=data, Driver=cdc_ether, 480M
        |__ Port 5: Dev 6, If 0, Class=hub, Driver=hub/4p, 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
  
Our target is:







Shell



1


Bus 002 Device 005: ID 12d1:14db Huawei Technologies Co., Ltd.
  Which is located at 2-1.1 (tree part where device 5 is located)
First method (newer kernel)
  To turn it off simply echo address:







Shell



1


echo '2-1.1' > /sys/bus/usb/drivers/usb/unbind
  here is result from syslog:







Shell



1


Feb 20 12:03:27 vgsms6 kernel: [ 1734.993667] cdc_ether 2-1.1:1.0 eth2: unregister 'cdc_ether' usb-0000:00:1d.0-1.1, CDC Ethernet Device
  Unfortunately this device was still visible in lsusb, so I turned off whole usb hub there (2-1), and voila, usb device gone.
  To enable it, echo same address to “bind” part, for example:







Shell



1


echo '2-1.1' > /sys/bus/usb/drivers/usb/bind
  Second method (older kernel)
You need to go to devices:







Shell



1


cd /sys/bus/usb/devices
  Addressess will be listed similar:







Shell



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17


/sys/bus/usb/devices# ls -alh
total 0
drwxr-xr-x 2 root root 0 Feb 20 11:34 .
drwxr-xr-x 4 root root 0 Feb 20 11:34 ..
lrwxrwxrwx 1 root root 0 Feb 20 11:34 1-0:1.0 -> ../../../devices/pci0000:00/0000:00:1a.0/usb1/1-0:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 1-1 -> ../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1
lrwxrwxrwx 1 root root 0 Feb 20 11:34 1-1:1.0 -> ../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-0:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 2-1 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.1 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1:1.0
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.1:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.1:1.1 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.1
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.5 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5
lrwxrwxrwx 1 root root 0 Feb 20 12:34 2-1.5:1.0 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/2-1.5:1.0
lrwxrwxrwx 1 root root 0 Feb 20 11:34 usb1 -> ../../../devices/pci0000:00/0000:00:1a.0/usb1
lrwxrwxrwx 1 root root 0 Feb 20 11:34 usb2 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2
  So go to in our example 2-1.1/power (full path /sys/bus/usb/devices2-1.1/power)







Shell



1


cd /sys/bus/usb/devices2-1.1/power
  to turn off device:







Shell



1


echo suspend > level
  to turn on:







Shell



1


echo on > level


Share this:


  • Facebook
  • Google
  • Reddit
  • LinkedIn
  • Twitter
  • Email


Like this:

Related


Installing Debian on GuruPlug Server Plus

Guruplug serial connection

Updating u-boot on GuruPlug Server PLUS


← Previous post
Next post →

Comments (7)



  • DSC0000.jpg AnonymousSeptember 28, 2014 at 4:01 pm
      ~ $ sudo echo ‘1-1.2’ > /sys/bus/usb/drivers/usb/unbind
    -bash: /sys/bus/usb/drivers/usb/unbind: Permission denied

    Reply ↓


  • NiekoNovember 4, 2014 at 11:59 am
      Thanks, finally got it working! :)
      Anonymous: your command executes “echo ‘1-1.2′” under sudo, and then tries to write that to /sys/bus/usb/drivers/usb/unbind as the normal user again. Try this: echo ‘1-1.2″ | sudo tee /sys/bus/usb/drivers/usb/unbind

    Reply ↓


  • SantosNovember 8, 2014 at 2:25 am
      You could also use a switchable USB hub.
      Something like this https://www.yepkit.com/products/ykush
      but it’s more expensive :)

    Reply ↓



    • nsc(Post author)November 8, 2014 at 9:47 am
        Smart way of leaving a backlink.
      I encourage doing opensource projects :)
        Usually the budget depends on what are the requirements. For a simple “faulty” usb emergency device reset I would use my way (I wouldn’t expect something to break, would I?).
        But for day to day planned switch off/on I’d consider such device.
      Thanks for sharing Your product.
      That’s pretty useful thing, it should have more reliable switching capability and it’s more powerful than a server usb port.
        You should consider making a bigger hub, as it seems to be possible to use it as a powersource for usb devices (2Amps of current).
      For example external usb 2.5 hdd would already take 2 ports, leaving only one free.
      Or make an usb controlled power source switcher with relays, it would perfectly go as a combo with this usb hub device :)

      Reply ↓



      • SantosNovember 8, 2014 at 1:58 pm
          Fully agree with you, the best approach depends of the requirements.
          Those are cool ideas for improving the product.
          Cheers

        Reply ↓


  •   Pingback: » Linux: Turning off power to usb port. Or turn off power to entire usb subsystem
  •   Pingback: Raspberry Pi + L-02C でバッチリ安定する多機能 LTE ルータをつくったメモ – 怠惰の形而上学

Leave a Reply

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-409795-1-1.html 上篇帖子: Ansible无网络安装Newton版本openstack 下篇帖子: #LNMP一键安装包
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表