3

Whenever I plug an USB mass storage device into the system, I get uevents like these from the kernel. (as shown by udevadm monitor)

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)

I need to attach the USB device to a KVM as soon as possible, and while udev rules allows me to call a script that does the attaching, the kernel processing still takes place automatically. I'd like to prevent that from happening. Would this be possible with udev or some other mechanism?

hotmultimedia
  • 86
  • 1
  • 6
  • We can do this if you are willing to build a custom kernel? If you are interested reply to this comment and I could try an answer. – Vality Aug 13 '14 at 16:43
  • @Vality Sure, custom kernel is an option. – hotmultimedia Aug 14 '14 at 09:24
  • I actually realized in resent kernels you can do this easily and without modifying the kernel. Please see below. If you have an older kernel you may need to patch the features in. – Vality Aug 14 '14 at 10:07

1 Answers1

4

I actually remembered this is far simpler than I remembered in new kernels, you simply have to run:

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

as root at boot time, this will prevent the kernel from probing USB devices when they are connected, thus they will only be enumerated when you manually choose to do so by writing something to /sys/bus/usb/drivers_probe.

This should do more or less what you want, the kernel will not bind any drivers to the USB devices, you are then free to bind them to your VM later.

Vality
  • 6,577
  • 3
  • 27
  • 48