Gentoo Archives: gentoo-dev

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: /usr vs. initramfs redux
Date: Sat, 06 Aug 2011 02:16:54
Message-Id: pan.2011.08.06.02.15.34@cox.net
In Reply to: Re: [gentoo-dev] /usr vs. initramfs redux by Rich Freeman
1 Rich Freeman posted on Fri, 05 Aug 2011 21:04:50 -0400 as excerpted:
2
3 > On Fri, Aug 5, 2011 at 8:42 PM, William Hubbs <williamh@g.o>
4 > wrote:
5 >> On Fri, Aug 05, 2011 at 10:06:48PM +0200, Sven Vermeulen wrote:
6 >>> How does the tool that creates an initramfs know which files to copy
7 >>> from /usr and /var anyhow?
8 >>
9 >>  My understanding is that nothing gets copied from /usr and /var, and
10 >>  it doesn't have to.
11 >>
12 >>  Here is my basic understanding of how the boot sequence works:
13 >>
14 >>  1) rootfs is mounted on /. Rootfs contains the contents of the
15 >>        initramfs.
16 >
17 > Ok, so the initfs is typically in /boot, though it need not be. It
18 > needs to be someplace the bootloader can find it, and with grub legacy
19 > that typically means on a bare hard drive partition, or one using md
20 > raid-1 with older metadata. The initramfs doesn't need to find itself -
21 > the bootloader loads it into ram and passes its address to the kernel
22 > when executing it.
23
24 With a personal knowledge caveat similar to that of williamh's, I believe
25 tha above to be incorrect.
26
27 AFAIK, the distinction between initrd and initramfs is the following:
28
29 initrd: An initrd is a file separate from the kernel, so yes, the
30 bootloader needs to know about and pass its information to the kernel.
31
32 initramfs: An initramfs, as alluded to in the quote from the
33 documentation in an earlier post, is a cpio archive appended to the
34 kernel image itself -- no separate initrd file, and the kernel knows to
35 look for the compressed image as loaded into memory after the end of the
36 kernel code itself. At kernel build time, if this feature is configured
37 the kernel make process will check to see if a suitable prebuild cpio
38 archive is available and append it to the kernel image if so. If the cpio
39 archive is not available yet but there's a configuration for building it,
40 it'll be built, then appended to the kernel image.
41
42 As such, the bootloader doesn't need to point the kernel at the initramfs
43 since the kernel already knows where to find it as loaded into memory as
44 part of the kernel image file, and certain kernel commandline options
45 (AFAIK root=, init=) that would normally apply to the initrd if one was
46 used, apply to the final "realroot" instead.
47
48 An initramfs thus has less "to go wrong", since it's appended to the
49 kernel image as part of the same file at build time, so the two are
50 always kept together. While it's still possible that the kernel fails to
51 update its initramfs image at build-time, once that's correct, the boot
52 loader can't accidentally be pointed at the wrong initrd, since an
53 initramfs becomes part of the same kernel file as the kernel image itself.
54
55 (I've read that it's possible to have both an initramfs as appended to
56 the kernel image, and an initrd as configured on the kernel command line
57 by the boot loader, thus effectively creating a three-stage boot,
58 initramfs, initrd, realroot. I've no idea whether that's true or not,
59 but the idea of trying to keep track of what belongs in one vs. the other
60 strikes me as way more complex than it'd be worth for most gentoo users,
61 altho I can see that it might be useful for users of binary distros with
62 prebuilt kernel images, who wish to do additional stuff in an initrd,
63 without messing with the prebuilt and presumably supported kernel image
64 as distributed by their distro, with its own prebuilt initramfs
65 appended. It could also be useful for certain gentoo users, for instance
66 those doing remote-boot kernels with the basics applying to most
67 instances found in the initramfs, while any necessary configuration
68 specific to only a subset could be loaded as an initrd.)
69
70 >> 2) the init program inside  the initramfs is run.
71 >> 3) This init program will mount the real /usr and /var.
72 >
73 > So, this is the chicken and egg bit that led to the question about how
74 > the tool that creates initramfs knows what to copy from /usr, etc. If
75 > /usr can be mounted without any files from /usr, then clearly booting
76 > without /usr mounted shouldn't be a problem (just mount it early). If
77 > it does need files from /usr, then the initramfs has to contain those
78 > files since /usr isn't mounted yet.
79 >
80 > The answer isn't that complicated - the tool just knows what files are
81 > needed from a hardcoded list/etc.
82
83 No quibbles with this or the rest of what you wrote, and indeed, I agree
84 that the question needed asked/answered. (It still hasn't been answered
85 in any detail, but I'm not sure if that was the intent of asking the
86 question. The general "it's hardcoded" answer is sufficient at a
87 suitably high level.)
88
89 --
90 Duncan - List replies preferred. No HTML msgs.
91 "Every nonfree program has a lord, a master --
92 and if you use the program, he is your master." Richard Stallman