sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget6/translations/zh_CN/filesystems/ramfs-rootfs-initramfsmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget6/translations/zh_TW/filesystems/ramfs-rootfs-initramfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget6/translations/it_IT/filesystems/ramfs-rootfs-initramfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget6/translations/ja_JP/filesystems/ramfs-rootfs-initramfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget6/translations/ko_KR/filesystems/ramfs-rootfs-initramfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget6/translations/pt_BR/filesystems/ramfs-rootfs-initramfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget6/translations/sp_SP/filesystems/ramfs-rootfs-initramfsmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhP/var/lib/git/docbuild/linux/Documentation/filesystems/ramfs-rootfs-initramfs.rsthKubhsection)}(hhh](htitle)}(hRamfs, rootfs and initramfsh]hRamfs, rootfs and initramfs}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hOctober 17, 2005h]hOctober 17, 2005}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh field_list)}(hhh]hfield)}(hhh](h field_name)}(hAuthorh]hAuthor}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhKubh field_body)}(hRob Landley h]h)}(hRob Landley h](h Rob Landley <}(hj hhhNhNubh reference)}(hrob@landley.neth]hrob@landley.net}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:rob@landley.netuh1jhj ubh>}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hj ubah}(h]h ]h"]h$]h&]uh1jhhubeh}(h]h ]h"]h$]h&]uh1hhhhK hhhhubah}(h]h ]h"]h$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hWhat is ramfs?h]hWhat is ramfs?}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjChhhhhK ubh)}(hRamfs is a very simple filesystem that exports Linux's disk caching mechanisms (the page cache and dentry cache) as a dynamically resizable RAM-based filesystem.h]hRamfs is a very simple filesystem that exports Linux’s disk caching mechanisms (the page cache and dentry cache) as a dynamically resizable RAM-based filesystem.}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjChhubh)}(hXNormally all files are cached in memory by Linux. Pages of data read from backing store (usually the block device the filesystem is mounted on) are kept around in case it's needed again, but marked as clean (freeable) in case the Virtual Memory system needs the memory for something else. Similarly, data written to files is marked clean as soon as it has been written to backing store, but kept around for caching purposes until the VM reallocates the memory. A similar mechanism (the dentry cache) greatly speeds up access to directories.h]hX!Normally all files are cached in memory by Linux. Pages of data read from backing store (usually the block device the filesystem is mounted on) are kept around in case it’s needed again, but marked as clean (freeable) in case the Virtual Memory system needs the memory for something else. Similarly, data written to files is marked clean as soon as it has been written to backing store, but kept around for caching purposes until the VM reallocates the memory. A similar mechanism (the dentry cache) greatly speeds up access to directories.}(hjbhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjChhubh)}(hXWith ramfs, there is no backing store. Files written into ramfs allocate dentries and page cache as usual, but there's nowhere to write them to. This means the pages are never marked clean, so they can't be freed by the VM when it's looking to recycle memory.h]hX With ramfs, there is no backing store. Files written into ramfs allocate dentries and page cache as usual, but there’s nowhere to write them to. This means the pages are never marked clean, so they can’t be freed by the VM when it’s looking to recycle memory.}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjChhubh)}(hX<The amount of code required to implement ramfs is tiny, because all the work is done by the existing Linux caching infrastructure. Basically, you're mounting the disk cache as a filesystem. Because of this, ramfs is not an optional component removable via menuconfig, since there would be negligible space savings.h]hX>The amount of code required to implement ramfs is tiny, because all the work is done by the existing Linux caching infrastructure. Basically, you’re mounting the disk cache as a filesystem. Because of this, ramfs is not an optional component removable via menuconfig, since there would be negligible space savings.}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hjChhubeh}(h] what-is-ramfsah ]h"]what is ramfs?ah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hramfs and ramdisk:h]hramfs and ramdisk:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK'ubh)}(hXThe older "ram disk" mechanism created a synthetic block device out of an area of RAM and used it as backing store for a filesystem. This block device was of fixed size, so the filesystem mounted on it was of fixed size. Using a ram disk also required unnecessarily copying memory from the fake block device into the page cache (and copying changes back out), as well as creating and destroying dentries. Plus it needed a filesystem driver (such as ext2) to format and interpret this data.h]hXThe older “ram disk” mechanism created a synthetic block device out of an area of RAM and used it as backing store for a filesystem. This block device was of fixed size, so the filesystem mounted on it was of fixed size. Using a ram disk also required unnecessarily copying memory from the fake block device into the page cache (and copying changes back out), as well as creating and destroying dentries. Plus it needed a filesystem driver (such as ext2) to format and interpret this data.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hjhhubh)}(hXCompared to ramfs, this wastes memory (and memory bus bandwidth), creates unnecessary work for the CPU, and pollutes the CPU caches. (There are tricks to avoid this copying by playing with the page tables, but they're unpleasantly complicated and turn out to be about as expensive as the copying anyway.) More to the point, all the work ramfs is doing has to happen _anyway_, since all file access goes through the page and dentry caches. The RAM disk is simply unnecessary; ramfs is internally much simpler.h]hXCompared to ramfs, this wastes memory (and memory bus bandwidth), creates unnecessary work for the CPU, and pollutes the CPU caches. (There are tricks to avoid this copying by playing with the page tables, but they’re unpleasantly complicated and turn out to be about as expensive as the copying anyway.) More to the point, all the work ramfs is doing has to happen _anyway_, since all file access goes through the page and dentry caches. The RAM disk is simply unnecessary; ramfs is internally much simpler.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK1hjhhubh)}(hAnother reason ramdisks are semi-obsolete is that the introduction of loopback devices offered a more flexible and convenient way to create synthetic block devices, now from files instead of from chunks of memory. See losetup (8) for details.h]hAnother reason ramdisks are semi-obsolete is that the introduction of loopback devices offered a more flexible and convenient way to create synthetic block devices, now from files instead of from chunks of memory. See losetup (8) for details.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK9hjhhubeh}(h]ramfs-and-ramdiskah ]h"]ramfs and ramdisk:ah$]h&]uh1hhhhhhhhK'ubh)}(hhh](h)}(hramfs and tmpfs:h]hramfs and tmpfs:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK?ubh)}(hXYOne downside of ramfs is you can keep writing data into it until you fill up all memory, and the VM can't free it because the VM thinks that files should get written to backing store (rather than swap space), but ramfs hasn't got any backing store. Because of this, only root (or a trusted user) should be allowed write access to a ramfs mount.h]hX]One downside of ramfs is you can keep writing data into it until you fill up all memory, and the VM can’t free it because the VM thinks that files should get written to backing store (rather than swap space), but ramfs hasn’t got any backing store. Because of this, only root (or a trusted user) should be allowed write access to a ramfs mount.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKAhjhhubh)}(hA ramfs derivative called tmpfs was created to add size limits, and the ability to write the data to swap space. Normal users can be allowed write access to tmpfs mounts. See Documentation/filesystems/tmpfs.rst for more information.h]hA ramfs derivative called tmpfs was created to add size limits, and the ability to write the data to swap space. Normal users can be allowed write access to tmpfs mounts. See Documentation/filesystems/tmpfs.rst for more information.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKGhjhhubeh}(h]ramfs-and-tmpfsah ]h"]ramfs and tmpfs:ah$]h&]uh1hhhhhhhhK?ubh)}(hhh](h)}(hWhat is rootfs?h]hWhat is rootfs?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhKLubh)}(hXZRootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is always present in Linux systems. The kernel uses an immutable empty filesystem called nullfs as the true root of the VFS hierarchy, with the mutable rootfs (tmpfs/ramfs) mounted on top of it. This allows pivot_root() and unmounting of the initramfs to work normally.h]hX\Rootfs is a special instance of ramfs (or tmpfs, if that’s enabled), which is always present in Linux systems. The kernel uses an immutable empty filesystem called nullfs as the true root of the VFS hierarchy, with the mutable rootfs (tmpfs/ramfs) mounted on top of it. This allows pivot_root() and unmounting of the initramfs to work normally.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKNhj hhubh)}(hMost systems just mount another filesystem over rootfs and ignore it. The amount of space an empty instance of ramfs takes up is tiny.h]hMost systems just mount another filesystem over rootfs and ignore it. The amount of space an empty instance of ramfs takes up is tiny.}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThj hhubh)}(hIf CONFIG_TMPFS is enabled, rootfs will use tmpfs instead of ramfs by default. To force ramfs, add "rootfstype=ramfs" to the kernel command line.h]hIf CONFIG_TMPFS is enabled, rootfs will use tmpfs instead of ramfs by default. To force ramfs, add “rootfstype=ramfs” to the kernel command line.}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKWhj hhubeh}(h]what-is-rootfsah ]h"]what is rootfs?ah$]h&]uh1hhhhhhhhKLubh)}(hhh](h)}(hWhat is initramfs?h]hWhat is initramfs?}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjOhhhhhK\ubh)}(hXlAll 2.6 Linux kernels contain a gzipped "cpio" format archive, which is extracted into rootfs when the kernel boots up. After extracting, the kernel checks to see if rootfs contains a file "init", and if so it executes it as PID 1. If found, this init process is responsible for bringing the system the rest of the way up, including locating and mounting the real root device (if any). If rootfs does not contain an init program after the embedded cpio archive is extracted into it, the kernel will fall through to the older code to locate and mount a root partition, then exec some variant of /sbin/init out of that.h]hXtAll 2.6 Linux kernels contain a gzipped “cpio” format archive, which is extracted into rootfs when the kernel boots up. After extracting, the kernel checks to see if rootfs contains a file “init”, and if so it executes it as PID 1. If found, this init process is responsible for bringing the system the rest of the way up, including locating and mounting the real root device (if any). If rootfs does not contain an init program after the embedded cpio archive is extracted into it, the kernel will fall through to the older code to locate and mount a root partition, then exec some variant of /sbin/init out of that.}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK^hjOhhubh)}(h5All this differs from the old initrd in several ways:h]h5All this differs from the old initrd in several ways:}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhjOhhubh block_quote)}(hXH- The old initrd was always a separate file, while the initramfs archive is linked into the linux kernel image. (The directory ``linux-*/usr`` is devoted to generating this archive during the build.) - The old initrd file was a gzipped filesystem image (in some file format, such as ext2, that needed a driver built into the kernel), while the new initramfs archive is a gzipped cpio archive (like tar only simpler, see cpio(1) and Documentation/driver-api/early-userspace/buffer-format.rst). The kernel's cpio extraction code is not only extremely small, it's also __init text and data that can be discarded during the boot process. - The program run by the old initrd (which was called /initrd, not /init) did some setup and then returned to the kernel, while the init program from initramfs is not expected to return to the kernel. (If /init needs to hand off control it can overmount / with a new root device and exec another init program. See the switch_root utility, below.) - When switching another root device, initrd would pivot_root and then umount the ramdisk. With nullfs as the true root, pivot_root() works normally from the initramfs. Userspace can simply do:: chdir(new_root); pivot_root(".", "."); umount2(".", MNT_DETACH); This is the preferred method for switching root filesystems. h]h bullet_list)}(hhh](h list_item)}(hThe old initrd was always a separate file, while the initramfs archive is linked into the linux kernel image. (The directory ``linux-*/usr`` is devoted to generating this archive during the build.) h]h)}(hThe old initrd was always a separate file, while the initramfs archive is linked into the linux kernel image. (The directory ``linux-*/usr`` is devoted to generating this archive during the build.)h](h~The old initrd was always a separate file, while the initramfs archive is linked into the linux kernel image. (The directory }(hjhhhNhNubhliteral)}(h``linux-*/usr``h]h linux-*/usr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh9 is devoted to generating this archive during the build.)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKjhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hXThe old initrd file was a gzipped filesystem image (in some file format, such as ext2, that needed a driver built into the kernel), while the new initramfs archive is a gzipped cpio archive (like tar only simpler, see cpio(1) and Documentation/driver-api/early-userspace/buffer-format.rst). The kernel's cpio extraction code is not only extremely small, it's also __init text and data that can be discarded during the boot process. h]h)}(hXThe old initrd file was a gzipped filesystem image (in some file format, such as ext2, that needed a driver built into the kernel), while the new initramfs archive is a gzipped cpio archive (like tar only simpler, see cpio(1) and Documentation/driver-api/early-userspace/buffer-format.rst). The kernel's cpio extraction code is not only extremely small, it's also __init text and data that can be discarded during the boot process.h]hXThe old initrd file was a gzipped filesystem image (in some file format, such as ext2, that needed a driver built into the kernel), while the new initramfs archive is a gzipped cpio archive (like tar only simpler, see cpio(1) and Documentation/driver-api/early-userspace/buffer-format.rst). The kernel’s cpio extraction code is not only extremely small, it’s also __init text and data that can be discarded during the boot process.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKnhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hX[The program run by the old initrd (which was called /initrd, not /init) did some setup and then returned to the kernel, while the init program from initramfs is not expected to return to the kernel. (If /init needs to hand off control it can overmount / with a new root device and exec another init program. See the switch_root utility, below.) h]h)}(hXZThe program run by the old initrd (which was called /initrd, not /init) did some setup and then returned to the kernel, while the init program from initramfs is not expected to return to the kernel. (If /init needs to hand off control it can overmount / with a new root device and exec another init program. See the switch_root utility, below.)h]hXZThe program run by the old initrd (which was called /initrd, not /init) did some setup and then returned to the kernel, while the init program from initramfs is not expected to return to the kernel. (If /init needs to hand off control it can overmount / with a new root device and exec another init program. See the switch_root utility, below.)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hXIWhen switching another root device, initrd would pivot_root and then umount the ramdisk. With nullfs as the true root, pivot_root() works normally from the initramfs. Userspace can simply do:: chdir(new_root); pivot_root(".", "."); umount2(".", MNT_DETACH); This is the preferred method for switching root filesystems. h](h)}(hWhen switching another root device, initrd would pivot_root and then umount the ramdisk. With nullfs as the true root, pivot_root() works normally from the initramfs. Userspace can simply do::h]hWhen switching another root device, initrd would pivot_root and then umount the ramdisk. With nullfs as the true root, pivot_root() works normally from the initramfs. Userspace can simply do:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK{hjubh literal_block)}(h@chdir(new_root); pivot_root(".", "."); umount2(".", MNT_DETACH);h]h@chdir(new_root); pivot_root(".", "."); umount2(".", MNT_DETACH);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjubh)}(h and TimeSys Corporation. # Licensed under GPL version 2 if [ $# -ne 2 ] then echo "usage: mkinitramfs directory imagename.cpio.gz" exit 1 fi if [ -d "$1" ] then echo "creating $2 from $1" (cd "$1"; find . | cpio -o -H newc | gzip) > "$2" else echo "First argument must be a directory" exit 1 fih]hXn#!/bin/sh # Copyright 2006 Rob Landley and TimeSys Corporation. # Licensed under GPL version 2 if [ $# -ne 2 ] then echo "usage: mkinitramfs directory imagename.cpio.gz" exit 1 fi if [ -d "$1" ] then echo "creating $2 from $1" (cd "$1"; find . | cpio -o -H newc | gzip) > "$2" else echo "First argument must be a directory" exit 1 fi}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhj1hhubhnote)}(hXWThe cpio man page contains some bad advice that will break your initramfs archive if you follow it. It says "A typical way to generate the list of filenames is with the find command; you should give find the -depth option to minimize problems with permissions on directories that are unwritable or not searchable." Don't do this when creating initramfs.cpio.gz images, it won't work. The Linux kernel cpio extractor won't create files in a directory that doesn't exist, so the directory entries must go before the files that go in those directories. The above script gets them in the right order.h]h)}(hXWThe cpio man page contains some bad advice that will break your initramfs archive if you follow it. It says "A typical way to generate the list of filenames is with the find command; you should give find the -depth option to minimize problems with permissions on directories that are unwritable or not searchable." Don't do this when creating initramfs.cpio.gz images, it won't work. The Linux kernel cpio extractor won't create files in a directory that doesn't exist, so the directory entries must go before the files that go in those directories. The above script gets them in the right order.h]hXcThe cpio man page contains some bad advice that will break your initramfs archive if you follow it. It says “A typical way to generate the list of filenames is with the find command; you should give find the -depth option to minimize problems with permissions on directories that are unwritable or not searchable.” Don’t do this when creating initramfs.cpio.gz images, it won’t work. The Linux kernel cpio extractor won’t create files in a directory that doesn’t exist, so the directory entries must go before the files that go in those directories. The above script gets them in the right order.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj1hhhhhNubeh}(h]populating-initramfsah ]h"]populating initramfs:ah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hExternal initramfs images:h]hExternal initramfs images:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXIf the kernel has initrd support enabled, an external cpio.gz archive can also be passed into a 2.6 kernel in place of an initrd. In this case, the kernel will autodetect the type (initramfs, not initrd) and extract the external cpio archive into rootfs before trying to run /init.h]hXIf the kernel has initrd support enabled, an external cpio.gz archive can also be passed into a 2.6 kernel in place of an initrd. In this case, the kernel will autodetect the type (initramfs, not initrd) and extract the external cpio archive into rootfs before trying to run /init.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXThis has the memory efficiency advantages of initramfs (no ramdisk block device) but the separate packaging of initrd (which is nice if you have non-GPL code you'd like to run from initramfs, without conflating it with the GPL licensed Linux kernel binary).h]hXThis has the memory efficiency advantages of initramfs (no ramdisk block device) but the separate packaging of initrd (which is nice if you have non-GPL code you’d like to run from initramfs, without conflating it with the GPL licensed Linux kernel binary).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hX/It can also be used to supplement the kernel's built-in initramfs image. The files in the external archive will overwrite any conflicting files in the built-in initramfs archive. Some distributors also prefer to customize a single kernel image with task-specific initramfs images, without recompiling.h]hX1It can also be used to supplement the kernel’s built-in initramfs image. The files in the external archive will overwrite any conflicting files in the built-in initramfs archive. Some distributors also prefer to customize a single kernel image with task-specific initramfs images, without recompiling.}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]external-initramfs-imagesah ]h"]external initramfs images:ah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hContents of initramfs:h]hContents of initramfs:}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjAhhhhhKubh)}(hAn initramfs archive is a complete self-contained root filesystem for Linux. If you don't already understand what shared libraries, devices, and paths you need to get a minimal root filesystem up and running, here are some references:h]hAn initramfs archive is a complete self-contained root filesystem for Linux. If you don’t already understand what shared libraries, devices, and paths you need to get a minimal root filesystem up and running, here are some references:}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjAhhubj)}(hhh](j)}(h*https://www.tldp.org/HOWTO/Bootdisk-HOWTO/h]h)}(hjeh]j)}(hjeh]h*https://www.tldp.org/HOWTO/Bootdisk-HOWTO/}(hjjhhhNhNubah}(h]h ]h"]h$]h&]refurijeuh1jhjgubah}(h]h ]h"]h$]h&]uh1hhhhKhjcubah}(h]h ]h"]h$]h&]uh1jhj`hhhhhNubj)}(hAhttps://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.htmlh]h)}(hjh]j)}(hjh]hAhttps://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj`hhhhhNubj)}(h1http://www.linuxfromscratch.org/lfs/view/stable/ h]h)}(h0http://www.linuxfromscratch.org/lfs/view/stable/h]j)}(hjh]h0http://www.linuxfromscratch.org/lfs/view/stable/}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj`hhhhhNubeh}(h]h ]h"]h$]h&]j!j"uh1jhhhKhjAhhubh)}(hThe "klibc" package (https://www.kernel.org/pub/linux/libs/klibc) is designed to be a tiny C library to statically link early userspace code against, along with some related utilities. It is BSD licensed.h](hThe “klibc” package (}(hjhhhNhNubj)}(h+https://www.kernel.org/pub/linux/libs/klibch]h+https://www.kernel.org/pub/linux/libs/klibc}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubh) is designed to be a tiny C library to statically link early userspace code against, along with some related utilities. It is BSD licensed.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjAhhubh)}(hI use uClibc (https://www.uclibc.org) and busybox (https://www.busybox.net) myself. These are LGPL and GPL, respectively. (A self-contained initramfs package is planned for the busybox 1.3 release.)h](hI use uClibc (}(hjhhhNhNubj)}(hhttps://www.uclibc.orgh]hhttps://www.uclibc.org}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubh) and busybox (}(hjhhhNhNubj)}(hhttps://www.busybox.neth]hhttps://www.busybox.net}(hj hhhNhNubah}(h]h ]h"]h$]h&]refurij uh1jhjubh~) myself. These are LGPL and GPL, respectively. (A self-contained initramfs package is planned for the busybox 1.3 release.)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjAhhubh)}(hXIn theory you could use glibc, but that's not well suited for small embedded uses like this. (A "hello world" program statically linked against glibc is over 400k. With uClibc it's 7k. Also note that glibc dlopens libnss to do name lookups, even when otherwise statically linked.)h]hX#In theory you could use glibc, but that’s not well suited for small embedded uses like this. (A “hello world” program statically linked against glibc is over 400k. With uClibc it’s 7k. Also note that glibc dlopens libnss to do name lookups, even when otherwise statically linked.)}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjAhhubh)}(hA good first step is to get initramfs to run a statically linked "hello world" program as init, and test it under an emulator like qemu (www.qemu.org) or User Mode Linux, like so::h]hA good first step is to get initramfs to run a statically linked “hello world” program as init, and test it under an emulator like qemu (www.qemu.org) or User Mode Linux, like so:}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjAhhubj)}(hX^cat > hello.c << EOF #include #include int main(int argc, char *argv[]) { printf("Hello world!\n"); sleep(999999999); } EOF gcc -static hello.c -o init echo init | cpio -o -H newc | gzip > test.cpio.gz # Testing external initramfs using the initrd loading mechanism. qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zeroh]hX^cat > hello.c << EOF #include #include int main(int argc, char *argv[]) { printf("Hello world!\n"); sleep(999999999); } EOF gcc -static hello.c -o init echo init | cpio -o -H newc | gzip > test.cpio.gz # Testing external initramfs using the initrd loading mechanism. qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero}hj>sbah}(h]h ]h"]h$]h&]hhuh1jhhhM hjAhhubh)}(hWhen debugging a normal root filesystem, it's nice to be able to boot with "init=/bin/sh". The initramfs equivalent is "rdinit=/bin/sh", and it's just as useful.h]hWhen debugging a normal root filesystem, it’s nice to be able to boot with “init=/bin/sh”. The initramfs equivalent is “rdinit=/bin/sh”, and it’s just as useful.}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjAhhubeh}(h]contents-of-initramfsah ]h"]contents of initramfs:ah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hWhy cpio rather than tar?h]hWhy cpio rather than tar?}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhjbhhhhhMubh)}(hLThis decision was made back in December, 2001. The discussion started here:h]hLThis decision was made back in December, 2001. The discussion started here:}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM!hjbhhubj)}(hhh]j)}(h@https://lore.kernel.org/lkml/a03cke$640$1@cesium.transmeta.com/ h]h)}(h?https://lore.kernel.org/lkml/a03cke$640$1@cesium.transmeta.com/h]j)}(hjh]h?https://lore.kernel.org/lkml/a03cke$640$1@cesium.transmeta.com/}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhM#hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubah}(h]h ]h"]h$]h&]j!j"uh1jhhhM#hjbhhubh)}(hIAnd spawned a second thread (specifically on tar vs cpio), starting here:h]hIAnd spawned a second thread (specifically on tar vs cpio), starting here:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM%hjbhhubj)}(hhh]j)}(h9https://lore.kernel.org/lkml/3C25A06D.7030408@zytor.com/ h]h)}(h8https://lore.kernel.org/lkml/3C25A06D.7030408@zytor.com/h]j)}(hjh]h8https://lore.kernel.org/lkml/3C25A06D.7030408@zytor.com/}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhM'hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubah}(h]h ]h"]h$]h&]j!j"uh1jhhhM'hjbhhubh)}(h^The quick and dirty summary version (which is no substitute for reading the above threads) is:h]h^The quick and dirty summary version (which is no substitute for reading the above threads) is:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM)hjbhhubhenumerated_list)}(hhh](j)}(hXcpio is a standard. It's decades old (from the AT&T days), and already widely used on Linux (inside RPM, Red Hat's device driver disks). Here's a Linux Journal article about it from 1996: http://www.linuxjournal.com/article/1213 It's not as popular as tar because the traditional cpio command line tools require _truly_hideous_ command line arguments. But that says nothing either way about the archive format, and there are alternative tools, such as: https://linux.die.net/man/1/afio h](h)}(hcpio is a standard. It's decades old (from the AT&T days), and already widely used on Linux (inside RPM, Red Hat's device driver disks). Here's a Linux Journal article about it from 1996:h]hcpio is a standard. It’s decades old (from the AT&T days), and already widely used on Linux (inside RPM, Red Hat’s device driver disks). Here’s a Linux Journal article about it from 1996:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM,hjubj})}(h)http://www.linuxjournal.com/article/1213 h]h)}(h(http://www.linuxjournal.com/article/1213h]j)}(hjh]h(http://www.linuxjournal.com/article/1213}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhM0hj ubah}(h]h ]h"]h$]h&]uh1j|hhhM0hjubh)}(hIt's not as popular as tar because the traditional cpio command line tools require _truly_hideous_ command line arguments. But that says nothing either way about the archive format, and there are alternative tools, such as:h]hIt’s not as popular as tar because the traditional cpio command line tools require _truly_hideous_ command line arguments. But that says nothing either way about the archive format, and there are alternative tools, such as:}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM2hjubj})}(h!https://linux.die.net/man/1/afio h]h)}(h https://linux.die.net/man/1/afioh]j)}(hj@h]h https://linux.die.net/man/1/afio}(hjBhhhNhNubah}(h]h ]h"]h$]h&]refurij@uh1jhj>ubah}(h]h ]h"]h$]h&]uh1hhhhM7hj:ubah}(h]h ]h"]h$]h&]uh1j|hhhM7hjubeh}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hXThe cpio archive format chosen by the kernel is simpler and cleaner (and thus easier to create and parse) than any of the (literally dozens of) various tar archive formats. The complete initramfs archive format is explained in buffer-format.rst, created in usr/gen_init_cpio.c, and extracted in init/initramfs.c. All three together come to less than 26k total of human-readable text. h]h)}(hXThe cpio archive format chosen by the kernel is simpler and cleaner (and thus easier to create and parse) than any of the (literally dozens of) various tar archive formats. The complete initramfs archive format is explained in buffer-format.rst, created in usr/gen_init_cpio.c, and extracted in init/initramfs.c. All three together come to less than 26k total of human-readable text.h]hXThe cpio archive format chosen by the kernel is simpler and cleaner (and thus easier to create and parse) than any of the (literally dozens of) various tar archive formats. The complete initramfs archive format is explained in buffer-format.rst, created in usr/gen_init_cpio.c, and extracted in init/initramfs.c. All three together come to less than 26k total of human-readable text.}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM9hjbubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hThe GNU project standardizing on tar is approximately as relevant as Windows standardizing on zip. Linux is not part of either, and is free to make its own technical decisions. h]h)}(hThe GNU project standardizing on tar is approximately as relevant as Windows standardizing on zip. Linux is not part of either, and is free to make its own technical decisions.h]hThe GNU project standardizing on tar is approximately as relevant as Windows standardizing on zip. Linux is not part of either, and is free to make its own technical decisions.}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM@hjzubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hSince this is a kernel internal format, it could easily have been something brand new. The kernel provides its own tools to create and extract this format anyway. Using an existing standard was preferable, but not essential. h]h)}(hSince this is a kernel internal format, it could easily have been something brand new. The kernel provides its own tools to create and extract this format anyway. Using an existing standard was preferable, but not essential.h]hSince this is a kernel internal format, it could easily have been something brand new. The kernel provides its own tools to create and extract this format anyway. Using an existing standard was preferable, but not essential.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMDhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hXAl Viro made the decision (quote: "tar is ugly as hell and not going to be supported on the kernel side"): - https://lore.kernel.org/lkml/Pine.GSO.4.21.0112222109050.21702-100000@weyl.math.psu.edu/ explained his reasoning: - https://lore.kernel.org/lkml/Pine.GSO.4.21.0112222240530.21702-100000@weyl.math.psu.edu/ - https://lore.kernel.org/lkml/Pine.GSO.4.21.0112230849550.23300-100000@weyl.math.psu.edu/ and, most importantly, designed and implemented the initramfs code. h](h)}(hjAl Viro made the decision (quote: "tar is ugly as hell and not going to be supported on the kernel side"):h]hnAl Viro made the decision (quote: “tar is ugly as hell and not going to be supported on the kernel side”):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMIhjubj})}(h[- https://lore.kernel.org/lkml/Pine.GSO.4.21.0112222109050.21702-100000@weyl.math.psu.edu/ h]j)}(hhh]j)}(hYhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112222109050.21702-100000@weyl.math.psu.edu/ h]h)}(hXhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112222109050.21702-100000@weyl.math.psu.edu/h]j)}(hjh]hXhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112222109050.21702-100000@weyl.math.psu.edu/}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhMLhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]j!j"uh1jhhhMLhjubah}(h]h ]h"]h$]h&]uh1j|hhhMLhjubh)}(hexplained his reasoning:h]hexplained his reasoning:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMNhjubj})}(h- https://lore.kernel.org/lkml/Pine.GSO.4.21.0112222240530.21702-100000@weyl.math.psu.edu/ - https://lore.kernel.org/lkml/Pine.GSO.4.21.0112230849550.23300-100000@weyl.math.psu.edu/ h]j)}(hhh](j)}(hXhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112222240530.21702-100000@weyl.math.psu.edu/h]h)}(hjh]j)}(hjh]hXhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112222240530.21702-100000@weyl.math.psu.edu/}(hj hhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhj ubah}(h]h ]h"]h$]h&]uh1hhhhMPhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hYhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112230849550.23300-100000@weyl.math.psu.edu/ h]h)}(hXhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112230849550.23300-100000@weyl.math.psu.edu/h]j)}(hj-h]hXhttps://lore.kernel.org/lkml/Pine.GSO.4.21.0112230849550.23300-100000@weyl.math.psu.edu/}(hj/hhhNhNubah}(h]h ]h"]h$]h&]refurij-uh1jhj+ubah}(h]h ]h"]h$]h&]uh1hhhhMQhj'ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]j!j"uh1jhhhMPhjubah}(h]h ]h"]h$]h&]uh1j|hhhMPhjubh)}(hCand, most importantly, designed and implemented the initramfs code.h]hCand, most importantly, designed and implemented the initramfs code.}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMShjubeh}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix)uh1jhjbhhhhhM,ubeh}(h]why-cpio-rather-than-tarah ]h"]why cpio rather than tar?ah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hFuture directions:h]hFuture directions:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj|hhhhhMVubh)}(hXVToday (2.6.16), initramfs is always compiled in, but not always used. The kernel falls back to legacy boot code that is reached only if initramfs does not contain an /init program. The fallback is legacy code, there to ensure a smooth transition and allowing early boot functionality to gradually move to "early userspace" (I.E. initramfs).h]hXZToday (2.6.16), initramfs is always compiled in, but not always used. The kernel falls back to legacy boot code that is reached only if initramfs does not contain an /init program. The fallback is legacy code, there to ensure a smooth transition and allowing early boot functionality to gradually move to “early userspace” (I.E. initramfs).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMXhj|hhubh)}(hX#The move to early userspace is necessary because finding and mounting the real root device is complex. Root partitions can span multiple devices (raid or separate journal). They can be out on the network (requiring dhcp, setting a specific MAC address, logging into a server, etc). They can live on removable media, with dynamically allocated major/minor numbers and persistent naming issues requiring a full udev implementation to sort out. They can be compressed, encrypted, copy-on-write, loopback mounted, strangely partitioned, and so on.h]hX#The move to early userspace is necessary because finding and mounting the real root device is complex. Root partitions can span multiple devices (raid or separate journal). They can be out on the network (requiring dhcp, setting a specific MAC address, logging into a server, etc). They can live on removable media, with dynamically allocated major/minor numbers and persistent naming issues requiring a full udev implementation to sort out. They can be compressed, encrypted, copy-on-write, loopback mounted, strangely partitioned, and so on.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hj|hhubh)}(hThis kind of complexity (which inevitably includes policy) is rightly handled in userspace. Both klibc and busybox/uClibc are working on simple initramfs packages to drop into a kernel build.h]hThis kind of complexity (which inevitably includes policy) is rightly handled in userspace. Both klibc and busybox/uClibc are working on simple initramfs packages to drop into a kernel build.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMghj|hhubh)}(hThe klibc package has now been accepted into Andrew Morton's 2.6.17-mm tree. The kernel's current early boot code (partition detection, etc) will probably be migrated into a default initramfs, automatically created and used by the kernel build.h]hThe klibc package has now been accepted into Andrew Morton’s 2.6.17-mm tree. The kernel’s current early boot code (partition detection, etc) will probably be migrated into a default initramfs, automatically created and used by the kernel build.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMkhj|hhubeh}(h]future-directionsah ]h"]future directions:ah$]h&]uh1hhhhhhhhMVubeh}(h]ramfs-rootfs-and-initramfsah ]h"]ramfs, rootfs and initramfsah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehnj _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jjjjjjj jjLjIj.j+jjj>j;j_j\jyjvjju nametypes}(jjjj jLj.jj>j_jyjuh}(jhjjCjjjjjIj j+jOjj1j;jj\jAjvjbjj|u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.