udevilicious - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html) +--- Forum: Kernel Related (https://www.linux-noob.com/forums/forum-61.html) +--- Thread: udevilicious (/thread-2756.html) |
udevilicious - znx - 2005-04-07 !--=[ udevilicios !--=[ by znx Original the /dev directory was full to the gills of every possible combination, this made for a huge amount of wasted space. Lots of devices that you would never need nor require and the possibility that the device doesn't exist at all. Now due to the fact that ever increasing amounts of hardware were getting supported (yes Linux is growing ;)) the /dev directory was growing to near ridiculous levels. Enter devfs. This was the first attempt at a solution to the problem, created by Richard Gooch, devfs allowed the device entries to be made on the fly. Connecting a device would then create the device node inside the /dev directory, disconnecting would then remove the entry. This mean that the huge difficultly with over population of the directory. So you think why udev? Well unfortunately devfs had some problems along the way (nothing that I ever encountered) but bugs that couldn't get solved meant that another solution was required. So this is where udev steps in, written by Greg Kroah-Hartman, it was a user space solution removing the need for more code inside the kernel (hence user dev!). One of the great features of udev is something called persistent naming. Normally devices are named in the order that they are connected in. If you use any USB device you'll already know this, the first time you find you camera as /dev/sda the next as /dev/sdb. This makes it a difficult to handle these devices via /etc/fstab. Udev solves all this by allowing the user to specify a device name. This means you can name your camera /dev/camera, no more hunting. All of the rules that we will create will be made in the file /etc/udev/rules.d/10-udev.rules. All the default rules are in /etc/udev/rules.d/50-udev.rules, don't add any here, they'll get overwritten. OK so lets find our device. I'm going to use my 256Mb USB stick in this example. So stick the drive into the port and lets look throw the output of dmesg. Code: # dmesg I can see that it has mounted this device under /dev/sda. You can also see that the drive hasn't had any partitions detected (else we would have sda1, sda2 etc). So now we need to discover where the information is stored inside the /sys directory. After that we can read through the information inside the /sys directory. Code: # udevinfo -q path -n /dev/sda There is a lot of data in there and what we need to do now is pick the correct keys to identify our device uniquely. So on with the rule (remember put this into /etc/udev/rules.d/10-udev.rules): Code: BUS="usb",KERNEL="sd[a-z]",SYSFS[product]="USB Flash Drive",NAME="%k",SYMLINK="flash" Let's walk through this: Code: BUS="usb" - Connecting on the USB bus You can add lots of other SYSFS entries if you need to tighten up the description of the device. Using "USB Flash Device" or something equally as generic can lead to more than device matching the rule. Instead look for information on the particular manufacture and model. Now when the device is connected the symlink will magically appear. And then you can use it. The entry can be made in /etc/fstab allowing quick and easy access to your device. A really nice rule to show you the power of udev is this: Code: KERNEL="eth*",SYSFS[address]="00:d0:b7:c5:48:30",NAME="inet" When the interface is configured you will get /dev/lan and /dev/inet. Just think of your firewall rules: Code: iptables -A input -i lan -p tcp -j accept This is far easier to understand which interface you are configuring. Well thats it.. have fun! udevilicious - znx - 2006-05-09 A question came from Fujita as to how you can obtain information about network interfaces, so: Code: udevinfo -a -p /sys/class/net/eth0/ :) .. keeping the udev alive!! |