Commit Graph

78 Commits (b80ee080937ce364f7324c297f23e40af6d88892)

Author SHA1 Message Date
Harald Hoyer 2536a9eaff fix(install): handle builtin modules
If a `kmod_module` is missing the `path`, it is `builtin`.
2021-03-30 10:27:02 +02:00
Harald Hoyer 2ec7fa190e style(install): astyle post correction 2021-03-15 15:37:08 +01:00
Harald Hoyer f1ed92c348 style: use astyle for C formatting 2021-03-15 15:37:08 +01:00
Harald Hoyer 0850cf532d style(install): use block for the FOREACH macros 2021-03-15 15:37:08 +01:00
Harald Hoyer 9bc5282e30 style: `make indent` for C 2021-03-13 20:10:43 +01:00
Zoltán Böszörményi ddcdee9147 fix(dracut-install): allow globbing for multiple sources
Signed-off-by: Zoltán Böszörményi <zboszor@pr.hu>
2021-02-09 07:09:28 +00:00
Daniel Molkentin 1a5845b45f dracut-install: Globbing support for resolving "firmware:"
Implements #849
2020-11-18 14:11:30 +01:00
Daniel Molkentin ee9b9b1241 dracut-install: fix edge-case regression with weak modules
This was introduced with 6dafdda4a6, but
is actually caused by the fact that modules that have already been
installed cause dracut_install() to return without adding the module
to the hashmap. This can happen if an earlier-run dracut module chose
to install the same module. Now modprobe statements like:

softdep usb_storage post: uas
softdep uas pre: usb_storage

(which look weird, but are perfectly valid), cause
dracut_install() to enter an infinite recursion if and only if
at least one of the files has previously been installed by another
module.

Fix this by also adding already installed modules to the hashmap.
2020-10-02 15:49:09 +02:00
David Tardon 4916dfc2b9 dracut-install: ignore bogus preload libs
If there are any nonexistent libraries listed in /etc/ld.so.preload, ldd
prints error messages like:

ERROR: ld.so: object '/usr/lib64/libfoo.so.1' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.

This causes resolve_deps() to return error, which leads to symlinks
(like usr/bin/awk) not being copied into the initrd.
2020-10-02 15:34:40 +02:00
Lukas Nykryn 6dafdda4a6 install: also install post weak dependencies of kernel modules 2020-07-02 16:06:44 +02:00
Lucas C. Villa Real 3d2a6d29d4 dracut_mkdir(): create parent directories as needed. 2020-03-02 14:48:11 +01:00
Harald Hoyer 93be2bc6ab add DRACUT_NO_XATTR global environment variable
Useful, if you know, that those can't be copied anyway.
2020-02-27 13:49:21 +01:00
Daniel Cordero 1bef2934d7 dracut-install: fetch kernel modules from kmoddir
dracut, when passing --kmoddir, would only install modules that exist at
the same location as it will appear in the initramfs.

For most (possibly all) outputs, the output path would be /lib/modules,
so previously all kernel modules must be copied there or the module
installation silently fails.

Now use the original path variable, and install to the shortened path
variable (as calculated by kerneldirlen).

Note: This means that the argument to --kmoddir (and the modules filetree)
should be a directory that ends in 'lib/modules/$kernelversion'.
2020-01-27 09:02:46 +01:00
Böszörményi Zoltán a01204202b Allow running on a cross-compiled rootfs
For the shell scripts, new environment variables were introduced.

dracutsysrootdir is the root directory, file existence checks use it.

DRACUT_LDCONFIG can override ldconfig with a different one that works
on the sysroot with foreign binaries.

DRACUT_LDD can override ldd with a different one that works
with foreign binaries.

DRACUT_TESTBIN can override /bin/sh. A cross-compiled sysroot
may use symlinks that are valid only when running on the target
so a real file must be provided that exist in the sysroot.

