Device management in Linux … continued

In case you read my previous post about the intricacies of /proc directory, now I would like to continue in the same line and tell my thoughts about other two Linux folders being mount points for virtual filesystems, /dev and /sys. 

Before going further I just want to share with you an interesting resource that I found about this extended topic how Linux sees PnP devices) which outlines probably better what I am trying  to do in a couple of posts 🙂 (very useful and intuitive the CPU privilege rings, also the communication diagram at the end)

What to say about /sys, or about Sysfs (file system)? Since I am a very “young” Linux user I do not have the practical understanding and meaning of it… I just can add my impression to the dozens of the  already existing ones on forums, discussion lists, or simply … on Google …

It is younger, much younger, than Procfs, it has been introduced starting with kernel 2.6, and basically was adopted because of the lack of an unified method of exporting device/drivers info and also in order to release some of the burden and mess in the already existing Procfs. Anyhow here you may found some differences between the two.

Do not mix it with /proc/sys!!  The latter one contains critical info about the system and kernel configuration which can be overwritten by the admin on the fly, without recompilation of the kernel (so, be veeeery careful when play with it!!), while former one is a mount point of Sysfs, containing attached drivers and devices to the systems, meaning that is rather a read-only directory or informative.

Here(this one being written by the author of Sysfs himself) and also here, you may find some really documented resources about Sysfs (also I am sure that there are tons of them, on tlpd.org, or kernel.org, and many more ..) but only for LPIC-1 sake is better  to say some words about utilities like udev, HALd and D-BUS, than to dive into Kobjects and classes …

In this way, one of the important purposes of /sys is that it is used by HAL daemon for detecting devices attached to the system. Another utilities used for discovering “complicated” devices, like PnP ones, is udev, which recently replaced the obsolete HAL software project. This one is based on /dev folder(which in fact is completely managed by udev). Now … what about Devfs and /dev??

Historically /dev has been the mount point (what in Windows and Mac OS is represented as some cosy icons) and Devfs the managing SW on Linux systems for devices detected by the system. The problem was that Devfs suffered some drawbacks: was completely implemented in the kernel, did not had a persistent device naming, depended for example on the order in which devices were added to the system …

All these paved the way to the creation of udev (introduced in 2.5), which is NOT only an utility or an aplication, is an administration system. Udev is composed of three parts: libudev, udevd (daemon) and udevadm. The first one  is walking through Sysfs at boot time and fills the /dev folder with the corresponding device nodes. Then the daemon, which runs in the user space, maintains the /dev folder, by filling it with nodes added on the fly. Udevd listens uevents from the driver core and depending on the /etc/udev/rules.d/* rules  creates nodes in /dev, symbolic links or runs specific SW for setting up the corresponding device. Finally udevadm requests uevents, manages the events queue and provides simple debugging mechanisms.

Enough for today, I will try not to stray too far from the initial purpose of these posts, being as a kind of tutorial for LPIC, even it will be really hard not to approach topics like Netlink, IPC or Filesystem hierarchy standard, which may  inherently pop-up while discussing about Linux device management and hotplugging.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: