1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun=========================== 4*4882a593SmuzhiyunRamfs, rootfs and initramfs 5*4882a593Smuzhiyun=========================== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunOctober 17, 2005 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunRob Landley <rob@landley.net> 10*4882a593Smuzhiyun============================= 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunWhat is ramfs? 13*4882a593Smuzhiyun-------------- 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunRamfs is a very simple filesystem that exports Linux's disk caching 16*4882a593Smuzhiyunmechanisms (the page cache and dentry cache) as a dynamically resizable 17*4882a593SmuzhiyunRAM-based filesystem. 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunNormally all files are cached in memory by Linux. Pages of data read from 20*4882a593Smuzhiyunbacking store (usually the block device the filesystem is mounted on) are kept 21*4882a593Smuzhiyunaround in case it's needed again, but marked as clean (freeable) in case the 22*4882a593SmuzhiyunVirtual Memory system needs the memory for something else. Similarly, data 23*4882a593Smuzhiyunwritten to files is marked clean as soon as it has been written to backing 24*4882a593Smuzhiyunstore, but kept around for caching purposes until the VM reallocates the 25*4882a593Smuzhiyunmemory. A similar mechanism (the dentry cache) greatly speeds up access to 26*4882a593Smuzhiyundirectories. 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunWith ramfs, there is no backing store. Files written into ramfs allocate 29*4882a593Smuzhiyundentries and page cache as usual, but there's nowhere to write them to. 30*4882a593SmuzhiyunThis means the pages are never marked clean, so they can't be freed by the 31*4882a593SmuzhiyunVM when it's looking to recycle memory. 32*4882a593Smuzhiyun 33*4882a593SmuzhiyunThe amount of code required to implement ramfs is tiny, because all the 34*4882a593Smuzhiyunwork is done by the existing Linux caching infrastructure. Basically, 35*4882a593Smuzhiyunyou're mounting the disk cache as a filesystem. Because of this, ramfs is not 36*4882a593Smuzhiyunan optional component removable via menuconfig, since there would be negligible 37*4882a593Smuzhiyunspace savings. 38*4882a593Smuzhiyun 39*4882a593Smuzhiyunramfs and ramdisk: 40*4882a593Smuzhiyun------------------ 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunThe older "ram disk" mechanism created a synthetic block device out of 43*4882a593Smuzhiyunan area of RAM and used it as backing store for a filesystem. This block 44*4882a593Smuzhiyundevice was of fixed size, so the filesystem mounted on it was of fixed 45*4882a593Smuzhiyunsize. Using a ram disk also required unnecessarily copying memory from the 46*4882a593Smuzhiyunfake block device into the page cache (and copying changes back out), as well 47*4882a593Smuzhiyunas creating and destroying dentries. Plus it needed a filesystem driver 48*4882a593Smuzhiyun(such as ext2) to format and interpret this data. 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunCompared to ramfs, this wastes memory (and memory bus bandwidth), creates 51*4882a593Smuzhiyununnecessary work for the CPU, and pollutes the CPU caches. (There are tricks 52*4882a593Smuzhiyunto avoid this copying by playing with the page tables, but they're unpleasantly 53*4882a593Smuzhiyuncomplicated and turn out to be about as expensive as the copying anyway.) 54*4882a593SmuzhiyunMore to the point, all the work ramfs is doing has to happen _anyway_, 55*4882a593Smuzhiyunsince all file access goes through the page and dentry caches. The RAM 56*4882a593Smuzhiyundisk is simply unnecessary; ramfs is internally much simpler. 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunAnother reason ramdisks are semi-obsolete is that the introduction of 59*4882a593Smuzhiyunloopback devices offered a more flexible and convenient way to create 60*4882a593Smuzhiyunsynthetic block devices, now from files instead of from chunks of memory. 61*4882a593SmuzhiyunSee losetup (8) for details. 62*4882a593Smuzhiyun 63*4882a593Smuzhiyunramfs and tmpfs: 64*4882a593Smuzhiyun---------------- 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunOne downside of ramfs is you can keep writing data into it until you fill 67*4882a593Smuzhiyunup all memory, and the VM can't free it because the VM thinks that files 68*4882a593Smuzhiyunshould get written to backing store (rather than swap space), but ramfs hasn't 69*4882a593Smuzhiyungot any backing store. Because of this, only root (or a trusted user) should 70*4882a593Smuzhiyunbe allowed write access to a ramfs mount. 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunA ramfs derivative called tmpfs was created to add size limits, and the ability 73*4882a593Smuzhiyunto write the data to swap space. Normal users can be allowed write access to 74*4882a593Smuzhiyuntmpfs mounts. See Documentation/filesystems/tmpfs.rst for more information. 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunWhat is rootfs? 77*4882a593Smuzhiyun--------------- 78*4882a593Smuzhiyun 79*4882a593SmuzhiyunRootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is 80*4882a593Smuzhiyunalways present in 2.6 systems. You can't unmount rootfs for approximately the 81*4882a593Smuzhiyunsame reason you can't kill the init process; rather than having special code 82*4882a593Smuzhiyunto check for and handle an empty list, it's smaller and simpler for the kernel 83*4882a593Smuzhiyunto just make sure certain lists can't become empty. 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunMost systems just mount another filesystem over rootfs and ignore it. The 86*4882a593Smuzhiyunamount of space an empty instance of ramfs takes up is tiny. 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunIf CONFIG_TMPFS is enabled, rootfs will use tmpfs instead of ramfs by 89*4882a593Smuzhiyundefault. To force ramfs, add "rootfstype=ramfs" to the kernel command 90*4882a593Smuzhiyunline. 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunWhat is initramfs? 93*4882a593Smuzhiyun------------------ 94*4882a593Smuzhiyun 95*4882a593SmuzhiyunAll 2.6 Linux kernels contain a gzipped "cpio" format archive, which is 96*4882a593Smuzhiyunextracted into rootfs when the kernel boots up. After extracting, the kernel 97*4882a593Smuzhiyunchecks to see if rootfs contains a file "init", and if so it executes it as PID 98*4882a593Smuzhiyun1. If found, this init process is responsible for bringing the system the 99*4882a593Smuzhiyunrest of the way up, including locating and mounting the real root device (if 100*4882a593Smuzhiyunany). If rootfs does not contain an init program after the embedded cpio 101*4882a593Smuzhiyunarchive is extracted into it, the kernel will fall through to the older code 102*4882a593Smuzhiyunto locate and mount a root partition, then exec some variant of /sbin/init 103*4882a593Smuzhiyunout of that. 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunAll this differs from the old initrd in several ways: 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun - The old initrd was always a separate file, while the initramfs archive is 108*4882a593Smuzhiyun linked into the linux kernel image. (The directory ``linux-*/usr`` is 109*4882a593Smuzhiyun devoted to generating this archive during the build.) 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun - The old initrd file was a gzipped filesystem image (in some file format, 112*4882a593Smuzhiyun such as ext2, that needed a driver built into the kernel), while the new 113*4882a593Smuzhiyun initramfs archive is a gzipped cpio archive (like tar only simpler, 114*4882a593Smuzhiyun see cpio(1) and Documentation/driver-api/early-userspace/buffer-format.rst). 115*4882a593Smuzhiyun The kernel's cpio extraction code is not only extremely small, it's also 116*4882a593Smuzhiyun __init text and data that can be discarded during the boot process. 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun - The program run by the old initrd (which was called /initrd, not /init) did 119*4882a593Smuzhiyun some setup and then returned to the kernel, while the init program from 120*4882a593Smuzhiyun initramfs is not expected to return to the kernel. (If /init needs to hand 121*4882a593Smuzhiyun off control it can overmount / with a new root device and exec another init 122*4882a593Smuzhiyun program. See the switch_root utility, below.) 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun - When switching another root device, initrd would pivot_root and then 125*4882a593Smuzhiyun umount the ramdisk. But initramfs is rootfs: you can neither pivot_root 126*4882a593Smuzhiyun rootfs, nor unmount it. Instead delete everything out of rootfs to 127*4882a593Smuzhiyun free up the space (find -xdev / -exec rm '{}' ';'), overmount rootfs 128*4882a593Smuzhiyun with the new root (cd /newmount; mount --move . /; chroot .), attach 129*4882a593Smuzhiyun stdin/stdout/stderr to the new /dev/console, and exec the new init. 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun Since this is a remarkably persnickety process (and involves deleting 132*4882a593Smuzhiyun commands before you can run them), the klibc package introduced a helper 133*4882a593Smuzhiyun program (utils/run_init.c) to do all this for you. Most other packages 134*4882a593Smuzhiyun (such as busybox) have named this command "switch_root". 135*4882a593Smuzhiyun 136*4882a593SmuzhiyunPopulating initramfs: 137*4882a593Smuzhiyun--------------------- 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunThe 2.6 kernel build process always creates a gzipped cpio format initramfs 140*4882a593Smuzhiyunarchive and links it into the resulting kernel binary. By default, this 141*4882a593Smuzhiyunarchive is empty (consuming 134 bytes on x86). 142*4882a593Smuzhiyun 143*4882a593SmuzhiyunThe config option CONFIG_INITRAMFS_SOURCE (in General Setup in menuconfig, 144*4882a593Smuzhiyunand living in usr/Kconfig) can be used to specify a source for the 145*4882a593Smuzhiyuninitramfs archive, which will automatically be incorporated into the 146*4882a593Smuzhiyunresulting binary. This option can point to an existing gzipped cpio 147*4882a593Smuzhiyunarchive, a directory containing files to be archived, or a text file 148*4882a593Smuzhiyunspecification such as the following example:: 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun dir /dev 755 0 0 151*4882a593Smuzhiyun nod /dev/console 644 0 0 c 5 1 152*4882a593Smuzhiyun nod /dev/loop0 644 0 0 b 7 0 153*4882a593Smuzhiyun dir /bin 755 1000 1000 154*4882a593Smuzhiyun slink /bin/sh busybox 777 0 0 155*4882a593Smuzhiyun file /bin/busybox initramfs/busybox 755 0 0 156*4882a593Smuzhiyun dir /proc 755 0 0 157*4882a593Smuzhiyun dir /sys 755 0 0 158*4882a593Smuzhiyun dir /mnt 755 0 0 159*4882a593Smuzhiyun file /init initramfs/init.sh 755 0 0 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunRun "usr/gen_init_cpio" (after the kernel build) to get a usage message 162*4882a593Smuzhiyundocumenting the above file format. 163*4882a593Smuzhiyun 164*4882a593SmuzhiyunOne advantage of the configuration file is that root access is not required to 165*4882a593Smuzhiyunset permissions or create device nodes in the new archive. (Note that those 166*4882a593Smuzhiyuntwo example "file" entries expect to find files named "init.sh" and "busybox" in 167*4882a593Smuzhiyuna directory called "initramfs", under the linux-2.6.* directory. See 168*4882a593SmuzhiyunDocumentation/driver-api/early-userspace/early_userspace_support.rst for more details.) 169*4882a593Smuzhiyun 170*4882a593SmuzhiyunThe kernel does not depend on external cpio tools. If you specify a 171*4882a593Smuzhiyundirectory instead of a configuration file, the kernel's build infrastructure 172*4882a593Smuzhiyuncreates a configuration file from that directory (usr/Makefile calls 173*4882a593Smuzhiyunusr/gen_initramfs.sh), and proceeds to package up that directory 174*4882a593Smuzhiyunusing the config file (by feeding it to usr/gen_init_cpio, which is created 175*4882a593Smuzhiyunfrom usr/gen_init_cpio.c). The kernel's build-time cpio creation code is 176*4882a593Smuzhiyunentirely self-contained, and the kernel's boot-time extractor is also 177*4882a593Smuzhiyun(obviously) self-contained. 178*4882a593Smuzhiyun 179*4882a593SmuzhiyunThe one thing you might need external cpio utilities installed for is creating 180*4882a593Smuzhiyunor extracting your own preprepared cpio files to feed to the kernel build 181*4882a593Smuzhiyun(instead of a config file or directory). 182*4882a593Smuzhiyun 183*4882a593SmuzhiyunThe following command line can extract a cpio image (either by the above script 184*4882a593Smuzhiyunor by the kernel build) back into its component files:: 185*4882a593Smuzhiyun 186*4882a593Smuzhiyun cpio -i -d -H newc -F initramfs_data.cpio --no-absolute-filenames 187*4882a593Smuzhiyun 188*4882a593SmuzhiyunThe following shell script can create a prebuilt cpio archive you can 189*4882a593Smuzhiyunuse in place of the above config file:: 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun #!/bin/sh 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun # Copyright 2006 Rob Landley <rob@landley.net> and TimeSys Corporation. 194*4882a593Smuzhiyun # Licensed under GPL version 2 195*4882a593Smuzhiyun 196*4882a593Smuzhiyun if [ $# -ne 2 ] 197*4882a593Smuzhiyun then 198*4882a593Smuzhiyun echo "usage: mkinitramfs directory imagename.cpio.gz" 199*4882a593Smuzhiyun exit 1 200*4882a593Smuzhiyun fi 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun if [ -d "$1" ] 203*4882a593Smuzhiyun then 204*4882a593Smuzhiyun echo "creating $2 from $1" 205*4882a593Smuzhiyun (cd "$1"; find . | cpio -o -H newc | gzip) > "$2" 206*4882a593Smuzhiyun else 207*4882a593Smuzhiyun echo "First argument must be a directory" 208*4882a593Smuzhiyun exit 1 209*4882a593Smuzhiyun fi 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun.. Note:: 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun The cpio man page contains some bad advice that will break your initramfs 214*4882a593Smuzhiyun archive if you follow it. It says "A typical way to generate the list 215*4882a593Smuzhiyun of filenames is with the find command; you should give find the -depth 216*4882a593Smuzhiyun option to minimize problems with permissions on directories that are 217*4882a593Smuzhiyun unwritable or not searchable." Don't do this when creating 218*4882a593Smuzhiyun initramfs.cpio.gz images, it won't work. The Linux kernel cpio extractor 219*4882a593Smuzhiyun won't create files in a directory that doesn't exist, so the directory 220*4882a593Smuzhiyun entries must go before the files that go in those directories. 221*4882a593Smuzhiyun The above script gets them in the right order. 222*4882a593Smuzhiyun 223*4882a593SmuzhiyunExternal initramfs images: 224*4882a593Smuzhiyun-------------------------- 225*4882a593Smuzhiyun 226*4882a593SmuzhiyunIf the kernel has initrd support enabled, an external cpio.gz archive can also 227*4882a593Smuzhiyunbe passed into a 2.6 kernel in place of an initrd. In this case, the kernel 228*4882a593Smuzhiyunwill autodetect the type (initramfs, not initrd) and extract the external cpio 229*4882a593Smuzhiyunarchive into rootfs before trying to run /init. 230*4882a593Smuzhiyun 231*4882a593SmuzhiyunThis has the memory efficiency advantages of initramfs (no ramdisk block 232*4882a593Smuzhiyundevice) but the separate packaging of initrd (which is nice if you have 233*4882a593Smuzhiyunnon-GPL code you'd like to run from initramfs, without conflating it with 234*4882a593Smuzhiyunthe GPL licensed Linux kernel binary). 235*4882a593Smuzhiyun 236*4882a593SmuzhiyunIt can also be used to supplement the kernel's built-in initramfs image. The 237*4882a593Smuzhiyunfiles in the external archive will overwrite any conflicting files in 238*4882a593Smuzhiyunthe built-in initramfs archive. Some distributors also prefer to customize 239*4882a593Smuzhiyuna single kernel image with task-specific initramfs images, without recompiling. 240*4882a593Smuzhiyun 241*4882a593SmuzhiyunContents of initramfs: 242*4882a593Smuzhiyun---------------------- 243*4882a593Smuzhiyun 244*4882a593SmuzhiyunAn initramfs archive is a complete self-contained root filesystem for Linux. 245*4882a593SmuzhiyunIf you don't already understand what shared libraries, devices, and paths 246*4882a593Smuzhiyunyou need to get a minimal root filesystem up and running, here are some 247*4882a593Smuzhiyunreferences: 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun- https://www.tldp.org/HOWTO/Bootdisk-HOWTO/ 250*4882a593Smuzhiyun- https://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html 251*4882a593Smuzhiyun- http://www.linuxfromscratch.org/lfs/view/stable/ 252*4882a593Smuzhiyun 253*4882a593SmuzhiyunThe "klibc" package (https://www.kernel.org/pub/linux/libs/klibc) is 254*4882a593Smuzhiyundesigned to be a tiny C library to statically link early userspace 255*4882a593Smuzhiyuncode against, along with some related utilities. It is BSD licensed. 256*4882a593Smuzhiyun 257*4882a593SmuzhiyunI use uClibc (https://www.uclibc.org) and busybox (https://www.busybox.net) 258*4882a593Smuzhiyunmyself. These are LGPL and GPL, respectively. (A self-contained initramfs 259*4882a593Smuzhiyunpackage is planned for the busybox 1.3 release.) 260*4882a593Smuzhiyun 261*4882a593SmuzhiyunIn theory you could use glibc, but that's not well suited for small embedded 262*4882a593Smuzhiyunuses like this. (A "hello world" program statically linked against glibc is 263*4882a593Smuzhiyunover 400k. With uClibc it's 7k. Also note that glibc dlopens libnss to do 264*4882a593Smuzhiyunname lookups, even when otherwise statically linked.) 265*4882a593Smuzhiyun 266*4882a593SmuzhiyunA good first step is to get initramfs to run a statically linked "hello world" 267*4882a593Smuzhiyunprogram as init, and test it under an emulator like qemu (www.qemu.org) or 268*4882a593SmuzhiyunUser Mode Linux, like so:: 269*4882a593Smuzhiyun 270*4882a593Smuzhiyun cat > hello.c << EOF 271*4882a593Smuzhiyun #include <stdio.h> 272*4882a593Smuzhiyun #include <unistd.h> 273*4882a593Smuzhiyun 274*4882a593Smuzhiyun int main(int argc, char *argv[]) 275*4882a593Smuzhiyun { 276*4882a593Smuzhiyun printf("Hello world!\n"); 277*4882a593Smuzhiyun sleep(999999999); 278*4882a593Smuzhiyun } 279*4882a593Smuzhiyun EOF 280*4882a593Smuzhiyun gcc -static hello.c -o init 281*4882a593Smuzhiyun echo init | cpio -o -H newc | gzip > test.cpio.gz 282*4882a593Smuzhiyun # Testing external initramfs using the initrd loading mechanism. 283*4882a593Smuzhiyun qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero 284*4882a593Smuzhiyun 285*4882a593SmuzhiyunWhen debugging a normal root filesystem, it's nice to be able to boot with 286*4882a593Smuzhiyun"init=/bin/sh". The initramfs equivalent is "rdinit=/bin/sh", and it's 287*4882a593Smuzhiyunjust as useful. 288*4882a593Smuzhiyun 289*4882a593SmuzhiyunWhy cpio rather than tar? 290*4882a593Smuzhiyun------------------------- 291*4882a593Smuzhiyun 292*4882a593SmuzhiyunThis decision was made back in December, 2001. The discussion started here: 293*4882a593Smuzhiyun 294*4882a593Smuzhiyun http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1538.html 295*4882a593Smuzhiyun 296*4882a593SmuzhiyunAnd spawned a second thread (specifically on tar vs cpio), starting here: 297*4882a593Smuzhiyun 298*4882a593Smuzhiyun http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1587.html 299*4882a593Smuzhiyun 300*4882a593SmuzhiyunThe quick and dirty summary version (which is no substitute for reading 301*4882a593Smuzhiyunthe above threads) is: 302*4882a593Smuzhiyun 303*4882a593Smuzhiyun1) cpio is a standard. It's decades old (from the AT&T days), and already 304*4882a593Smuzhiyun widely used on Linux (inside RPM, Red Hat's device driver disks). Here's 305*4882a593Smuzhiyun a Linux Journal article about it from 1996: 306*4882a593Smuzhiyun 307*4882a593Smuzhiyun http://www.linuxjournal.com/article/1213 308*4882a593Smuzhiyun 309*4882a593Smuzhiyun It's not as popular as tar because the traditional cpio command line tools 310*4882a593Smuzhiyun require _truly_hideous_ command line arguments. But that says nothing 311*4882a593Smuzhiyun either way about the archive format, and there are alternative tools, 312*4882a593Smuzhiyun such as: 313*4882a593Smuzhiyun 314*4882a593Smuzhiyun http://freecode.com/projects/afio 315*4882a593Smuzhiyun 316*4882a593Smuzhiyun2) The cpio archive format chosen by the kernel is simpler and cleaner (and 317*4882a593Smuzhiyun thus easier to create and parse) than any of the (literally dozens of) 318*4882a593Smuzhiyun various tar archive formats. The complete initramfs archive format is 319*4882a593Smuzhiyun explained in buffer-format.txt, created in usr/gen_init_cpio.c, and 320*4882a593Smuzhiyun extracted in init/initramfs.c. All three together come to less than 26k 321*4882a593Smuzhiyun total of human-readable text. 322*4882a593Smuzhiyun 323*4882a593Smuzhiyun3) The GNU project standardizing on tar is approximately as relevant as 324*4882a593Smuzhiyun Windows standardizing on zip. Linux is not part of either, and is free 325*4882a593Smuzhiyun to make its own technical decisions. 326*4882a593Smuzhiyun 327*4882a593Smuzhiyun4) Since this is a kernel internal format, it could easily have been 328*4882a593Smuzhiyun something brand new. The kernel provides its own tools to create and 329*4882a593Smuzhiyun extract this format anyway. Using an existing standard was preferable, 330*4882a593Smuzhiyun but not essential. 331*4882a593Smuzhiyun 332*4882a593Smuzhiyun5) Al Viro made the decision (quote: "tar is ugly as hell and not going to be 333*4882a593Smuzhiyun supported on the kernel side"): 334*4882a593Smuzhiyun 335*4882a593Smuzhiyun http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1540.html 336*4882a593Smuzhiyun 337*4882a593Smuzhiyun explained his reasoning: 338*4882a593Smuzhiyun 339*4882a593Smuzhiyun - http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1550.html 340*4882a593Smuzhiyun - http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1638.html 341*4882a593Smuzhiyun 342*4882a593Smuzhiyun and, most importantly, designed and implemented the initramfs code. 343*4882a593Smuzhiyun 344*4882a593SmuzhiyunFuture directions: 345*4882a593Smuzhiyun------------------ 346*4882a593Smuzhiyun 347*4882a593SmuzhiyunToday (2.6.16), initramfs is always compiled in, but not always used. The 348*4882a593Smuzhiyunkernel falls back to legacy boot code that is reached only if initramfs does 349*4882a593Smuzhiyunnot contain an /init program. The fallback is legacy code, there to ensure a 350*4882a593Smuzhiyunsmooth transition and allowing early boot functionality to gradually move to 351*4882a593Smuzhiyun"early userspace" (I.E. initramfs). 352*4882a593Smuzhiyun 353*4882a593SmuzhiyunThe move to early userspace is necessary because finding and mounting the real 354*4882a593Smuzhiyunroot device is complex. Root partitions can span multiple devices (raid or 355*4882a593Smuzhiyunseparate journal). They can be out on the network (requiring dhcp, setting a 356*4882a593Smuzhiyunspecific MAC address, logging into a server, etc). They can live on removable 357*4882a593Smuzhiyunmedia, with dynamically allocated major/minor numbers and persistent naming 358*4882a593Smuzhiyunissues requiring a full udev implementation to sort out. They can be 359*4882a593Smuzhiyuncompressed, encrypted, copy-on-write, loopback mounted, strangely partitioned, 360*4882a593Smuzhiyunand so on. 361*4882a593Smuzhiyun 362*4882a593SmuzhiyunThis kind of complexity (which inevitably includes policy) is rightly handled 363*4882a593Smuzhiyunin userspace. Both klibc and busybox/uClibc are working on simple initramfs 364*4882a593Smuzhiyunpackages to drop into a kernel build. 365*4882a593Smuzhiyun 366*4882a593SmuzhiyunThe klibc package has now been accepted into Andrew Morton's 2.6.17-mm tree. 367*4882a593SmuzhiyunThe kernel's current early boot code (partition detection, etc) will probably 368*4882a593Smuzhiyunbe migrated into a default initramfs, automatically created and used by the 369*4882a593Smuzhiyunkernel build. 370