dracut icon indicating copy to clipboard operation
dracut copied to clipboard

fix(dmsquash-live-root): check kernel for built-in `overlay` drivers

Open FGrose opened this issue 3 years ago • 11 comments

Do not assume that overlay is always a module. Check first for overlay in /proc/filesystems.

Signed-off-by: Federico Vaga [email protected]

See this discussion thread: https://www.spinics.net/lists/linux-initramfs/msg04900.html

FGrose avatar Aug 02 '22 22:08 FGrose

modprobe foo should return 0 for builtin modules, no?

# modinfo ext4
name:           ext4
filename:       (builtin)
softdep:        pre: crc32c
license:        GPL
file:           fs/ext4/ext4
description:    Fourth Extended Filesystem
author:         Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others
alias:          fs-ext4
alias:          ext3
alias:          fs-ext3
alias:          ext2
alias:          fs-ext2
# modprobe ext4
# echo $?
0

marcosfrm avatar Aug 03 '22 10:08 marcosfrm

Your example is correct, and you are right, modprobe behaves as you described. However, it does behave like that only if you have this file /lib/modules/<kver>/modules.builtin in your filesystem (most cases). If you do not have it, you will get the following message:

modprobe overlay                                                                                               
modprobe: FATAL: Module overlay not found in directory /lib/modules/<kver>

If you run dracut with --no-kernel you do not get any /lib/modules/<kver> directory.

What I implemented in this patch is also what has been done in the NFS module modules.d/95nfs/nfs-start-rpc.sh (see a67a6f957dfd8ca51dea1ac5f8ca51a7646cca0f).

FedericoVaga avatar Aug 03 '22 19:08 FedericoVaga

Always copy /lib/modules/$(uname -r)/modules.builtin* to the initramfs and avoid these hacks?

marcosfrm avatar Aug 03 '22 19:08 marcosfrm

I must say I do not fully know --no-kernel use case, hence your fix may be better after all.

marcosfrm avatar Aug 03 '22 19:08 marcosfrm

Always copy /lib/modules/$(uname -r)/modules.builtin* to the initramfs and avoid these hacks?

If this become a requirement, then it should be done by dracut automatically, not by users.

I must say I do not fully know --no-kernel use case, hence your fix may be better after all.

In my case, I do not want any kernel stuff to be in the initrd because I have all I need in the kernel image. I need an initrd stage to perform a couple of actions, and I want this to be decoupled from the kernel. Meaning that whenever I update the kernel I can forget about rebuilding the initrd image, or to update final rootfs.

FedericoVaga avatar Aug 04 '22 06:08 FedericoVaga

Meaning that whenever I update the kernel I can forget about rebuilding the initrd image, or to update final rootfs.

Right. Your patch makes sense then. Sorry for the noise. On a side note, kernel should put this information somewhere in /sys to allow libkmod detect it without having to parse any index file...

marcosfrm avatar Aug 04 '22 10:08 marcosfrm

Right. Your patch makes sense then. Sorry for the noise. On a side note, kernel should put this information somewhere in /sys to allow libkmod detect it without having to parse any index file...

It would be a nice option. Something along the line of /proc/config.gz and /sys/kernel/kheaders.tar.xz

FedericoVaga avatar Aug 04 '22 15:08 FedericoVaga

LGTM

lnykryn avatar Aug 05 '22 09:08 lnykryn

Do not assume that overlay is always a module.

Is this only a concern for the the overlay module ? As an example same can be said for the squashfs module.

Perhaps this is an opportunity to introduce this piece of code as a reusable function in dracut-lib.sh, so that other modules can also start using it as needed.

{ strstr "$(< /proc/filesystems)" $1 || modprobe $1; };

LaszloGombos avatar Aug 06 '22 17:08 LaszloGombos

Is this only a concern for the the overlay module ? As an example same can be said for the squashfs module.

You are right. As I mentioned, I copied the proposed code from the NFS module, and probably the problem is present in other modules. I'm not a dracut developer, but what you suggest sounds to me the right approach: for sure there are 2 modules needing it :)

FedericoVaga avatar Aug 06 '22 22:08 FedericoVaga

One could argue to fix the bug and refactor code later with a follow-up PR - especially if @FedericoVaga is not in a position to do so in this PR.

LGTM.

LaszloGombos avatar Aug 06 '22 23:08 LaszloGombos