Gentoo Archives: gentoo-doc-cvs

From: "Sven Vermeulen (swift)" <swift@g.o>
To: gentoo-doc-cvs@l.g.o
Subject: [gentoo-doc-cvs] gentoo commit in xml/htdocs/doc/en: initramfs-guide.xml metadoc.xml
Date: Thu, 05 Apr 2012 21:02:38
Message-Id: 20120405194055.EDE402004B@flycatcher.gentoo.org
1 swift 12/04/05 19:40:55
2
3 Modified: metadoc.xml
4 Added: initramfs-guide.xml
5 Log:
6 Fix bug #408971 - Add an initramfs-guide
7
8 Revision Changes Path
9 1.238 xml/htdocs/doc/en/metadoc.xml
10
11 file : http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/doc/en/metadoc.xml?rev=1.238&view=markup
12 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/doc/en/metadoc.xml?rev=1.238&content-type=text/plain
13 diff : http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/doc/en/metadoc.xml?r1=1.237&r2=1.238
14
15 Index: metadoc.xml
16 ===================================================================
17 RCS file: /var/cvsroot/gentoo/xml/htdocs/doc/en/metadoc.xml,v
18 retrieving revision 1.237
19 retrieving revision 1.238
20 diff -u -r1.237 -r1.238
21 --- metadoc.xml 15 Jan 2012 15:54:44 -0000 1.237
22 +++ metadoc.xml 5 Apr 2012 19:40:55 -0000 1.238
23 @@ -1,8 +1,8 @@
24 <?xml version="1.0" encoding="UTF-8"?>
25 <!DOCTYPE metadoc SYSTEM "/dtd/metadoc.dtd">
26 -<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/metadoc.xml,v 1.237 2012/01/15 15:54:44 swift Exp $ -->
27 +<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/metadoc.xml,v 1.238 2012/04/05 19:40:55 swift Exp $ -->
28 <metadoc lang="en">
29 - <version>1.159</version>
30 + <version>1.160</version>
31 <members>
32 <lead>nightmorph</lead>
33 <member>cam</member>
34 @@ -357,6 +357,7 @@
35 <file id="conky">/doc/en/conky-howto.xml</file>
36 <file id="man-guide">/doc/en/man-guide.xml</file>
37 <file id="info-guide">/doc/en/info-guide.xml</file>
38 + <file id="initramfs-guide">/doc/en/initramfs-guide.xml</file>
39 <file id="java-upgrade">/proj/en/java/java-upgrade.xml</file>
40 <file id="kernel-config">/doc/en/kernel-config.xml</file>
41 <file id="zsh">/doc/en/zsh.xml</file>
42 @@ -1093,6 +1094,9 @@
43 <doc fileid="info-guide">
44 <memberof>sysadmin_general</memberof>
45 </doc>
46 + <doc fileid="initramfs-guide">
47 + <memberof>sysadmin_general</memberof>
48 + </doc>
49 <doc fileid="java-upgrade">
50 <memberof>upgrade</memberof>
51 </doc>
52
53
54
55 1.1 xml/htdocs/doc/en/initramfs-guide.xml
56
57 file : http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/doc/en/initramfs-guide.xml?rev=1.1&view=markup
58 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/xml/htdocs/doc/en/initramfs-guide.xml?rev=1.1&content-type=text/plain
59
60 Index: initramfs-guide.xml
61 ===================================================================
62 <?xml version='1.0' encoding="UTF-8"?>
63 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/initramfs-guide.xml,v 1.1 2012/04/05 19:40:55 swift Exp $ -->
64
65 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
66
67 <guide>
68 <title>Gentoo Linux Initial RAM File System Guide</title>
69
70 <author title="Author">
71 <mail link="swift@g.o">Sven Vermeulen</mail>
72 </author>
73
74 <abstract>
75 More and more systems require an initramfs to boot up properly. In this guide,
76 we tackle the concepts of the initramfs as well as how to properly create and
77 manage initramfs instances.
78 </abstract>
79
80 <!-- The content of this document is licensed under the CC-BY-SA license -->
81 <!-- See http://creativecommons.org/licenses/by-sa/3.0 -->
82 <license/>
83
84 <version>1</version>
85 <date>2012-03-31</date>
86
87 <chapter>
88 <title>Initramfs concepts</title>
89 <section>
90 <title>Introduction</title>
91 <body>
92
93 <p>
94 For many users, an initramfs system is of no concern. Their system uses a simple
95 partitioning schema with no exotic drivers or setups (like encrypted file
96 systems), so the Linux kernel is well able to hand over control to the
97 <c>init</c> binary on their system. But for many systems, an initramfs is almost
98 mandatory.
99 </p>
100
101 <p>
102 The key concept to understanding what an initramfs is (or is needed for) is to
103 understand how the Linux boot process works, even in a high-level approach.
104 </p>
105
106 </body>
107 </section>
108 <section>
109 <title>Linux boot process</title>
110 <body>
111
112 <p>
113 Once the Linux kernel has control over the system (which it gets after being
114 loaded by the boot loader), it prepares its memory structures and drivers as
115 good as it can. It then hands over control to an application (usually
116 <c>init</c>) whose task it is to further prepare the system and make sure that,
117 at the end of the boot process, all necessary services are running and the user
118 is able to log on. The <c>init</c> application does that by launching, amongst
119 other services, the <c>udev</c> daemon who will further load up and prepare the
120 system based on the detected devices. When <c>udev</c> is launched, all
121 remaining file systems that have not been mounted are mounted, and the remainder
122 of services is started.
123 </p>
124
125 <p>
126 For systems where all necessary files and tools reside on the same file system,
127 the <c>init</c> application can perfectly control the further boot process. But
128 when multiple file systems are defined (or more exotic installations are done),
129 this might become a bit more tricky:
130 </p>
131
132 <ul>
133 <li>
134 When the <path>/usr</path> partition is on a separate file system, tools and
135 drivers that have files stored within <path>/usr</path> cannot be used
136 unless <path>/usr</path> is available. If those tools are needed to make
137 <path>/usr</path> available, then we cannot boot up the system.
138 </li>
139 <li>
140 If the root file system is encrypted, then the Linux kernel will not be able
141 to find the <c>init</c> application, resulting in an unbootable system.
142 </li>
143 </ul>
144
145 <p>
146 The solution for this problem has since long been to use an <e>initrd</e>
147 (initial root device).
148 </p>
149
150 </body>
151 </section>
152 <section>
153 <title>The initial root disk</title>
154 <body>
155
156 <p>
157 The <e>initrd</e> is an in-memory disk structure (ramdisk) that
158 contains the necessary tools and scripts to mount the needed file systems before
159 control is handed over to the <c>init</c> application on the root file system.
160 The Linux kernel triggers the setup script (usually called <c>linuxrc</c> but
161 that is not mandatory) on this root disk, which prepares the system, switches to
162 the real root file system and then calls <c>init</c>.
163 </p>
164
165 <p>
166 Although the initrd method is all that is needed, it had a few drawbacks:
167 </p>
168
169 <ul>
170 <li>
171 It is a full-fledged block device, requiring the overhead of an entire
172 file system on it, and has a fixed size. Choose an initrd that is too small,
173 and you won't be able to fit in all needed scripts. Make it too big, and
174 you're wasting memory.
175 </li>
176 <li>
177 Because it is a real device, it also consumes cache memory in the Linux
178 kernel and is prone to the memory- and file management methods in use (such
179 as paging), making it even worse in memory consumption.
180 </li>
181 </ul>
182
183 <p>
184 To resolve these (for some perhaps hardly called) issues, the initramfs was
185 created.
186 </p>
187
188 </body>
189 </section>
190 <section>
191 <title>The initial ram file system</title>
192 <body>
193
194 <p>
195 An <e>initramfs</e> is an initial ram file system based on <e>tmpfs</e>
196 (a size-flexible, in-memory lightweight file system), which also didn't use a
197 separate block device (so no caching was done and all overhead mentioned earlier
198 disappears). Just like the initrd, it contains the tools and scripts needed to
199 mount the file systems before the <c>init</c> binary on the real root file
200 system is called. These tools can be decryption abstraction layers (for
201 encrypted file systems), logical volume managers, software raid, bluetooth
202 driver based file system loaders, etc.
203 </p>
204
205 <p>
206 The content of the initramfs is made by creating a cpio archive. <c>cpio</c> is
207 an old (but proven) file archiver solution (and its resulting archive files are
208 called <e>cpio files</e>). You can definitely compare it to <c>tar</c>. The
209 choice of <c>cpio</c> here was because it is easier to implement (code-wise) and
210 supported (back then) device files (which <c>tar</c> couldn't).
211 </p>
212
213 <p>
214 All files, tools, libraries, configuration settings (if applicable), etc. are
215 put into the cpio archive. This archive is then compressed using the <c>gzip</c>
216 utility and stored alongside the Linux kernel. The boot loader will then offer
217 it to the Linux kernel at boot time so the kernel knows an initramfs is needed.
218 </p>
219
220 <p>
221 Once detected, the Linux kernel will create a tmpfs file system, extract the
222 contents of the archive on it, and then launches the <c>init</c> script located
223 in the root of the tmpfs file system. This script will then mount the real root
224 file system (after making sure it can mount it, for instance by loading
225 additional modules, preparing an encryption abstraction layer, etc.) as well as
226 vital other file systems (such as <path>/usr</path> and <path>/var</path>).
227 </p>
228
229 <p>
230 Once the root file system and the other vital file systems are mounted, the
231 <c>init</c> script from the initramfs will switch the root towards the real root
232 file system and finally call the <c>/sbin/init</c> on that system to continue
233 the boot process.
234 </p>
235
236 </body>
237 </section>
238 </chapter>
239
240 <chapter>
241 <title>Creating an initramfs</title>
242 <section>
243 <title>Introduction and bootloader configuration</title>
244 <body>
245
246 <p>
247 To create an initramfs, it is important that you know what additional drivers,
248 scripts and tools you need to boot your system. For instance, if you use LVM,
249 then you will need to support LVM tools on the initramfs. Likewise, if you use
250 software RAID, you need <c>mdadm</c>, etc.
251 </p>
252
253 <p>
254 Some tools exist that help you create initramfs' (compressed cpio archives) for
255 your system. But for those that want total control, you can easily create your
256 own initramfs as well.
257 </p>
258
259 <p>
260 Once created, you will need to adjust the bootloader configuration to tell it
261 that an initramfs is to be used. For instance, if the initramfs file is stored
262 as <path>/boot/initramfs-3.2.2-gentoo-r5</path>, then the configuration in
263 <path>/boot/grub/grub.conf</path> could look like so:
264 </p>
265
266 <pre caption="Example entry in grub.conf for booting with an initramfs">
267 title Gentoo Linux 3.2.2-r5
268 root (hd0,0)
269 kernel /boot/kernel-3.2.2-gentoo-r5
270 initrd /boot/initramfs-3.2.2-gentoo-r5
271 </pre>
272
273 </body>
274 </section>
275 <section id="genkernel">
276 <title>Using genkernel</title>
277 <body>
278
279 <p>
280 Gentoo's kernel building utility, <c>genkernel</c>, can be used to generate an
281 initramfs, even if you didn't use <c>genkernel</c> to configure and build your
282 kernel.
283 </p>
284
285 <p>
286 To use <c>genkernel</c> for generating an initramfs, it is recommended that you
287 include all necessary drivers and code that is needed to mount your
288 <path>/</path> and <path>/usr</path> file systems in the kernel (and not as
289 modules). Then, call <c>genkernel</c> as follows:
290 </p>
291
292 <pre caption="Running genkernel to setup an initramfs">
293 # <i>genkernel --install --no-ramdisk-modules initramfs</i>
294 </pre>
295
296 <p>
297 Depending on your system, you might want to add one or more of the following
298 options:
299 </p>
300
301 <table>
302 <tr>
303 <th>Option</th>
304 <th>Description</th>
305 </tr>
306 <tr>
307 <ti>--disklabel</ti>
308 <ti>Add support for <c>LABEL=</c> settings in your <path>/etc/fstab</path></ti>
309 </tr>
310 <tr>
311 <ti>--dmraid</ti>
312 <ti>Add support for fake hardware RAID</ti>
313 </tr>
314 <tr>
315 <ti>--firmware</ti>
316 <ti>Add in firmware code found on the system</ti>
317 </tr>
318 <tr>
319 <ti>--gpg</ti>
320 <ti>Add in GnuPG support</ti>
321 </tr>
322 <tr>
323 <ti>--iscsi</ti>
324 <ti>Add support for iSCSI</ti>
325 </tr>
326 <tr>
327 <ti>--luks</ti>
328 <ti>Add support for luks encryption containers</ti>
329 </tr>
330 <tr>
331 <ti>--lvm</ti>
332 <ti>Add support for LVM</ti>
333 </tr>
334 <tr>
335 <ti>--mdadm</ti>
336 <ti>Add support for software RAID</ti>
337 </tr>
338 <tr>
339 <ti>--multipath</ti>
340 <ti>Add support for multiple I/O access towards a SAN</ti>
341 </tr>
342 <tr>
343 <ti>--zfs</ti>
344 <ti>Add support for ZFS</ti>
345 </tr>
346 </table>
347
348 <p>
349 When finished, the resulting initramfs file will be stored in your
350 <path>/boot</path>.
351 </p>
352
353 </body>
354 </section>
355 <section id="dracut">
356 <title>Using dracut</title>
357 <body>
358
359 <warn>
360 At the time of writing, dracut is not marked stable yet, so you might need to
361 unmask it before continuing.
362 </warn>
363
364 <p>
365 The <c>dracut</c> utility is created for the sole purpose of managing initramfs
366 files. It uses a highly modular approach on which support you want to include
367 and which not.
368 </p>
369
370 <p>
371 When you install <c>dracut</c>, you will need to take care to include support
372 for the correct <c>DRACUT_MODULES</c>. This is a variable you can set in
373 <path>/etc/make.conf</path> to include support for specific setups:
374 </p>
375
376 <pre caption="Preparing to install dracut">
377 DRACUT_MODULES="dmraid lvm syslog -biosdevname -btrfs -caps -crypt -crypt-gpg
378 -dmsquash-live -gensplash -iscsi -livenet -mdraid -multipath -nbd -nfs -plymouth
379 -ssh-client"
380 </pre>
381
382 <p>
383 It is adviseable to set (or unset) those modules you need (and don't need).
384 Afterwards, <c>emerge dracut</c> to install the utility on your system.
385 </p>
386
387 <p>
388 The next step is to configure <c>dracut</c> by editing
389 <path>/etc/dracut.conf</path>. In the configuration file, which is well
390 commented, you can add in support for specific modules where needed.
391 </p>
392
393 <p>
394 Once configured, create an initramfs by calling <c>dracut</c> as follows:
395 </p>
396
397 <pre caption="Calling dracut to generate an initramfs">
398 # <i>dracut</i>
399 </pre>
400
401 <p>
402 The resulting image supports generic system boots based on the configuration in
403 <path>/etc/dracut.conf</path>. You can also opt to generate an initramfs
404 specifically tailored to your system (in which <c>dracut</c> tries to detect the
405 needed tools, drivers, etc. from your existing system). If you know that the
406 needed support (code and drivers) is built in in your kernel (and not as
407 module), then you can even add in <c>--no-kernel</c>:
408 </p>
409
410 <pre caption="Allowing dracut to generate a host-specific initramfs">
411 # <i>dracut --host-only --no-kernel</i>
412 </pre>
413
414 <p>
415 For more information, check out the <c>dracut</c> and <c>dracut.cmdline</c>
416 manual pages.
417 </p>
418
419 </body>
420 </section>
421 </chapter>
422
423 <chapter>
424 <title>Additional resources</title>
425 <section>
426 <title>Gentoo-specific</title>
427 <body>
428
429 <ul>
430 <li>
431 <uri link="http://en.gentoo-wiki.com/wiki/Initramfs">Initramfs</uri> on
432 Gentoo-wiki.com
433 </li>
434 <li>
435 <uri link="http://wiki.gentoo.org/wiki/Initramfs">Initramfs</uri> on the
436 official Gentoo Wiki
437 </li>
438 <li>
439 <uri link="http://wiki.gentoo.org/wiki/Dracut">Dracut</uri> on the official
440 Gentoo Wiki
441 </li>
442 </ul>
443
444 </body>
445 </section>
446 <section>
447 <title>General resources</title>
448 <body>
449
450 <ul>
451 <li>
452 <uri
453 link="https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt">ramfs-rootfs-initramfs.txt</uri>
454 within the Linux kernel documentation
455 </li>
456 </ul>
457
458 </body>
459 </section>
460 </chapter>
461
462 </guide>