Dracut is a new system to generate, in the same way for all Gnu/Linux distributions, the special programs and files that make Linux boot.
Linux Format decided to find out more.
Q. OK, now I understand what we're talking about. But what is that initramfs thing?
A. Please let me check something before I answer that question. You do remember that Linux is only a kernel, and what its limits are, don't you?
Q. Er… sure. Yes, of course I do. The Linux kernel…
A. …is the basic software that executes orders to do all of and only the very basic, low-level stuff inside a computer, from managing hardware drivers to scheduling of different processes.
Q. Right, all becomes clear now… So, what does it do?
A. When a Linux kernel boots, the first thing it must do is find and mount the filesystem hosting the first program to run. That is the piece of software, usually called 'init', that knows how to start all the other programs in an ordered way, and where to find them (because, in general, they may be on a different disk, or on some other server).
Q. That doesn't sound like a really complicated task. Couldn't the kernel do that by itself?
A. Theoretically, yes. As a matter of fact, it is a complicated task (for a kernel, at least), when you start considering all of the different possibilities. These days, Linux runs on practically everything, from mainframes to mobile phones and car entertainment systems. Apart from the microprocessor, that first filesystem may be installed on good old hard disks, but it's also used on USB keys, network drives, flash chips and RAID arrays. And besides, even the filesystems on two identical computers may have entirely different configurations.
Q. Why do you say "entirely" different? Apart from their own type, that is ext3 or ext4, how else could the filesystems on two identical computers differ?
A. Well, they may or may not be compressed or encrypted, just to mention the most frequent cases. Which means that the kernel should have not only the right software tools to access them but, in the latter case, also the right password. Finally, in a world full of laptops, Linux must also be able to handle hibernation - that is to boot back to the exact state it was at when it was suspended.
Q. OK, so there are a lot of possibilities, after all.
A. Indeed. At least there are enough that it would be very hard to describe all of them only with command-line options for the kernel. Besides, the kernel is such a peculiar piece of software that it's also difficult to make it perform all of the possible actions needed to find the root device. Some developers express this concept by saying that the kernel is built only to take orders and requests, not to make decisions.
Q. And how does initramfs go about solving this problem? I mean, what IS an initramfs anyway?
A. It is, as its name suggests, a small 'initial filesystem' that was introduced with the 2.6 version of the Linux kernel, built to be loaded in the RAM and ran entirely from it. The purpose of an initramfs is to host, in a place and format surely usable by the kernel, a custom version of the init program and all the drivers and tools that it may need at boot.
Once the kernel finds and launches that application, it doesn't have to perform any other special tasks anymore. It is that init program inside the initramfs that will find the real filesystem - the one where your Gnu/ Linux distribution lives - and start it.
Q. But isn't a filesystem a permanent data structure? How can one live in the RAM?
A. Well, in general, a filesystem is just a bunch of bytes which, as you'll already know, can be copied everywhere - that is internally formatted in such a way to host and easily find folders and files. However, to make it usable even from the RAM, an initramfs can be mounted as if it were a real disk that, for reasons too technical to cover here, doesn't need any driver.
Q. And you said that initramfs was already used before Dracut, didn't you?
A. That's correct. It has been used so much that, over the years, each GNU/Linux distribution has developed its own custom tools to generate these kinds of filesystems.
Q. Back to Dracut: how does it enter this picture?
A. Dracut is both a series of tools and a new method, based on Udev events, to create a general-purpose initramfs. It was created in 2009 to overcome certain limits of the previous distribution-specific systems.
Q. Wait! You did it again! Throwing around weird names. I mean, what's Udev?
A. Udev is the daemon that creates, names and deletes device nodes - that is the software interfaces to hardware devices, in all GNU/Linux systems.
Q. Why do we need a daemon for that?
A. The main reason is to have a standard way to get persistent device names, even for removable drives. Udev actions are communicated to all the programs that ask to be notified about them.
Q. Thanks. So, why was Dracut started? What is its purpose?
A. For end users, the most visible justification for Dracut will be faster boot times. Dracut should make it easier to mount and use the real root filesystem, that is to leave the initramfs with all its limitations, as soon as possible.
Q. What about developers and maintainers? What do they gain from Dracut?
A. In a nutshell, less code to run and debug, and more efficient ways to do it. As long as every distribution has its own tools to create an initramfs, there are more things that can go wrong. The first idea behind Dracut is to move the generation of initramfs outside the distributions, and to make it simpler to use for their maintainers.
Q. How would Dracut do that?
A. Through a simpler, generic init program that uses, for all the installation methods and boot configurations, the standard udev tool, inside a common and much more general initramfs. Another way in which Dracut would make developers' lives easier is the fact that it includes a diagnostic shell. There's also some activity to create 'hooks', that is ways for running arbitrary commands.
Q. But how would a generic init work in all cases?
A. Just because of the availability of udev in the new initramfs, Dracut turns the old procedures upside down. Instead of having each distribution, in a different way, stuffing its initramfs with all sorts of black magic tools for hardware detection, the init program in the initramfs generated by Dracut enables udev to create device nodes.
Q. You mean, just as it happens during normal operation, when I plug a USB key into my computer?
Q. What happens after that?
A. The boot phase is practically over. As soon as the device node of the real root filesystem is mounted, the kernel 'jumps' to it, leaving the initramfs to start the real init.
Q. Can Dracut create an initramfs optimised for my system?
A. Yes. You may, for example, easily create smaller images by passing to the Dracut script the -H option. This will leave on your hard drive an initramfs that, in general, won't boot if you move that drive to a computer with a different configuration, but how often is this a problem?
Q. What if I wanted, instead, to speed up the boot process?
A. In that case, you should describe yourself to Dracut, using the proper command-line options, how your system is configured and how you want it to boot. If you do that, Dracut will translate all that information into proper kernel options and other customisations, in order to create an initramfs that knows from the very first instant what the root filesystem is.