bash 如何在 linux 中永久禁用特定的 USB 端口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27047959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:50:02  来源:igfitidea点击:

How to disable a specific usb port permanently in linux?

linuxbashusbreal-timepci

提问by gabriel

Is it possible to permanently disable a usbport in linux?

是否可以永久禁用 中的usb端口linux

I have already figured out how to disable it:

我已经想出了如何禁用它:

echo -n "0000:00:12.0" > /sys/bus/pci/drivers/ohci_hcd/unbind

BUT after restart it is enabled.

但是重启后它被启用。

I have placed this script :

我已经放置了这个脚本:

#!/bin/sh
case "" in
    resume|thaw)
            echo -n "0000:00:12.0" > /sys/bus/pci/drivers/ohci_hcd/unbind
            ;;
esac

in /etc/pm/sleep.d/0_disable_usb2

/etc/pm/sleep.d/0_disable_usb2

But again without success. I also thought that i could disable it through biosbut as i could see i can disable the whole pci.

但又没有成功。我还认为我可以禁用它,bios但正如我所见,我可以禁用整个pci.

Is there any way of doing this?

有没有办法做到这一点?

.. My Operating system is Debian 7.7 64bit. The reason i want to do this is I am trying to configure my system for realtimecapabilities and my usb soundcardsharing the same IRQwith this port.

.. 我的操作系统是Debian 7.7 64bit. 我想这样做的原因是我正在尝试配置我的系统的realtime功能,并与此端口usb soundcard共享相同的功能IRQ

采纳答案by muradin

First of all you should find your USB number of your device, Simply by using lsusb.

首先,您应该找到设备的 USB 编号,只需使用lsusb.

And in Linux everything is a file, So you can manage all of your hardware using the files.

在 Linux 中,一切都是一个文件,因此您可以使用这些文件管理所有硬件。

As it describes Hereif your kernel is > 2.6.38 you should use this keywords:

正如它在此处描述的那样,如果您的内核 > 2.6.38,您应该使用以下关键字:

echo "0" > "/sys/bus/usb/devices/usb2/power/autosuspend_delay_ms"
Then:

echo "0" > "/sys/bus/usb/devices/usb2/power/autosuspend_delay_ms"
然后:

echo "auto" > "/sys/bus/usb/devices/usb1/power/control"

echo "auto" > "/sys/bus/usb/devices/usb1/power/control"

回答by Mansur Ali

For me usb mounting is handle by a service udisk2.service if you would like to stop usb mounting then stop below service

对我来说,usb 安装由服务 udisk2.service 处理,如果您想停止 usb 安装,请停止以下服务

root@mahasan-Inspiron-5537:~# systemctl start udisks2.service
root@mahasan-Inspiron-5537:~# systemctl disable udisks2.service