DRACUT_INSTALL now supports debugging dracut-install in itself
when run by dracut but without debugging the dracut scripts.
E.g. DRACUT_INSTALL="valgrind dracut-install or
DRACUT_INSTALL="dracut-install --debug".

DRACUT_COMPRESS_BZIP2, DRACUT_COMPRESS_LBZIP2, DRACUT_COMPRESS_LZMA,
DRACUT_COMPRESS_XZ, DRACUT_COMPRESS_GZIP, DRACUT_COMPRESS_PIGZ,
DRACUT_COMPRESS_LZOP, DRACUT_COMPRESS_ZSTD, DRACUT_COMPRESS_LZ4,
DRACUT_COMPRESS_CAT: All of the compression utilities may be
overridden, to support the native binaries in non-standard places.

DRACUT_ARCH overrides "uname -m".

SYSTEMD_VERSION overrides "systemd --version".

The dracut-install utility was overhauled to support sysroot via
a new option -r and fixes for clang-analyze. It supports
cross-compiler-ldd from
https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f

DRACUT_INSTALL_PATH was introduced so dracut-install can work with
a different PATH. In a cross-compiled environment (e.g. Yocto), PATH
points to natively built binaries that are not in the host's /bin,
/usr/bin, etc. dracut-install still needs plain /bin and /usr/bin
that are relative to the cross-compiled sysroot.

The hashmap pool allocate_tile/deallocate_tile code was removed
because clang-analyze showed errors in it. hashmap_copy was removed
because it wasn't used and clang-analyze showed errors in it.

DRACUT_INSTALL_LOG_TARGET and DRACUT_INSTALL_LOG_LEVEL were
introduced so dracut-install can use different settings from
DRACUT_LOG_TARGET and DRACUT_LOG_LEVEL.

Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
2019-10-25 11:58:58 +02:00
Takashi Iwai 999cfa8458 dracut-install: Support the compressed firmware files correctly
The compressed firmware support was supposed to be already
implemented, but it didn't work as expected in the end, because dracut
moved to use dracut-install binary.  This patch adds the support of
XZ-compressed firmware installation to dracut-install for fixing the
missing piece.

At best the firmware files should be uncompressed in initrd, but this
patch simply copies the compressed file as-is, as a quick workaround.

BugLink: https://bugzilla.suse.com/show_bug.cgi?id=1146769
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-08-26 14:57:37 +02:00
Lukas Nykryn fc141f2286 install: string_hash_func should not be fed with NULL
If kmod_module_get_path returns NULL, we should skip that entry,
the hash function does not like NULL pointers.
2019-02-15 08:52:58 +01:00
Harald Hoyer c38f9e980c
install/dracut-install.c: install module dependencies of dependencies 2018-12-04 10:03:31 +01:00
Mike Gilbert 6d886bb74d dracut-install: simplify ldd parsing logic
The previous logic would not handle absolute paths on the left side of
the "=>" properly. For example, on Gentoo ARM64, ldd outputs this:

	/lib/ld-linux-aarch64.so.1 => /lib64/ld-linux-aarch64.so.1

At runtime, the kernel tries to load the file from /lib, and fails if we
only provide it in /lib64.

Instead of looking for the first slash after the "=>", just look for the
first slash, period. This would fail if we somehow had a relative path
on the left side (foo/libbar.so), but I'm not aware of any binaries that
would contain such an entry in DT_NEEDED.

Bug: https://bugs.gentoo.org/667752
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
2018-10-09 13:38:47 +02:00
Alexander Tsoy 838f22259a install: avoid non-portable __WORDSIZE
Lets not unnecessarily rely on __WORDSIZE, which is not clearly specified
by any spec. Use explicit size comparisons if we're not interested in the
WORDSIZE, anyway.

Patch ported from systemd.
(commit 8507eb20b64010b26f23822cbf442bb0bf96511c)

