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.
fix: rename dracut.conf.d .conf files to conf.example
Sadly, dracut.conf.d.*.conf files will be also picked up
during CI test runs and there is no trivial way to disable
that, so let's follow the existing .example pattern until
there is a better solution.
find_kmod_module_from_sysfs_node() is called for every platform device
in the system via find_suppliers(). In turn, this calls
kmod_module_new_from_lookup() for every device modalias. This is an
expensive call that reads the modalias files every single time from
scratch.
On many platforms, there are many identical platform devices (e.g.
multiple serial ports, or dozens or hundreds of power domain devices).
Therefore, it's worth memoizing this so we only perform the expensive
lookup once per unique modalias.
This cuts down dracut generation time on an Apple M1 Pro MacBook Pro
from 26 seconds to 17 seconds, give or take (which is close to the
performance prior to 3de4c7313, which introduced a major regression
which has been incrementally improved in prior commits already).
feat(crypt): force the inclusion of crypttab entries with x-initrd.attach
dracut has a "hidden" and undocumented `force` crypttab option (added with
commit b7058d0ce5e99cbc80b5f760a0b654d3ff03c094). This option forces the
inclusion of a crypttab entry in the initrd, which is useful in some cases where
the filesystem check (for whatever reason) does not report a required encrypted
device as "crypto_LUKS".
On the other hand, systemd provides the `x-initrd.attach` crypttab option since
v245. Excerpt from `crypttab(5)`:
```
x-initrd.attach
Setup this encrypted block device in the initrd, similarly to systemd.mount(5)
units marked with x-initrd.mount.
```
This crypttab option is commonly used to mark encrypted block devices that
contain filesystems mounted in the initrd. So, this patch aims to make use of
this well-known systemd crypttab option to match the functionality provided by
the not so well-known dracut crypttab option.
Lidong Zhong [Mon, 24 Jun 2024 01:57:44 +0000 (09:57 +0800)]
fix(mdraid): try to assemble the missing raid device
If some raid devices with specified UUIDs fail to be assembled in
initrd, we will try to assemble them again in this script to avoid
system falling into emergency mode. This patch is created because we can
offen see mdadm command failure during boot because of timing issue
introduced between mdadm and udevd.
Benjamin Drung [Mon, 24 Jun 2024 15:17:03 +0000 (17:17 +0200)]
fix(lsinitrd.sh): disable SC2317 for cat functions
shellcheck 0.10 complains about SC2317 (info): Command appears to be
unreachable. Check usage (or ignore if invoked indirectly). It fails to
detect that these functions are assigned to `CAT` and `$CAT` is called
later. Disable shellcheck in this case.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Mon, 24 Jun 2024 11:28:00 +0000 (13:28 +0200)]
fix(dracut): microcode loading named .initramfs
intel-microcode on Debian/Ubuntu uses the `.initramfs` suffix for the
ucode files (e.g. `/lib/firmware/intel-ucode/06-9e-0b.initramfs`).
`get_ucode_file` returns `family-model-stepping` on Intel (e.g.
`06-9e-0b`). If the microcode file is found, the loop is broken.
Otherwise `.early` is appended to the name (e.g. `06-9e-0b.early`) and
tried again. If that file is not found, `.initramfs` is appended to the
name (e.g. `06-9e-0b.early.initramfs`), but this suffix should be
appended to the initial name (e.g. `06-9e-0b.initramfs`).
Fixes: 16573680d1b6 ("fix(dracut): microcode loading") Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
The `get_maj_min()` cache lookup is commonly used
across many flows. While `awk` should be available,
some highly constrained environments may not have it.
A second call to `grep` can provide the same behaviour
without adding a dependnecy.
Lines in the cache will be of the form "/dev/sda2 8:2".
`awk '{print $NF}'` returns the last word of a matching line. Since
the initial matching regex is so specific a second call to grep can
easily extract the last word.
Benjamin Drung [Fri, 21 Jun 2024 23:55:17 +0000 (01:55 +0200)]
fix(dracut-logger.sh): disable SC2317 for logger functions
shellcheck 0.10 complains about SC2317 (info): Command appears to be
unreachable. Check usage (or ignore if invoked indirectly). It fails to
detect that these logger functions are called later by scripts that
source `dracut-logger.sh`. Disable shellcheck in this case.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Fri, 21 Jun 2024 23:37:04 +0000 (01:37 +0200)]
test: disable SC2317 in test 98
shellcheck 0.10 complains about SC2317 (info): Command appears to be
unreachable. Check usage (or ignore if invoked indirectly). It fails to
detect cases where a function is defined and later called by `getarg` or
existing functions are overridden. Disable shellcheck in these cases.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Fri, 21 Jun 2024 23:27:23 +0000 (01:27 +0200)]
fix(convertfs): disable SC2317 for EXIT trap function
shellcheck complains about SC2317 (info): Command appears to be
unreachable. Check usage (or ignore if invoked indirectly). It fails to
detect cases where a function is defined and later called by a trap.
Disable shellcheck in this case.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Thu, 20 Jun 2024 12:11:02 +0000 (14:11 +0200)]
feat(dracut): search for zstd compressor first
Searching for an available compressor was introduced in commit 693b7a32833b ("Cleanup compressor handling") but the order was not
justified.
Ubuntu uses zstd for compressing the packages, the kernel modules,
firmware files, and the initrd (when using initramfs-tools). zstd has a
good compromise between compression ratio and speed. Therefore search
for zstd first.
Further readings:
* https://lists.ubuntu.com/archives/ubuntu-devel/2021-December/041726.html
* analysis.ipynb on https://github.com/waveform80/compression
Benjamin Drung [Sat, 15 Jun 2024 20:17:51 +0000 (22:17 +0200)]
fix: disable SC2317 for calls by for_each_host_dev_and_slaves
shellcheck 0.10 complains about SC2317 (info): Command appears to be
unreachable. Check usage (or ignore if invoked indirectly). It fails to
detect cases where a function is defined and later called by
`for_each_host_dev_and_slaves`. Disable shellcheck in this case.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Sat, 15 Jun 2024 13:23:53 +0000 (15:23 +0200)]
fix(convertfs): quote single CP_HARDLINK variable
shellcheck complains about SC2086 (info): Double quote to prevent
globbing and word splitting.
The variable `CP_HARDLINK` contains either nothing or exactly one
parameter. Use shell substitution to quote this single parameter in case
it is not empty.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Sat, 15 Jun 2024 12:48:49 +0000 (14:48 +0200)]
fix(dmsquash-live-autooverlay): quote variables
shellcheck complains about SC2086 (info): Double quote to prevent
globbing and word splitting.
Instead of ignoring those complains fix them instead. The variable
`overlay` should be quoted since it might contain spaces. The variables
`rootDevice`, `rootDeviceAbsolutePath`, `rootDeviceSysfsPath`,
`fullDriveSysfsPath`, `blockDevice` refer to paths. Therefore they are
safe to quote.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Benjamin Drung [Thu, 13 Jun 2024 22:41:53 +0000 (00:41 +0200)]
fix(iscsi): address shellcheck SC2319
shellcheck complains:
```
In modules.d/95iscsi/iscsiroot.sh line 232:
[ -z "$targets" ] && warn "Target discovery to $iscsi_target_ip:${iscsi_target_port:+$iscsi_target_port} failed with status $?" && return 1
^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.
```
The `while` loop that gets the output from `iscsiadm` via a pipe will
exit with 0. Printing the exit code 0 does not help. So just drop it.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
```
In modules.d/80lvmthinpool-monitor/start-thinpool-monitor.sh line 12:
[ -n "$_lvm2_thin_device" ] && return $?
^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.
```
Let `is_lvm2_thinp_device` directly return the test exit code.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>