如何停止自动Linux设备初始化

时间:2014-08-13 15:37:31

标签: linux usb udev

每当我将USB大容量存储设备插入系统时,我都会从内核中获取这些内容。 (如udevadm监视器所示)

KERNEL[104397.739313] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6 (usb)
KERNEL[104397.740141] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0 (usb)
KERNEL[104397.740787] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48 (scsi)
KERNEL[104397.741362] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/scsi_host/host48 (scsi_host)
KERNEL[104399.210661] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0 (scsi)
KERNEL[104399.211095] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0/48:0:0:0 (scsi)
KERNEL[104399.211502] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0/48:0:0:0/scsi_disk/48:0:0:0 (scsi_disk)
KERNEL[104399.211757] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0/48:0:0:0/scsi_device/48:0:0:0 (scsi_device)
KERNEL[104399.212464] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0/48:0:0:0/scsi_generic/sg1 (scsi_generic)
KERNEL[104399.212743] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0/48:0:0:0/bsg/48:0:0:0 (bsg)
KERNEL[104399.215444] add      /devices/virtual/bdi/8:16 (bdi)
KERNEL[104399.220099] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0/48:0:0:0/block/sdb (block)
KERNEL[104399.220181] add      /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/host48/target48:0:0/48:0:0:0/block/sdb/sdb1 (block)

我需要尽快将USB设备连接到KVM,虽然udev规则允许我调用执行附加的脚本,但内核处理仍然会自动进行。我想防止这种情况发生。用udev或其他机制可以实现吗?

1 个答案:

答案 0 :(得分:3)

我实际上记得这比我在新内核中记得的要简单得多,你只需要运行:

echo '0' > /sys/bus/usb/drivers_autoprobe

在启动时以root用户身份,这将阻止内核在连接时探测USB设备,因此只有在您通过向/sys/bus/usb/drivers_probe写入内容手动选择时才会枚举它们。

这应该或多或少地做你想要的,内核不会将任何驱动程序绑定到USB设备,然后你可以随时将它们绑定到你的VM。