Original-patch-by: Emil Renner Berthing <systemd@esmil.dk>
Bug: https://bugs.gentoo.org/602122
2018-09-10 09:45:22 +02:00
Harald Hoyer e331e06a39 dracut-install: skip modules with empty path
if kmod_module_get_path(module) returns NULL, skip the module
2018-07-18 12:42:02 +02:00
Jeremy Linton 4cdee66c8e dracut-install: Support modules.softdep
Dracut uses the module deps to determine module dependencies
but that only works for modules with hard symbolic dependencies.
Some modules have dependencies created via callback API's or other
methods which aren't reflected in the modules.dep but rather in
modules.softdep through the use of "pre:" and "post:" commands
created in the kernel with MODULE_SOFTDEP().

Since in dracut we are only concerned about early boot, this patch
only looks at the pre: section of modules which are already being
inserted in the initrd under the assumption that the pre: section
lists dependencies required for the functionality of the module being
installed in the initrd.

Signed-off-by: Jeremy Linton <lintonrjeremy@gmail.com>
2018-07-03 13:36:26 +02:00
Harald Hoyer 731b37e929 dracut-install.c: untabify 2018-05-07 15:23:04 +02:00
Harald Hoyer 8ad3215590 don't error out, if no modules were installed
dracut-install … -m -s drm_crtc_init =drivers/staging
should not return an error, if no module was found in =drivers/staging

https://bugzilla.redhat.com/show_bug.cgi?id=1575527
2018-05-07 15:21:35 +02:00
Harald Hoyer 6c7776e344 dracut-install: strdup() kmod_module_get_name() string
otherwise it can't be used later on after freeing the context.

Should resolve https://bugzilla.redhat.com/show_bug.cgi?id=1536609
2018-01-23 14:09:31 +01:00
Harald Hoyer a13e97e511 dracut-install: remove double "//" in path names
makes relative symlinks shorter
2017-11-30 15:07:48 +01:00
Harald Hoyer 2c9bcac113 dracut-install: char* -> const char* 2017-10-10 13:39:17 +02:00
Artem Savkov ef84ce2521 dracut-install: fix relative paths in --kerneldir
kerneldirlen is used to modify absolute path returned by
kmod_module_get_path() while it is calculated on user-supplied
--kerneldir argument which can be a relative path.

Use kmod_get_dirname() to convert user-supplied path to the same format
as used by kmod_module_get_path().

This also allows to get rid of now useless strcmp checks that seem to
imply that /lib and /usr/lib are linked which is not always true.
2017-09-21 11:27:23 +02:00
Harald Hoyer 2b909b9a4b dracut-install: fixed hostonly modules hashmap_put 2017-08-10 09:20:35 +02:00
Harald Hoyer ed25fb0e91 dracut-install: fixed typo 2017-08-10 09:20:35 +02:00
Harald Hoyer 3ad12c7be8 Check all modalias files in /sys/devices for modules
and add the corresponding kernel modules to the host module list

https://bugzilla.redhat.com/show_bug.cgi?id=1467427
2017-07-07 15:55:55 +02:00
Harald Hoyer 076fcd1652 dracut: only copy xattr, if root
otherwise cp complains a lot about not being able to copy xattrs
2017-01-18 10:38:00 +01:00
Harald Hoyer be5025bf55 dracut-install: install kernel modules to /lib/modules/$kernelversion
Specifying a different kernel module directory with --kmoddir would
result in the same directory being the destination directory.

Strip everything before the "/lib/modules" for the destination dir.

https://github.com/dracutdevs/dracut/issues/194
2017-01-16 14:27:39 +01:00
Stefan Berger 61c761bc2c dracut-install: preserve extended attributes when copying files
Preserve extended attributes when copying files using dracut-install.

The copying of extended attributes avoids file execution denials when
the Linux Integrity Measurement's Appraisal mode is active. In that mode
executables need their file signatures copied. In particular, this patch
solves the problem that dependent libaries are not included in the
initramfs since the copied programs could not be executed due to missing
signatures. The following audit record shows the type of failure that
is now prevented:

