Nothing happens in Linux without udev knowledge when you connect any device. When you plug USB stick to the computer with Linux OS the really interesting things happen behind the scene where udev and dbus comes to play to provide recognizing and loading appropriate modules to the kernel.
In linux everything is a file, so processes info and kernel stuff as a files have been put into a virtual filesystem in /proc folder and may be read very easy even with cat command. In the course of time not only information about processes have been stored in procfs but also some system information. Creating of sysfs that is a follower of procfs was requirement in order to add handling with system (devices, configuration, memory addresing etc) and has been introduced in kernel 2.5. Sysfs added a structure and starts in /sys folder.
From kernel 2.6 udev was introduced with /dev folder. Udev is a device manager for Linux kernel. Manages permissions, creating symlinks (provides understandable consistent names), dynamically creates and removes devices files. Udev takes information from sysfs on the fly and this is how it gets information about hotplugged devices. The last link in this chain is dbus, that reads information from udev about plugged devices and pass along this information with signals to programs and operating system. So if you connect something to the system, system can automatically get this information just thanks to dbus.
How does the process of connecting device looks ?
1. Device is attached
2. Kernel detects its and sysfs gets information about device
3 Udev receives device event from the kernel
4. Udev matches it rules in /etc/udev/rules.d/*.rules directory againts various device attributes to identify the device and create the symlink (UUID to the readable name), set permisions, rename the device etc.
Udevadm device for management and monitoring events from UDEV and KERNEL. For example if we connect and disconnect USB stick, ‘udevadm monitor‘ command will show us this whole process.
Discovering of devices is the one part of the process that enable us using of devices. We know that each device requires a driver. In Linux, drivers that enable talking between device and the kernel are stored in /lib/modules folder. This folder contains drivers that can be loaded as needed, have modular structure and kernel doesn’t have to be recompile.after loading the module.
There is a couple of commands that enable us modules management and collecting information about devices.
lspci – shows pci bus devices
lsusb – shows usb devices
lsmod – shows modules currently loaded by OS
rmmod – removing modules / unloading modules
insmod – inserting module / loading module
modinfo [module_name] – shows info about module
uname – shows info about system
Modprobe is a new command that does similar what ‘insmode’ but also pay attention on dependencies, if we want to load given module but also the other modules need to be loaded in order to work properly, modprobe will do that automatically, ‘insmode’ can’t handle with dependencies.
modprobe -r – removing module
modprobe – loading module