Initramfs/Guide/es

Muchos sistemas necesitan un sistema initramfs para arrancar correctamente. En esta guía se cubre el concepto de initramfs y de cómo crear y gestionar adecuadamente instancias initramfs.

Introducción
Para la mayoría de los usuarios un sistema initramfs no es ninguna preocupación. Sus sistemas utilizan un esquema simple de particionamiento sin controladores o configuraciones exótica (como sistemas de ficheros cifrados) de modo que el núcleo Linux es perfectamente capaz de tomar el control del binario en sus sistemas. Pero para otros usuarios es obligatorio el uso de un initramfs.

El concepto clave para comprender lo que es (o para qué se necesita) un initramfs es conocer cómo se realiza el proceso de arranque de Linux incluso desde un alto nivel.

El proceso de arranque de Linux
Una vez el núcleo Linux tiene control del sistema (lo cual sucede una vez lo ha cargado el gestor de arranque) prepara las estructuras de memoria y los controladores. Es entonces cuando le pasa el control a una aplicación (normalmente ) cuya tarea es preparar el sistema y asegurarse de que, al final de proceso de arranque, todos los servicios necesarios están corriendo y el usuario puede entrar en el sistema. La aplicación  lo hace lanzando, entre otros servicios, el demonio  que más adelante cargará y preparará el sistema basado en los dipositivos detectados. Cuando se lanza los sistemas de archivos restantes que no se han montado, se montan y el resto de los servicios se arrancan.

Para los sistemas en los que todos los ficheros y herramientas necesarios residen en el mismo sistema de archivos, la aplicación puede perfectamente controlar el proceso de inicio subsiguiente. Sin embargo cuando se definen múltiples sistemas de archivos (o se realizan instalaciones más exóticas), esto podría ser un poco más truculento:


 * Cuando la partición está en un sistema de archivos separado, las herramientas y controladores que tienen ficheros almacenados en  no se pueden utilizar a menos que  esté disponible. Si estas herramientas son necesarias para hacer que  esté disponible entonces no podremos arrancar el sistema.


 * Si el sistema de archivos raíz está cifrado, entonces el núcleo Linux no podrá encontrar la aplicación resultando un sistema que no arranca.

La solución a este problema ha sido desde hace tiempo utilizar un initrd (dispositivo raíz inicial)

El disco raíz de inicio
The initrd is an in-memory disk structure (ramdisk) that contains the necessary tools and scripts to mount the needed file systems before control is handed over to the application on the root file system. The Linux kernel triggers the setup script (usually called but that name is not mandatory) on this root disk, which prepares the system, switches to the real root file system and then calls.

Although the initrd method is all that is needed, it had a few drawbacks:


 * It is a full-fledged block device, requiring the overhead of an entire file system; it has a fixed size. Choosing an initrd that is too small and all needed scripts cannot fit. Make it too big and memory will be wasted.


 * Because it is a real, static device it consumes cache memory in the Linux kernel and is prone to the memory and file management methods in use (such as paging), this makes initrd greater in memory consumption.

To resolve these (for some perhaps hardly called) problems, the initramfs was created.

The initial ram file system
An initramfs is an initial ram file system based on tmpfs (a size-flexible, in-memory lightweight file system), which also did not use a separate block device (so no caching was done and all overhead mentioned earlier disappears). Just like the initrd, it contains the tools and scripts needed to mount the file systems before the binary on the real root file system is called. These tools can be decryption abstraction layers (for encrypted file systems), logical volume managers, software raid, bluetooth driver based file system loaders, etc.

The content of the initramfs is made by creating a cpio archive. is an old (but proven) file archiver solution (and its resulting archive files are called cpio files). cpio is definitely comparable to the archiver. The choice of here was because it was easier to implement (code-wise) and supported (back then) device files which  could not.

All files, tools, libraries, configuration settings (if applicable), etc. are put into the cpio archive. This archive is then compressed using the utility and stored alongside the Linux kernel. The boot loader will then offer it to the Linux kernel at boot time so the kernel knows an initramfs is needed.

Once detected, the Linux kernel will create a tmpfs file system, extract the contents of the archive on it, and then launches the script located in the root of the tmpfs file system. This script will then mount the real root file system (after making sure it can mount it, for instance by loading additional modules, preparing an encryption abstraction layer, etc.) as well as vital other file systems (such as and  ).

Once the root file system and the other vital file systems are mounted, the script from the initramfs will switch the root towards the real root file system and finally call the  binary on that system to continue the boot process.

Introduction and bootloader configuration
To create an initramfs, it is important to know what additional drivers, scripts and tools will be needed to boot the system. For instance, if LVM is used, then LVM tools will be needed in the initramfs. Likewise, if software RAID is used, utilities will be needed, etc.

Some tools exist that help users create initramfs' (compressed archives) for their system. But for those who want total control can easily create personal, custom initramfs' as well.

Once created, the bootloader configuration will need adjusted to inform it an initramfs is to be used. For instance, if the initramfs file is stored as, then the configuration in could look like the following:

Using genkernel
Gentoo's kernel building utility,, can be used to generate an initramfs, even if was not used to configure and build the kernel.

To use for generating an initramfs, it is recommended all necessary drivers and code that is needed to mount the  and  file systems be included in the kernel (not as modules). Then, call as follows:

Depending on the system, one or more of the following options may be needed:

When finished, the resulting initramfs file will be stored in.

Using dracut
The utility is created for the sole purpose of managing initramfs files. It uses a highly modular approach on what support is to be included and what is not to be included.

To install, make special care to include support for the correct value(s) in the DRACUT_MODULES variable. This variable can be set in to include support for system specific setups:

It is advisable to set (or unset) the modules needed. After configuring the DRACUT_MODULES variable in, to install the Dracut utility.

The next step is to configure by editing. In the configuration file, which is well commented, in order to add support for needed modules.

Una vez configurado, crear un initramfs llamando a como sigue:

The resulting image supports generic system boots based on the configuration in. It is also possible to generate an initramfs specifically tailored to your system (which tries to detect the needed tools, drivers, etc. from the existing system). If the modules and drivers are built into the kernel (not as separate modules and references to the firmware), then the  option can be added:

Para más información, echar un vistazo a las páginas del manual de dracut y dracut.cmdline:

Ver también

 * Initramfs en el wiki oficial de Gentoo.
 * Dracut en el wiki oficial de Gentoo.

Recursos externos

 * El fichero ramfs-rootfs-initramfs.txt dentro de la documentación del núcleo Linux.