HOME

TheInfoList



OR:

In
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
systems, initrd (''initial
ramdisk A RAM drive (also called a RAM disk) is a block of random-access memory (primary storage or volatile memory) that a computer's software is treating as if the memory were a disk drive (secondary storage). RAM drives provide high-performance tempor ...
'') is a scheme for loading a temporary root file system into
memory Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
, to be used as part of the
Linux startup process The Linux booting process involves multiple stages and is in many ways similar to the BSD and other Unix-style boot processes, from which it derives. Although the Linux booting process depends very much on the computer architecture, those architect ...
. initrd and initramfs (from INITial RAM File System) refer to two different methods of achieving this. Both are commonly used to make preparations before the real
root In vascular plants, the roots are the plant organ, organs of a plant that are modified to provide anchorage for the plant and take in water and nutrients into the plant body, which allows plants to grow taller and faster. They are most often bel ...
file system can be mounted.


Rationale

Many
Linux distribution A Linux distribution, often abbreviated as distro, is an operating system that includes the Linux kernel for its kernel functionality. Although the name does not imply product distribution per se, a distro—if distributed on its own—is oft ...
s ship a single, generic
Linux kernel The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
image one which the distribution's developers create specifically to boot on a wide variety of hardware. The
device driver In the context of an operating system, a device driver is a computer program that operates or controls a particular type of device that is attached to a computer or automaton. A driver provides a software interface to hardware devices, enabli ...
s for this generic kernel image are included as
loadable kernel module A loadable kernel module (LKM) is an executable library that extends the capabilities of a running kernel, or so-called ''base kernel'', of an operating system. LKMs are typically used to add support for new hardware (as device drivers) and/or ...
s because statically compiling many drivers into one kernel causes the kernel image to be much larger, perhaps too large to boot on computers with limited memory, or in some cases to cause boot-time crashes or other problems due to probing for nonexistent or conflicting hardware. This static-compiled kernel approach also leaves modules in kernel memory which are no longer used or needed, and raises the problem of detecting and loading the modules necessary to mount the root file system at boot time, or for that matter, deducing where or what the root file system is. To further complicate matters, the root file system may be on a software
RAID RAID (; redundant array of inexpensive disks or redundant array of independent disks) is a data storage virtualization technology that combines multiple physical Computer data storage, data storage components into one or more logical units for th ...
volume, LVM, NFS (on diskless workstations), or on an encrypted partition. All of these require special preparations to mount. Another complication is kernel support for
hibernation Hibernation is a state of minimal activity and metabolic reduction entered by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It is mos ...
, which suspends the computer to disk by dumping an image of the entire contents of memory to a
swap partition In computer operating systems, memory paging is a memory management scheme that allows the physical memory used by a program to be non-contiguous. This also helps avoid the problem of memory fragmentation and requiring compaction to reduce fra ...
or a regular file, then powering off. On next boot, this image has to be made accessible before it can be loaded back into memory. To avoid having to hardcode handling for so many special cases into the kernel, an initial boot stage with a temporary root file-systemnow dubbed
early user space The Linux booting process involves multiple stages and is in many ways similar to the BSD and other Unix-style boot processes, from which it derives. Although the Linux booting process depends very much on the computer architecture, those architect ...
is used. This root file-system can contain user-space helpers which perform the hardware detection, module loading and device discovery necessary to mount the actual file-system.


Implementation