type=INTEGRITY_DATA msg=audit(1477409025.492:30065): pid=922 uid=0
 auid=4294967295 ses=4294967295
 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
 op="appraise_data" cause="IMA-signature-required"
 comm="ld-linux-x86-64"
 name="/var/tmp/dracut.R6ySa4/initramfs/usr/bin/journalctl"
 dev="dm-0" ino=37136 res=0

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-10-25 22:05:55 +02:00
Harald Hoyer bb47ec5499 dracut-install: fallback to non-hostonly mode if lsmod fails
if libkmod fails to get the list of loaded modules, fallback
to non-hostonly mode, to at least try to assemble a working initrd.
2016-10-13 09:19:29 +02:00
Harald Hoyer 24113c3a11 dracut-install.c: really add a "/" inbetween destdir and target
using dracut-install with

find . -print0 | xargs dracut-install -D /tmp/test -a

resulted in /tmp/test./.... files
2016-07-14 13:54:04 +02:00
Harald Hoyer eab32bda80 dracut-install: make use of _cleanup_ macros and improve hostonly check
If a module is renamed or another module takes care of the old one,
all of the alias strings have to be checked against the current set of
loaded modules.

This is still incomplete, because to be absolutely correct, all the
/sys/*...*/modalias files would have to be checked, if they match the
modules alias strings.
2016-04-15 16:48:13 +02:00
Harald Hoyer b14b039e90 dracut-install: add --help documentation 2016-04-14 11:51:36 +02:00
Harald Hoyer fe6e0c23ad dracut-install: simplify error logic
error out early, if "--optional" is not set
2016-04-13 13:56:52 +02:00
Harald Hoyer 8d9ab2755d Fix regressions with dracut-install with kernel modules
Make sure, the same modules are installed as before.
2016-04-13 11:47:20 +02:00
Harald Hoyer 794b2d2c75 Use dracut-install to install kernel modules
dracut-install can now install kernel modules and their corresponding
firmware files.
2016-04-11 16:32:10 +02:00
Ville Skyttä 9430ae301e Do not use deprecated egrep/fgrep 2016-03-28 11:38:34 +03:00
Harald Hoyer b127294def dracut-install: catch ldd message "cannot execute binary file" 2016-03-14 10:59:29 +01:00
yuwata fc212358da install blob: fix typos in usage. 2015-09-07 18:00:16 +09:00
xtraeme 6964169368 Portability fixes:
- Use uid_t not __uid_t.
- Define _GNU_SOURCE for cpu_set_t and others.
- Include string.h for strncmp().
- Detect musl's ldd error message.
2015-06-02 11:17:13 +02:00
Harald Hoyer 37383f7123 add "--loginstall <DIR>" and loginstall="<DIR>" options
loginstall specifies a directory, in which dracut-install records all
files, which were installed from the host system to the initramfs.

Use case is e.g. to create a list of packages to watch for updates, to
maybe trigger a recreation of the initramfs.
2014-09-11 16:42:36 +02:00
Harald Hoyer 967cc19ab1 remove all vim and emacs code format comments 2014-08-29 13:38:47 +02:00
Harald Hoyer 6770af96d4 add kate and emacs per directory config files 2014-08-29 13:38:47 +02:00
Harald Hoyer e7ba1392e1 install: add more error handling
also limit local variable scopes
and remove bogus checks to negativity of unsigned vars
2014-08-29 13:37:40 +02:00
Harald Hoyer 26cd262a6a install: add -H flag for install
inst* functions and dracut-install now accept the "-H" flag, which
logs all installed files to /lib/dracut/hostonly-files. This is used
to remove those files, if rd.hostonly is given on the kernel command line.
2014-06-25 11:42:53 +02:00
Harald Hoyer 93f44f28a2 dracut-install.c: "make indent" 2014-01-24 15:31:26 +01:00