ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / Documentation / early-userspace / README
1 Early userspace support
2 =======================
3
4 Last update: 2003-08-21
5
6
7 "Early userspace" is a set of libraries and programs that provide
8 various pieces of functionality that are important enough to be
9 available while a Linux kernel is coming up, but that don't need to be
10 run inside the kernel itself.
11
12 It consists of several major infrastructure components:
13
14 - gen_init_cpio, a program that builds a cpio-format archive
15   containing a root filesystem image.  This archive is compressed, and
16   the compressed image is linked into the kernel image.
17 - initramfs, a chunk of code that unpacks the compressed cpio image
18   midway through the kernel boot process.
19 - klibc, a userspace C library, currently packaged separately, that is
20   optimised for correctness and small size.
21
22 The cpio file format used by initramfs is the "newc" (aka "cpio -c")
23 format, and is documented in the file "buffer-format.txt".  If you
24 want to generate your own cpio files directly instead of hacking on
25 gen_init_cpio, you will need to short-circuit the build process in
26 usr/ so that gen_init_cpio does not get run, then simply pop your own
27 initramfs_data.cpio.gz file into place.
28
29
30 Where's this all leading?
31 =========================
32
33 The klibc distribution contains some of the necessary software to make
34 early userspace useful.  The klibc distribution is currently
35 maintained separately from the kernel, but this may change early in
36 the 2.7 era (it missed the boat for 2.5).
37
38 You can obtain somewhat infrequent snapshots of klibc from
39 ftp://ftp.kernel.org/pub/linux/libs/klibc/
40
41 For active users, you are better off using the klibc BitKeeper
42 repositories, at http://klibc.bkbits.net/
43
44 The standalone klibc distribution currently provides three components,
45 in addition to the klibc library:
46
47 - ipconfig, a program that configures network interfaces.  It can
48   configure them statically, or use DHCP to obtain information
49   dynamically (aka "IP autoconfiguration").
50 - nfsmount, a program that can mount an NFS filesystem.
51 - kinit, the "glue" that uses ipconfig and nfsmount to replace the old
52   support for IP autoconfig, mount a filesystem over NFS, and continue
53   system boot using that filesystem as root.
54
55 kinit is built as a single statically linked binary to save space.
56
57 Eventually, several more chunks of kernel functionality will hopefully
58 move to early userspace:
59
60 - Almost all of init/do_mounts* (the beginning of this is already in
61   place)
62 - ACPI table parsing
63 - Insert unwieldy subsystem that doesn't really need to be in kernel
64   space here
65
66 If kinit doesn't meet your current needs and you've got bytes to burn,
67 the klibc distribution includes a small Bourne-compatible shell (ash)
68 and a number of other utilities, so you can replace kinit and build
69 custom initramfs images that meet your needs exactly.
70
71 For questions and help, you can sign up for the early userspace
72 mailing list at http://www.zytor.com/mailman/listinfo/klibc
73
74 How does it work?
75 =================
76
77 The kernel has currently 3 ways to mount the root filesystem:
78
79 a) all required device and filesystem drivers compiled into the kernel, no
80    initrd.  init/main.c:init() will call prepare_namespace() to mount the
81    final root filesystem, based on the root= option and optional init= to run
82    some other init binary than listed at the end of init/main.c:init().
83
84 b) some device and filesystem drivers built as modules and stored in an
85    initrd.  The initrd must contain a binary '/linuxrc' which is supposed to
86    load these driver modules.  It is also possible to mount the final root
87    filesystem via linuxrc and use the pivot_root syscall.  The initrd is
88    mounted and executed via prepare_namespace().
89
90 c) using initramfs.  The call to prepare_namespace() must be skipped.
91    This means that a binary must do all the work.  Said binary can be stored
92    into initramfs either via modifying usr/gen_init_cpio.c or via the new
93    initrd format, an cpio archive.  It must be called "/init".  This binary
94    is responsible to do all the things prepare_namespace() would do.
95
96    To remain backwards compatibility, the /init binary will only run if it
97    comes via an initramfs cpio archive.  If this is not the case,
98    init/main.c:init() will run prepare_namespace() to mount the final root
99    and exec one of the predefined init binaries.
100
101 Bryan O'Sullivan <bos@serpentine.com>