An
image An image or picture is a visual representation. An image can be Two-dimensional space, two-dimensional, such as a drawing, painting, or photograph, or Three-dimensional space, three-dimensional, such as a carving or sculpture. Images may be di ...
of this initial root file system (along with the kernel image) must be stored somewhere accessible by the Linux
bootloader A bootloader, also spelled as boot loader or called bootstrap loader, is a computer program that is responsible for booting a computer and booting an operating system. If it also provides an interactive menu with multiple boot choices then it's o ...
or the boot firmware of the computer. This can be the root file system itself, a
boot image A boot image is a type of disk image that when on a boot device allows the associated computer to Booting, boot. A boot image usually includes an operating system, utilities, diagnostics, boot and data recovery information and applications used ...
on an
optical disc An optical disc is a flat, usuallyNon-circular optical discs exist for fashion purposes; see shaped compact disc. disc-shaped object that stores information in the form of physical variations on its surface that can be read with the aid o ...
, a small partition on a local disk (a ''boot partition'', usually using
ext2 ext2, or second extended file system, is a file system for the Linux kernel (operating system), kernel. It was initially designed by French software developer Rémy Card as a replacement for the extended file system (ext). Having been designed ...
or
FAT In nutrition science, nutrition, biology, and chemistry, fat usually means any ester of fatty acids, or a mixture of such chemical compound, compounds, most commonly those that occur in living beings or in food. The term often refers specif ...
file systems), or a
TFTP The Trivial File Transfer Protocol (TFTP) is a simple Lockstep (computing), lockstep communication protocol for transmitting or receiving files in a client-server application. A primary use of TFTP is in the early stages of nodes booting on a l ...
server (on systems that can boot from
Ethernet Ethernet ( ) is a family of wired computer networking technologies commonly used in local area networks (LAN), metropolitan area networks (MAN) and wide area networks (WAN). It was commercially introduced in 1980 and first standardized in 198 ...
). The bootloader will load the kernel and initial root file system image into memory and then start the kernel, passing in the memory address of the image. At the end of its boot sequence, the kernel tries to determine the format of the image from its first few blocks of data, which can lead either to the initrd or initramfs scheme. In the initrd scheme, the image may be a file system image (optionally compressed), which is made available in a special
block device In Unix-like operating systems, a device file, device node, or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These spec ...
() that is then mounted as the initial root file system. The driver for that file system must be compiled statically into the kernel. Many distributions originally used compressed
ext2 ext2, or second extended file system, is a file system for the Linux kernel (operating system), kernel. It was initially designed by French software developer Rémy Card as a replacement for the extended file system (ext). Having been designed ...
file system images, while the others (including
Debian Debian () is a free and open-source software, free and open source Linux distribution, developed by the Debian Project, which was established by Ian Murdock in August 1993. Debian is one of the oldest operating systems based on the Linux kerne ...
3.1) used cramfs in order to boot on memory-limited systems, since the cramfs image can be mounted in-place without requiring extra space for decompression. Once the initial root file system is up, the kernel executes as its first process; when it exits, the kernel assumes that the real root file system has been mounted and executes to begin the normal user-space boot process. In the initramfs scheme (available since the Linux kernel 2.6.13), the image may be a
cpio cpio is a general file archiver utility and its associated file format. It is primarily installed on Unix-like computer operating systems. The software utility was originally intended as a tape archiving program as part of the Programmer's Work ...
archive (optionally compressed) or a concatenation of such archives. The archive is unpacked by the kernel into a special instance of a tmpfs that becomes the initial root file system. This scheme has the advantage of not requiring an intermediate file system or block drivers to be compiled into the kernel. Some systems use the
dracut Dracut is a town in Middlesex County, Massachusetts, United States. At the 2020 census, the town's population was 32,617, making it the second most populous town in Massachusetts with an open town meeting system of governance. The town cove ...
package to create an initramfs image. In the initramfs scheme, the kernel executes as its first process that is not expected to exit. For some applications, initramfs can use the casper utility to create a writable environment using
unionfs Unionfs is a filesystem service for Linux, FreeBSD and NetBSD which implements a union mount for other file systems. It allows files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single cohe ...
to overlay a
persistence layer In computer science, persistence refers to the characteristic of state of a system that outlives (persists for longer than) the process that created it. This is achieved in practice by storing the state as data in computer data storage. Program ...
over a read-only root filesystem image. For example, overlay data can be stored on a
USB flash drive A flash drive (also thumb drive, memory stick, and pen drive/pendrive) is a data storage device that includes flash memory with an integrated USB interface. A typical USB drive is removable, rewritable, and smaller than an optical disc, and u ...
, while a compressed
SquashFS Squashfs is a compressed read-only file system for Linux. Squashfs compresses files, inodes and directories, and supports block sizes from 4 KiB up to 1 MiB for greater compression. Several compression algorithms are supported. Squashfs is ...
read-only image stored on a
live CD A live CD (also live DVD, live disc, or live operating system) is a complete booting, bootable computer installation including operating system which runs directly from a CD-ROM or similar storage device into a computer's memory, rather than lo ...
acts as a root filesystem. Depending on which algorithms were compiled statically into it, the kernel can unpack initrd/initramfs images compressed with
gzip gzip is a file format and a software application used for file compression and decompression. The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program used in early Unix systems, and ...
,
bzip2 bzip2 is a free and open-source file compression program that uses the Burrows–Wheeler algorithm. It only compresses single files and is not a file archiver. It relies on separate external utilities such as tar for tasks such as handli ...
, LZMA, XZ, LZO, LZ4, and zstd.


