diff options
Diffstat (limited to 'Documentation/early-userspace')
-rw-r--r-- | Documentation/early-userspace/README | 152 | ||||
-rw-r--r-- | Documentation/early-userspace/buffer-format.txt | 112 |
2 files changed, 264 insertions, 0 deletions
diff --git a/Documentation/early-userspace/README b/Documentation/early-userspace/README new file mode 100644 index 000000000000..270a88e22fb9 --- /dev/null +++ b/Documentation/early-userspace/README | |||
@@ -0,0 +1,152 @@ | |||
1 | Early userspace support | ||
2 | ======================= | ||
3 | |||
4 | Last update: 2004-12-20 tlh | ||
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 | optimized 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". There are | ||
24 | two ways to add an early userspace image: specify an existing cpio | ||
25 | archive to be used as the image or have the kernel build process build | ||
26 | the image from specifications. | ||
27 | |||
28 | CPIO ARCHIVE method | ||
29 | |||
30 | You can create a cpio archive that contains the early userspace image. | ||
31 | Youre cpio archive should be specified in CONFIG_INITRAMFS_SOURCE and it | ||
32 | will be used directly. Only a single cpio file may be specified in | ||
33 | CONFIG_INITRAMFS_SOURCE and directory and file names are not allowed in | ||
34 | combination with a cpio archive. | ||
35 | |||
36 | IMAGE BUILDING method | ||
37 | |||
38 | The kernel build process can also build an early userspace image from | ||
39 | source parts rather than supplying a cpio archive. This method provides | ||
40 | a way to create images with root-owned files even though the image was | ||
41 | built by an unprivileged user. | ||
42 | |||
43 | The image is specified as one or more sources in | ||
44 | CONFIG_INITRAMFS_SOURCE. Sources can be either directories or files - | ||
45 | cpio archives are *not* allowed when building from sources. | ||
46 | |||
47 | A source directory will have it and all of it's contents packaged. The | ||
48 | specified directory name will be mapped to '/'. When packaging a | ||
49 | directory, limited user and group ID translation can be performed. | ||
50 | INITRAMFS_ROOT_UID can be set to a user ID that needs to be mapped to | ||
51 | user root (0). INITRAMFS_ROOT_GID can be set to a group ID that needs | ||
52 | to be mapped to group root (0). | ||
53 | |||
54 | A source file must be directives in the format required by the | ||
55 | usr/gen_init_cpio utility (run 'usr/gen_init_cpio --help' to get the | ||
56 | file format). The directives in the file will be passed directly to | ||
57 | usr/gen_init_cpio. | ||
58 | |||
59 | When a combination of directories and files are specified then the | ||
60 | initramfs image will be an aggregate of all of them. In this way a user | ||
61 | can create a 'root-image' directory and install all files into it. | ||
62 | Because device-special files cannot be created by a unprivileged user, | ||
63 | special files can be listed in a 'root-files' file. Both 'root-image' | ||
64 | and 'root-files' can be listed in CONFIG_INITRAMFS_SOURCE and a complete | ||
65 | early userspace image can be built by an unprivileged user. | ||
66 | |||
67 | As a technical note, when directories and files are specified, the | ||
68 | entire CONFIG_INITRAMFS_SOURCE is passed to | ||
69 | scripts/gen_initramfs_list.sh. This means that CONFIG_INITRAMFS_SOURCE | ||
70 | can really be interpreted as any legal argument to | ||
71 | gen_initramfs_list.sh. If a directory is specified as an argument then | ||
72 | the contents are scanned, uid/gid translation is performed, and | ||
73 | usr/gen_init_cpio file directives are output. If a directory is | ||
74 | specified as an arugemnt to scripts/gen_initramfs_list.sh then the | ||
75 | contents of the file are simply copied to the output. All of the output | ||
76 | directives from directory scanning and file contents copying are | ||
77 | processed by usr/gen_init_cpio. | ||
78 | |||
79 | See also 'scripts/gen_initramfs_list.sh -h'. | ||
80 | |||
81 | Where's this all leading? | ||
82 | ========================= | ||
83 | |||
84 | The klibc distribution contains some of the necessary software to make | ||
85 | early userspace useful. The klibc distribution is currently | ||
86 | maintained separately from the kernel, but this may change early in | ||
87 | the 2.7 era (it missed the boat for 2.5). | ||
88 | |||
89 | You can obtain somewhat infrequent snapshots of klibc from | ||
90 | ftp://ftp.kernel.org/pub/linux/libs/klibc/ | ||
91 | |||
92 | For active users, you are better off using the klibc BitKeeper | ||
93 | repositories, at http://klibc.bkbits.net/ | ||
94 | |||
95 | The standalone klibc distribution currently provides three components, | ||
96 | in addition to the klibc library: | ||
97 | |||
98 | - ipconfig, a program that configures network interfaces. It can | ||
99 | configure them statically, or use DHCP to obtain information | ||
100 | dynamically (aka "IP autoconfiguration"). | ||
101 | - nfsmount, a program that can mount an NFS filesystem. | ||
102 | - kinit, the "glue" that uses ipconfig and nfsmount to replace the old | ||
103 | support for IP autoconfig, mount a filesystem over NFS, and continue | ||
104 | system boot using that filesystem as root. | ||
105 | |||
106 | kinit is built as a single statically linked binary to save space. | ||
107 | |||
108 | Eventually, several more chunks of kernel functionality will hopefully | ||
109 | move to early userspace: | ||
110 | |||
111 | - Almost all of init/do_mounts* (the beginning of this is already in | ||
112 | place) | ||
113 | - ACPI table parsing | ||
114 | - Insert unwieldy subsystem that doesn't really need to be in kernel | ||
115 | space here | ||
116 | |||
117 | If kinit doesn't meet your current needs and you've got bytes to burn, | ||
118 | the klibc distribution includes a small Bourne-compatible shell (ash) | ||
119 | and a number of other utilities, so you can replace kinit and build | ||
120 | custom initramfs images that meet your needs exactly. | ||
121 | |||
122 | For questions and help, you can sign up for the early userspace | ||
123 | mailing list at http://www.zytor.com/mailman/listinfo/klibc | ||
124 | |||
125 | How does it work? | ||
126 | ================= | ||
127 | |||
128 | The kernel has currently 3 ways to mount the root filesystem: | ||
129 | |||
130 | a) all required device and filesystem drivers compiled into the kernel, no | ||
131 | initrd. init/main.c:init() will call prepare_namespace() to mount the | ||
132 | final root filesystem, based on the root= option and optional init= to run | ||
133 | some other init binary than listed at the end of init/main.c:init(). | ||
134 | |||
135 | b) some device and filesystem drivers built as modules and stored in an | ||
136 | initrd. The initrd must contain a binary '/linuxrc' which is supposed to | ||
137 | load these driver modules. It is also possible to mount the final root | ||
138 | filesystem via linuxrc and use the pivot_root syscall. The initrd is | ||
139 | mounted and executed via prepare_namespace(). | ||
140 | |||
141 | c) using initramfs. The call to prepare_namespace() must be skipped. | ||
142 | This means that a binary must do all the work. Said binary can be stored | ||
143 | into initramfs either via modifying usr/gen_init_cpio.c or via the new | ||
144 | initrd format, an cpio archive. It must be called "/init". This binary | ||
145 | is responsible to do all the things prepare_namespace() would do. | ||
146 | |||
147 | To remain backwards compatibility, the /init binary will only run if it | ||
148 | comes via an initramfs cpio archive. If this is not the case, | ||
149 | init/main.c:init() will run prepare_namespace() to mount the final root | ||
150 | and exec one of the predefined init binaries. | ||
151 | |||
152 | Bryan O'Sullivan <bos@serpentine.com> | ||
diff --git a/Documentation/early-userspace/buffer-format.txt b/Documentation/early-userspace/buffer-format.txt new file mode 100644 index 000000000000..e1fd7f9dad16 --- /dev/null +++ b/Documentation/early-userspace/buffer-format.txt | |||
@@ -0,0 +1,112 @@ | |||
1 | initramfs buffer format | ||
2 | ----------------------- | ||
3 | |||
4 | Al Viro, H. Peter Anvin | ||
5 | Last revision: 2002-01-13 | ||
6 | |||
7 | Starting with kernel 2.5.x, the old "initial ramdisk" protocol is | ||
8 | getting {replaced/complemented} with the new "initial ramfs" | ||
9 | (initramfs) protocol. The initramfs contents is passed using the same | ||
10 | memory buffer protocol used by the initrd protocol, but the contents | ||
11 | is different. The initramfs buffer contains an archive which is | ||
12 | expanded into a ramfs filesystem; this document details the format of | ||
13 | the initramfs buffer format. | ||
14 | |||
15 | The initramfs buffer format is based around the "newc" or "crc" CPIO | ||
16 | formats, and can be created with the cpio(1) utility. The cpio | ||
17 | archive can be compressed using gzip(1). One valid version of an | ||
18 | initramfs buffer is thus a single .cpio.gz file. | ||
19 | |||
20 | The full format of the initramfs buffer is defined by the following | ||
21 | grammar, where: | ||
22 | * is used to indicate "0 or more occurrences of" | ||
23 | (|) indicates alternatives | ||
24 | + indicates concatenation | ||
25 | GZIP() indicates the gzip(1) of the operand | ||
26 | ALGN(n) means padding with null bytes to an n-byte boundary | ||
27 | |||
28 | initramfs := ("\0" | cpio_archive | cpio_gzip_archive)* | ||
29 | |||
30 | cpio_gzip_archive := GZIP(cpio_archive) | ||
31 | |||
32 | cpio_archive := cpio_file* + (<nothing> | cpio_trailer) | ||
33 | |||
34 | cpio_file := ALGN(4) + cpio_header + filename + "\0" + ALGN(4) + data | ||
35 | |||
36 | cpio_trailer := ALGN(4) + cpio_header + "TRAILER!!!\0" + ALGN(4) | ||
37 | |||
38 | |||
39 | In human terms, the initramfs buffer contains a collection of | ||
40 | compressed and/or uncompressed cpio archives (in the "newc" or "crc" | ||
41 | formats); arbitrary amounts zero bytes (for padding) can be added | ||
42 | between members. | ||
43 | |||
44 | The cpio "TRAILER!!!" entry (cpio end-of-archive) is optional, but is | ||
45 | not ignored; see "handling of hard links" below. | ||
46 | |||
47 | The structure of the cpio_header is as follows (all fields contain | ||
48 | hexadecimal ASCII numbers fully padded with '0' on the left to the | ||
49 | full width of the field, for example, the integer 4780 is represented | ||
50 | by the ASCII string "000012ac"): | ||
51 | |||
52 | Field name Field size Meaning | ||
53 | c_magic 6 bytes The string "070701" or "070702" | ||
54 | c_ino 8 bytes File inode number | ||
55 | c_mode 8 bytes File mode and permissions | ||
56 | c_uid 8 bytes File uid | ||
57 | c_gid 8 bytes File gid | ||
58 | c_nlink 8 bytes Number of links | ||
59 | c_mtime 8 bytes Modification time | ||
60 | c_filesize 8 bytes Size of data field | ||
61 | c_maj 8 bytes Major part of file device number | ||
62 | c_min 8 bytes Minor part of file device number | ||
63 | c_rmaj 8 bytes Major part of device node reference | ||
64 | c_rmin 8 bytes Minor part of device node reference | ||
65 | c_namesize 8 bytes Length of filename, including final \0 | ||
66 | c_chksum 8 bytes Checksum of data field if c_magic is 070702; | ||
67 | otherwise zero | ||
68 | |||
69 | The c_mode field matches the contents of st_mode returned by stat(2) | ||
70 | on Linux, and encodes the file type and file permissions. | ||
71 | |||
72 | The c_filesize should be zero for any file which is not a regular file | ||
73 | or symlink. | ||
74 | |||
75 | The c_chksum field contains a simple 32-bit unsigned sum of all the | ||
76 | bytes in the data field. cpio(1) refers to this as "crc", which is | ||
77 | clearly incorrect (a cyclic redundancy check is a different and | ||
78 | significantly stronger integrity check), however, this is the | ||
79 | algorithm used. | ||
80 | |||
81 | If the filename is "TRAILER!!!" this is actually an end-of-archive | ||
82 | marker; the c_filesize for an end-of-archive marker must be zero. | ||
83 | |||
84 | |||
85 | *** Handling of hard links | ||
86 | |||
87 | When a nondirectory with c_nlink > 1 is seen, the (c_maj,c_min,c_ino) | ||
88 | tuple is looked up in a tuple buffer. If not found, it is entered in | ||
89 | the tuple buffer and the entry is created as usual; if found, a hard | ||
90 | link rather than a second copy of the file is created. It is not | ||
91 | necessary (but permitted) to include a second copy of the file | ||
92 | contents; if the file contents is not included, the c_filesize field | ||
93 | should be set to zero to indicate no data section follows. If data is | ||
94 | present, the previous instance of the file is overwritten; this allows | ||
95 | the data-carrying instance of a file to occur anywhere in the sequence | ||
96 | (GNU cpio is reported to attach the data to the last instance of a | ||
97 | file only.) | ||
98 | |||
99 | c_filesize must not be zero for a symlink. | ||
100 | |||
101 | When a "TRAILER!!!" end-of-archive marker is seen, the tuple buffer is | ||
102 | reset. This permits archives which are generated independently to be | ||
103 | concatenated. | ||
104 | |||
105 | To combine file data from different sources (without having to | ||
106 | regenerate the (c_maj,c_min,c_ino) fields), therefore, either one of | ||
107 | the following techniques can be used: | ||
108 | |||
109 | a) Separate the different file data sources with a "TRAILER!!!" | ||
110 | end-of-archive marker, or | ||
111 | |||
112 | b) Make sure c_nlink == 1 for all nondirectory entries. | ||