Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop automatic Linux device initialization

Tags:

linux

usb

udev

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?

like image 510
hotmultimedia Avatar asked Feb 04 '26 11:02

hotmultimedia


1 Answers

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.

like image 99
Vality Avatar answered Feb 07 '26 01:02

Vality



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!