Fabian Vogt [Mon, 5 Aug 2024 09:28:32 +0000 (11:28 +0200)]
fix(dracut-functions.sh): only return block devices from get_persistent_dev
With udev 256, there are now directories such as
/dev/disk/by-path/pci-0000:02:00.0-nvme-1-part/ which match here.
In case a nonexisting file/device was passed to get_persistent_dev, it
returned the first directory it looked at because both have maj:min 0:0.
This accidental conversion from garbage to a sensible looking path leads
to weird behaviour later.
Instead of filtering out directories explicitly switch the check to only
return block devices, which also takes care of the character special
/dev/mapper/control.
Philipp Rudo [Tue, 30 Jul 2024 11:44:32 +0000 (13:44 +0200)]
fix(squash): use 99busybox instead of installing it manually
Make use of 99busybox in 99squash rather than installing it manually.
This not only removes duplicate code but allows mixing of busybox with
tools from coreutils. This requires a small change in 99busybox to
remove the hard coded use of $initdir.
Suggested-by: Laszlo Gombos <laszlo.gombos@gmail.com> Signed-off-by: Philipp Rudo <prudo@redhat.com>
At the moment 99squash relies on dracut-install to create the required
directories it later links to. This approach is error prone and will
cause problems when switching to use 99busybox later on, which tries to
add a link to /usr/sbin that hasn't been created. Thus explicitly
create the expected directories before installing the minimal initrd.
Philipp Rudo [Tue, 23 Jul 2024 16:33:37 +0000 (18:33 +0200)]
feat(lsinitrd): add support for erofs images
Add support to handle erofs images in lsinitrd. Unfortunately the erofs
tooling is missing some functionality of unsquashfs, esp. the ability to
extract single files and list the content of the image. Work around this
deficiency by always extracting the full image and emulate the missing
functionality as close as possible.
While at it also handle the rename of the squashfs image to
squashfs-root.img.
Philipp Rudo [Tue, 23 Jul 2024 15:42:33 +0000 (17:42 +0200)]
feat(squash): add module 95squash-erofs
Allow squashing the image in 99squash using erofs. Keep squashfs as
default to not change existing systems. I.e. only use erofs if the user
explicitly include 95squash-erofs or when the prereqs for squashfs are
missing.
Philipp Rudo [Tue, 23 Jul 2024 14:39:13 +0000 (16:39 +0200)]
feat(squash): split 95squash-squashfs from 99squash
99squash only allows squashing the files using squashfs. In order to
make the implementation for different filesystems easier split out the
squashfs specific parts into 95squash-squashfs.
While at it rename the root image contained in the initrd to
squashfs-root.img. This allows tools like lsinitrd to detect the
filesystem used later on.
Philipp Rudo [Mon, 22 Jul 2024 14:30:50 +0000 (16:30 +0200)]
feat(squash): move mksquashfs to 99squash/modules-setup
When using 99squash dracut actually builds two separat initrds. The
"normal" one, that gets squashed into a squashfs image, and a
"minimalistic" one, whose only task is to mount and switch_root to the
squashfs image.
For that 99squash currently requires a lot of special handling in
dracut.sh. Move most of this special handling into 99squash itself. This
requires a new approach when building the "minimalistic" initrd. The new
approach works the following way
1. During the installation phase install the "normal" initrd into
$initdir and the "minimalistic" initrd into $squashdir.
2. Strip the binaries in $initdir.
3. Trigger a special postinstall hook in 99squash that squashes the
content of $initdir (excluding $squashdir) into the squashfs image,
removes the content of $intidir (excluding $suqashdir) and, moves the
content of $squashdir into $initdir.
Philipp Rudo [Thu, 25 Jul 2024 10:47:00 +0000 (12:47 +0200)]
fix(dracut-init.sh): add module to mods_to_load before checking dependencies
When implementing erofs support for 99squash we end up with three
modules 99squash, 95squash-squashfs and 95squash-erofs. Where 99squash
contains the common code for filesystem images and
95squash-{squashfs,erofs} the special handing depending on the
filesystem used. This leads to a dependency cycle as we want to allow
users both to choose 99squash, when the exact filesystem doesn't matter,
as well as 95squash-{squashfs,erofs} when a specific filesystem is
required.
But when 99squash is added as a dependency calling
dracut_module_included fails in its depends() function. This lead to
cases where both handlers, 95squash-squashfs and 95squash-erofs, were
added to the initrd.
Reason for the failure is that a module only is marked to be loaded
after all it's dependencies have been checked as well. Thus a child
module cannot detect which parent module wants it to be included. Fix
this by marking modules to be loaded before checking its dependencies in
check_module. Do the same change in check_mount for consistency.
Philipp Rudo [Mon, 22 Jul 2024 14:46:47 +0000 (16:46 +0200)]
feat(dracut-init.sh): allow changing the destination directory for inst et al
When using 99squash dracut actually builds two separate initrds. The
"normal" one, that gets squashed into a squashfs image, and a
"minimalistic" one, whose only task is to mount and switch_root to the
squashfs image.
This is currently done the following way:
1. Skipp install() for 99squash during the "normal" installation phase.
2. Trigger a special postinstall hook in 99squash that moves the content
of $initdir to $squashdir and installs the "minimalistic" initrd to
$initdir.
3. Strip the binaries in $initdir (of which $squashdir is a sub
directory of).
4. Squash the content of $squashdir into the squashfs image and remove
$squashdir.
The problem with this approach is that the steps 2 and 4 specific to
99squash but need to be done in dracut.sh. Thus a lot of special
handling for 99squash is needed in dracut.sh. This will get even more
complex once support for different filesystem images, e.g. erofs, are
implemented.
In order to be able to move most of the functionality into 99squash
itself a new approach will be chosen, i.e.
1. During the installation phase install the "normal" initrd into
$initdir and the "minimalistic" initrd into $squashdir.
2. Strip the binaries in $initdir.
3. Trigger a special postinstall hook in 99squash that squashes the
content of $initdir (excluding $squashdir) into the squashfs image,
removes the content of $intidir (excluding $suqashdir) and, moves the
content of $squashdir into $initdir.
With that the only special handling remaining in dracut.sh is triggering
the postinstall hook.
However, in inst et al. the destination directory is hard coded to
$initdir. Thus allow setting a different destination directory in inst
et al. to get the new approach to work. For the time being only do that
for the functions required by 99squash.
feat(busybox): use busybox --install to install itself
Previous commits in this PR exposed a bug whereby some utilities
(e.g. dd) had both a busybox applet version and a coreutils version.
The busybox dracut module should not enforce taking always the
busybox version. The `busybox --install` command is safer option
that does not overwrite an existing binary of already exists.
By using a GitHub team for the CODEOWNERS file, we can
easily add and remove people through the interface for
global committers and avoid unnecessary churn.
Add new version commit number to the commit message.
Lock clog version to a version that is working well.
Allow clog to be installed in the user home as well.
Martin Wilck [Tue, 16 Jul 2024 14:55:03 +0000 (16:55 +0200)]
fix(multipath): include module with "find_multipaths strict"
The previous commits 377d52c and 4957ffa excluded the multipath module in
non-hostonly mode, with the purpose of avoiding to start multipath in the
initramfs on systems that don't use multipath. This is against the idea of
non-hostonly, which is to build an initramfs with all kernel modules and tools
that may be necessary to bring up the system.
This patch takes a different approach. In non-hostonly mode, if there are no
multipath devices and no multipath.conf, include the multipath module, but
require "find_multipaths strict" policy. This will ensure that users that don't
use dm-multipath won't be surprised by finding their root device under
multipath control. But the multipath tools will still be included in the
initramfs, allowing users to set up multipathing e.g. on the emergency shell if
necessary. Also, if /etc/multipath/wwids exists, it will be included in the
initramfs and will cause the WWIDs listed in that file to be multipathed.
Note that in multipath-tools upstream and many Linux distributions,
"find_multipaths strict" is the default anyway. Users of distributions with
different defaults (e.g. openSUSE) would just need to create
/etc/multipath.conf (possibly with empty contents) to override this behavior if
they intend to activate multipath in the initramfs.
Fixes: 377d52c ("fix(multipath): omit module if included with no multipath devices") Fixes: 4957ffa ("fix(multipath): omit module if included with no multipath devices")
Brian C. Lane [Fri, 12 Jul 2024 22:43:12 +0000 (15:43 -0700)]
test(DMSQUASH): add test for part of erofs support
This adds a test for using erofs on a bare partition by
creating a new disk image, root_erofs, and writing the erofs compressed
/source directory directly to partition 1 and then booting the image
with root=live:/dev/disk/by-label/dracut_erofs
This doesn't quite test the anaconda-dracut use case of calling
dmsquash-live-root with the path of an erofs compressed file, but it is
close enough for now.
Brian C. Lane [Wed, 10 Jul 2024 23:30:09 +0000 (16:30 -0700)]
feat(dmdquash-live): add support for using erofs
This adds support for rootfs compressed with erofs. Either as a plain
erofs image or a LiveOS/rootfs.img ext4 filesystem compressed with
erofs.
This patch does not make any attempt to change the squashfs directory
naming (or variable names) in order to make these changes as small as
possible and easy to review. It also does not make any attempt to
support the multitude of available options other than what is needed by
anaconda-dracut calling this script to setup the boot.iso root
filesystem.
(which isn't to say it doesn't work, it just hasn't been tested and is
outside the scope of this change).
feat(kernel-modules): install platform/chrome modules on ARM/RISC-V
Most ARM Chromebooks need the ChromiumOS Embedded Controller drivers
located under kernel/drivers/platform/chrome for essential functionality
like keyboard, USB, and display backlight. Add them to the non-hostonly
initramfs by adding them to the ARM/RISC-V-specific instmods call.
Huaxin Lu [Thu, 20 Jun 2024 05:38:26 +0000 (13:38 +0800)]
fix(dracut-install): copy xattr when use clone ioctl
When use clone ioctl to copy a file, the extended attributes of files are
missing, which is inconsistent with the result by using the cp command.
This commit add the process to copy extended attributes after clone_file().
feat(multipath): warn if included with no multipath devices and no user conf
The multipath module is always included in no-hostonly mode, but including it in
the initramfs might activate multipath on the root device, which could be
undesirable. This behavior can be manually fixed by explicitly excluding the
root device from multipath in /etc/multipath.conf.
Therefore, issue a warning in no-hostonly mode, if there is no multipath device
and the user has not configured multipath.
Benjamin Drung [Mon, 8 Jul 2024 14:29:40 +0000 (16:29 +0200)]
fix(nfs): support rpcbind user named _rpc
The Debian/Ubuntu package `rpcbind` creates a user named `_rpc`. Support
running `rpcbind` with that user. Add a helper function `get_rpc_user`
that derives the desired user from parsing `/etc/passwd`.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
feat(dracut-install): configure if weak dep is still not supported in kmod
The weak dependency feature is new and better be backward compatible.
So check in configure stage if the kmod used includes the weak dependency
feature so as not to include it here and avoid compilation errors.
Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
feat(dracut-install): add weak dependencies support
It has been seen that for some network mac drivers (i.e. lan78xx) the
related module for the phy is loaded dynamically depending on the current
hardware. In this case, the associated phy is read using mdio bus and then
the associated phy module is loaded during runtime (kernel function
phy_request_driver_module). However, no software dependency is defined, so
the user tools will no be able to get this dependency. For example, if
dracut is used and the hardware is present, lan78xx will be included but no
phy module will be added, and in the next restart the device will not work
from boot because no related phy will be found during initramfs stage.
In order to solve this, we could define a normal 'pre' software dependency
in lan78xx module with all the possible phy modules (there may be some),
but proceeding in that way, all the possible phy modules would be loaded
while only one is necessary.
So, a new type of dependency has been created, that we are going to call
'weak' to be used only by the user tools that need to detect this situation.
In that way, for example, dracut could check the 'weak' dependency of the
modules involved in order to install these dependencies in initramfs too.
That is, for the commented lan78xx module, defining the 'weak' dependency
with the possible phy modules list, only the necessary phy would be loaded
on demand keeping the same behavior, but all the possible phy modules would
be available from initramfs.
The 'weak' dependency support has been already included in kmod:
https://github.com/kmod-project/kmod/commit/05828b4a6e9327a63ef94df544a042b5e9ce4fe7
And in kernel:
https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/commit/?h=modules-next&id=1f3dacc0dcef6681c2acf5890e018012f6b53085
After these, 'weak' dependencies for modules will start to appear.
Read the possible weak dependencies from dracut in order to take them into
account.
Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
perf(dracut-install): use driver/module sysfs dirs for module name
To handle fw_devlink suppliers as dependencies, we traverse every device
in /sys and collect a hashmap of module names to their suppliers before
starting module installation work. The module names are found by reading
and passing the "modalias" file to the `kmod_module_new_from_lookup()`
function from libkmod. This function is unexpectedly slow on ARM64
systems with device-tree where this work is primarily necessary.
Usually (but not always), the running kernel has already looked up the
modalias and bound a driver from the associated module. Get module names
by resolving the "driver/module" symbolic link and taking its basename.
If it doesn't exist, fall back to looking up the modalias.
It's possible that multiple modules match the modalias, in which case
others will be ignored in favor of the one already chosen by the kernel.
Benjamin Drung [Tue, 2 Jul 2024 20:15:57 +0000 (22:15 +0200)]
feat(lsinitrd.sh): support configurable initrd filenames
The initrd filename can be configured via `initrdname`. Support this
feature also in `lsinitrd` (similar to the code in
`dracut-initramfs-restore.sh`).
Fix: 28820e205328 ("feat(dracut.sh): make initramfs-${kernel}.img filename configurable") Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Tue, 2 Jul 2024 20:15:41 +0000 (22:15 +0200)]
fix: check for searched initrds to be present
`find_initrd_for_kernel_version` uses the same search order than
`kernel-install` from systemd v249 [1]. When
`dracut-initramfs-restore.sh` or `lsinitrd.sh` searches for initrds,
they should check the presence of the files instead of assuming them to
be present. Otherwise the search might be stopped before an existing
initrd is found. On Ubuntu 24.10 (oracular) with a mounted `/boot`:
```
$ ls /boot/initr* -alh
lrwxrwxrwx 1 root root 27 Jun 20 15:31 /boot/initrd.img -> initrd.img-6.8.0-31-generic
-rw-r--r-- 1 root root 22M Jun 20 16:27 /boot/initrd.img-6.8.0-31-generic
lrwxrwxrwx 1 root root 27 Jun 20 15:31 /boot/initrd.img.old -> initrd.img-6.8.0-31-generic
$ lsinitrd 2>&1 | head -n1
No <initramfs file> specified and the default image '/boot/efi/6491959c70e6481eae6406d25e250d76/6.8.0-31-generic/initrd' cannot be accessed!
```
Refactor `dracut-initramfs-restore.sh` and `lsinitrd.sh` to introduce a
`find_initrd_for_kernel_version` function to abstract the code. This
commit does not change the logic of the search order.