Mount preparations

Some Linux distributions such as
Debian Debian () is a free and open-source software, free and open source Linux distribution, developed by the Debian Project, which was established by Ian Murdock in August 1993. Debian is one of the oldest operating systems based on the Linux kerne ...
will generate a customized initrd image which contains only whatever is necessary to boot some particular computer, such as ATA,
SCSI Small Computer System Interface (SCSI, ) is a set of standards for physically connecting and transferring data between computers and peripheral devices, best known for its use with storage devices such as hard disk drives. SCSI was introduced ...
and filesystem kernel modules. These typically embed the location and type of the root file system. Other Linux distributions (such as
Fedora A fedora () is a hat with a soft brim and indented crown.Kilgour, Ruth Edwards (1958). ''A Pageant of Hats Ancient and Modern''. R. M. McBride Company. It is typically creased lengthwise down the crown and "pinched" near the front on both sides ...
and
Ubuntu Ubuntu ( ) is a Linux distribution based on Debian and composed primarily of free and open-source software. Developed by the British company Canonical (company), Canonical and a community of contributors under a Meritocracy, meritocratic gover ...
) generate a more generic initrd image. These start only with the device name of the root file system (or its
UUID A Universally Unique Identifier (UUID) is a 128-bit nominal number, label used to uniquely identify objects in computer systems. The term Globally Unique Identifier (GUID) is also used, mostly in Microsoft systems. When generated according to the ...
) and must discover everything else at boot time. In this case, the software must perform a complex cascade of tasks to get the root file system mounted: * Any hardware drivers that the boot process depends on must be loaded. A common arrangement is to pack kernel modules for common storage devices onto the initrd and then invoke a
hotplug Hot swapping is the replacement or addition of components to a computer system without stopping, shutting down, or rebooting the system. Hot plugging describes only the addition of components to a running computer system. Components which ha ...
agent to pull in modules matching the computer's detected hardware. * On systems which display a boot splash screen, the video hardware must be initialized and a user-space helper started to paint animations onto the display in lockstep with the boot process. * If the root file system is on NFS, it must then bring up the primary network interface, invoke a
DHCP The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used on Internet Protocol (IP) networks for automatically assigning IP addresses and other communication parameters to devices connected to the network using a clie ...
client, with which it can obtain a DHCP lease, extract the name of the NFS share and the address of the NFS server from the lease, and mount the NFS share. * If the root file system appears to be on a software RAID device, there is no way of knowing which devices the RAID volume spans; the standard MD utilities must be invoked to scan all available block devices and bring the required ones online. * If the root file system appears to be on a
logical volume In computer storage, logical volume management or LVM provides a method of allocating space on mass-storage devices that is more flexible than conventional partitioning schemes to store volumes. In particular, a volume manager can concatenate, ...
, the LVM utilities must be invoked to scan for and activate the volume group containing it. * If the root file system is on an encrypted block device, the software needs to invoke a helper script to prompt the user to type in a passphrase and/or insert a hardware token (such as a
smart card A smart card (SC), chip card, or integrated circuit card (ICC or IC card), is a card used to control access to a resource. It is typically a plastic credit card-sized card with an Embedded system, embedded integrated circuit (IC) chip. Many smart ...
or a USB security
dongle A dongle is a small piece of computer hardware that connects to a port on another device to provide it with additional functionality, or enable a pass-through to such a device that adds functionality. In computing, the term was initially synony ...
), and then create a decryption target with the
device mapper The device mapper is a framework provided by the Linux kernel for mapping physical block devices onto higher-level ''virtual block devices''. It forms the foundation of the logical volume manager (LVM), software RAIDs and dm-crypt disk encrypt ...
. Some distributions use an event-driven hotplug agent such as
udev udev (userspace ) is a device manager for the Linux kernel. As the successor of devfsd and hotplug, udev primarily manages device nodes in the directory. At the same time, udev also handles all user space events raised when hardware devices ...
, which invokes helper programs as hardware devices, disk partitions and storage volumes matching certain rules come online. This allows discovery to run in parallel, and to progressively cascade into arbitrary nestings of LVM, RAID or encryption to get at the root file system. When the root file system finally becomes visible, any maintenance tasks that cannot run on a mounted root file system are done, the root file system is mounted read-only, and any processes that must continue running (such as the splash screen helper and its command FIFO) are hoisted into the newly mounted root file system. The final root file system cannot simply be mounted over , since that would make the scripts and tools on the initial root file system inaccessible for any final cleanup tasks: * On an initrd, the new root is mounted at a temporary mount point and rotated into place wit
pivot_root(8)
(which was introduced specifically for this purpose). This leaves the initial root file system at a mount point (such as ) where normal boot scripts can later unmount it to free up memory held by the initrd. * On an initramfs, the initial root file system cannot be rotated away. Instead, it is simply emptied and the final root file system mounted over the top. Most initial root file systems implement or as a shell script and thus include a minimal shell (usually /bin/ash) along with some essential user-space utilities (usually the
BusyBox BusyBox is a software suite that provides several List of Unix commands, Unix utilities in a single executable file. It runs in a variety of POSIX environments such as Linux, Android (operating system), Android, and FreeBSD, although many of the ...
toolkit). To further save space, the shell, utilities and their supporting libraries are typically compiled with space optimizations enabled (such as with gcc's "-Os" flag) and linked against klibc, a minimal version of the
C library The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the origina ...
written specifically for this purpose.


Other uses

Installers for Linux distributions typically run entirely from an initramfs, as they must be able to host the installer interface and supporting tools before any persistent storage has been set up.
Tiny Core Linux Tiny Core Linux (TCL) is a minimal Linux kernel based operating system focusing on providing a base system using BusyBox and FLTK. It was developed by Robert Shingledecker, who was previously the lead developer of Damn Small Linux. The distribu ...
and
Puppy Linux Puppy Linux is a family of light-weight Linux distributions that focus on ease of use and minimal memory footprint. The entire system can be run from random-access memory (RAM) with current versions generally taking up about 600 MB (64-bit), 3 ...
can run entirely from initrd.


Similarities in other operating systems

Since Windows Vista, Windows can boot from a
WIM Wim is a Dutch masculine given name or a shortened form of Willem and may refer to: * Wim Anderiesen (1903–1944), Dutch footballer * Wim Aantjes (1923–2015), Dutch politician * Wim Arras (born 1964), Flemish Belgian cyclist * Wim Blockman ...
disk image file, for which the file format is published; it is similar to the ZIP format except that it supports hard links, deduplicated chunks, and uses chunk-by-chunk compression. In this case, the whole WIM is initially loaded into RAM, followed by the kernel initialisation. Next, the loaded WIM is available as a SystemRoot with an assigned drive letter. The Windows installer uses this so it boots from BOOT.WIM, and then uses INSTALL.WIM as the collection of the Windows files to be installed. Also,
Windows Preinstallation Environment Windows Preinstallation Environment (also known as Windows PE and WinPE) is a lightweight version of Windows used for the deployment of PCs, workstations, and servers, or troubleshooting an operating system while it is offline. It is intended t ...
(Windows PE) uses the same, being a base for separate-boot versions of some antivirus and backup/disaster recovery software. It is also possible to install Windows so that it will always boot from a WIM or VHD file placed on a physical drive. However, this is rarely used since the Windows boot loader is capable of loading the .sys files for boot-time kernel modules itself, which is the task that requires initrd in Linux.


See also

*
dracut Dracut is a town in Middlesex County, Massachusetts, United States. At the 2020 census, the town's population was 32,617, making it the second most populous town in Massachusetts with an open town meeting system of governance. The town cove ...

booster initramfs generator
*
Linux startup process The Linux booting process involves multiple stages and is in many ways similar to the BSD and other Unix-style boot processes, from which it derives. Although the Linux booting process depends very much on the computer architecture, those architect ...
*
List of Linux distributions that run from RAM This is a list of Linux distributions that can be run entirely from a computer's RAM, meaning that once the OS has been loaded to the RAM, the media it was loaded from can be completely removed, and the distribution will run the PC through th ...

EFI boot stub
(Arch Linux Wiki)


References


External links


Debian initramfs-tools

Detailed comparison
of initrd-generating toolkits

on early userspace support *

{{Linux kernel Booting Linux kernel