1 |
On Fri, Feb 10, 2017 at 6:58 AM, marco restelli <mrestelli@×××××.com> wrote: |
2 |
> Hi all, |
3 |
> I am trying to understand a bit initramfs and genkernel and I have |
4 |
> few (basic) questions. |
5 |
> |
6 |
> I understand that one must have in the initramfs those modules which |
7 |
> are required to boot the system, for instance to access /dev . Now: |
8 |
|
9 |
Sort-of. You need an initramfs if the kernel cannot otherwise mount |
10 |
/, and /usr (if it isn't on the same filesystem as /). Being able to |
11 |
mount / is an absolute requirement, there are other ways to go about |
12 |
mounting /usr. |
13 |
|
14 |
An initramfs has some benefits even if the kernel could mount /, such |
15 |
as making it easier or more reliable to identify the correct root |
16 |
filesystem. |
17 |
|
18 |
> |
19 |
> - can a module be present both in the initramfs and as kernel module |
20 |
> in /lib/modules ? |
21 |
> |
22 |
|
23 |
Yes, and typically all of the initramfs modules are present in both. |
24 |
|
25 |
> - how does genkernel decide which modules to put in the initramfs ? |
26 |
|
27 |
I can't speak to genkernel specifically, but most initramfs generators |
28 |
include all modules. Other than space and miniscule load time there |
29 |
isn't much reason not to. |
30 |
|
31 |
> |
32 |
> - can modules included in the initramfs be unloaded once the system is |
33 |
> running, as modprobe -r |
34 |
|
35 |
Yes, assuming it isn't in use. Most of the stuff loaded by the |
36 |
initramfs is probably going to be in use until you shut down (such as |
37 |
the module for the root filesystem). |
38 |
|
39 |
> |
40 |
> - can modprobe load modules from the initramfs ? |
41 |
> |
42 |
|
43 |
Only if it is run from within the initramfs. Otherwise this is like |
44 |
asking whether a binary in a chroot can run something outside the |
45 |
chroot. Of course, typically all the initramfs modules are also |
46 |
present in /lib so modprobe will just load the module from there. |
47 |
|
48 |
> |
49 |
> Well, clearly I am a bit confused about the topic - I hope somebody |
50 |
> can help me a bit! |
51 |
> |
52 |
|
53 |
An initramfs is really just a chroot in some sense. Though, it would |
54 |
be more accurate to say that the system you're using after you've |
55 |
booted is the chroot, and the initramfs was the original host. The |
56 |
initramfs is the root filesystem when the kernel boots, and it |
57 |
basically does whatever it needs to to find the real root filesystem, |
58 |
mount it, and then it deletes its stuff to free up ram, chroots to the |
59 |
real root, and execs the real init. At that point very little of the |
60 |
initramfs is left, other than any kernel modules it might have loaded |
61 |
(which are no different from kernel modules loaded at a later point in |
62 |
time). |
63 |
|
64 |
It is just a way to do userspace bootstrapping. Coreboot/libreboot |
65 |
take this to yet another level. Rather than try to build the smarts |
66 |
into the kernel to handle every conceivable system configuration, the |
67 |
kernel provides the driver and some basic logic, and if you want to do |
68 |
something fancier you use an initramfs and the initramfs can do |
69 |
anything you can do in linux userspace to find and mount root. It |
70 |
could download root from a webserver, or launch postfix and wait for |
71 |
somebody to send the root filesystem as an attachment, or whatever |
72 |
your imagination can come up with. |
73 |
|
74 |
Usually, though, it ends up just mounting /dev/sda2 or whatever. Most |
75 |
distros use an initramfs by default because it is more robust and can |
76 |
handle things like UUIDs and labels. That way if you plug in a new |
77 |
drive and your existing drives get renumbered the correct filesystem |
78 |
gets mounted. That, and it lets them use highly modular kernels |
79 |
without having to know what kind of filesystem you'll use for /, since |
80 |
it can just be modprobed at run time. This lets them build all the |
81 |
drivers as modules, which costs some disk space and a lot of one-time |
82 |
compile time, but gives the end-user more flexibility without any need |
83 |
to custom-build a kernel. Gentoo is a bit unusual in encouraging |
84 |
users to build their own kernels, but of course once you do that then |
85 |
there is no need to build all the drivers, or use an initramfs for |
86 |
modules needed to mount /. |
87 |
|
88 |
Otherwise, there is nothing special about modules loaded from the |
89 |
initramfs. They're just kernel modules. |
90 |
|
91 |
-- |
92 |
Rich |