On Fri, Feb 10, 2017 at 6:58 AM, marco restelli <mreste...@gmail.com> wrote: > Hi all, > I am trying to understand a bit initramfs and genkernel and I have > few (basic) questions. > > I understand that one must have in the initramfs those modules which > are required to boot the system, for instance to access /dev . Now:
Sort-of. You need an initramfs if the kernel cannot otherwise mount /, and /usr (if it isn't on the same filesystem as /). Being able to mount / is an absolute requirement, there are other ways to go about mounting /usr. An initramfs has some benefits even if the kernel could mount /, such as making it easier or more reliable to identify the correct root filesystem. > > - can a module be present both in the initramfs and as kernel module > in /lib/modules ? > Yes, and typically all of the initramfs modules are present in both. > - how does genkernel decide which modules to put in the initramfs ? I can't speak to genkernel specifically, but most initramfs generators include all modules. Other than space and miniscule load time there isn't much reason not to. > > - can modules included in the initramfs be unloaded once the system is > running, as modprobe -r Yes, assuming it isn't in use. Most of the stuff loaded by the initramfs is probably going to be in use until you shut down (such as the module for the root filesystem). > > - can modprobe load modules from the initramfs ? > Only if it is run from within the initramfs. Otherwise this is like asking whether a binary in a chroot can run something outside the chroot. Of course, typically all the initramfs modules are also present in /lib so modprobe will just load the module from there. > > Well, clearly I am a bit confused about the topic - I hope somebody > can help me a bit! > An initramfs is really just a chroot in some sense. Though, it would be more accurate to say that the system you're using after you've booted is the chroot, and the initramfs was the original host. The initramfs is the root filesystem when the kernel boots, and it basically does whatever it needs to to find the real root filesystem, mount it, and then it deletes its stuff to free up ram, chroots to the real root, and execs the real init. At that point very little of the initramfs is left, other than any kernel modules it might have loaded (which are no different from kernel modules loaded at a later point in time). It is just a way to do userspace bootstrapping. Coreboot/libreboot take this to yet another level. Rather than try to build the smarts into the kernel to handle every conceivable system configuration, the kernel provides the driver and some basic logic, and if you want to do something fancier you use an initramfs and the initramfs can do anything you can do in linux userspace to find and mount root. It could download root from a webserver, or launch postfix and wait for somebody to send the root filesystem as an attachment, or whatever your imagination can come up with. Usually, though, it ends up just mounting /dev/sda2 or whatever. Most distros use an initramfs by default because it is more robust and can handle things like UUIDs and labels. That way if you plug in a new drive and your existing drives get renumbered the correct filesystem gets mounted. That, and it lets them use highly modular kernels without having to know what kind of filesystem you'll use for /, since it can just be modprobed at run time. This lets them build all the drivers as modules, which costs some disk space and a lot of one-time compile time, but gives the end-user more flexibility without any need to custom-build a kernel. Gentoo is a bit unusual in encouraging users to build their own kernels, but of course once you do that then there is no need to build all the drivers, or use an initramfs for modules needed to mount /. Otherwise, there is nothing special about modules loaded from the initramfs. They're just kernel modules. -- Rich