Commit Graph

40 Commits

Author SHA1 Message Date
Zoltán Böszörményi
b955dbf4a9 fix(dracut-init.sh): make inst_libdir_file work with dracutsysrootdir set
Signed-off-by: Zoltán Böszörményi <zboszor@pr.hu>
2021-01-21 16:33:18 +00:00
Colin Walters
6b8ee4fc37 Don't print when a module is explicitly omitted (by default)
dracut builds today are fairly verbose to start, but on top of
that many of the messages tend to liberally use the
exclamation point `!` which calls attention to them.

I see these a lot when looking at rpm-ostree build logs
and it'd be nicer if we were quiet when there wasn't
an actual problem.

In this specific case, if the builder is explicitly adding
`--omit=foo`, there's no reason for us to say:

`dracut: dracut module 'foo' will not be installed, because it's in the list to be omitted!`

We already print the command line to start, so the information
is there.

Demote this message to debug.
2020-11-14 19:38:29 +01:00
Mikhail Novosyolov
f84ad9e062 Allow $DRACUT_INSTALL to be not an absolute path
/usr/sbin/dracut-install is a symlink:
$ file /usr/sbin/dracut-install
/usr/sbin/dracut-install: symbolic link to ../lib/dracut/dracut-install

It resulted to "dracut-install not found" error:

+++ for p in $DRACUT_PATH
+++ [[ -L /sbin/dracut-install ]]
+++ [[ -x /sbin/dracut-install ]]
+++ for p in $DRACUT_PATH
+++ [[ -L /bin/dracut-install ]]
+++ [[ -x /bin/dracut-install ]]
+++ for p in $DRACUT_PATH
+++ [[ -L /usr/sbin/dracut-install ]]
+++ printf '%s\n' dracut-install
+++ return 0
++ DRACUT_INSTALL=dracut-install
++ [[ -n dracut-install ]]
++ [[ -n dracut-install ]]
++ DRINSTALLPARTS=0
++ for i in $DRACUT_INSTALL
++ DRINSTALLPARTS=1
++ [[ 1 = 1 ]]
++ [[ -x dracut-install ]]
++ dfatal 'dracut-install not found!'
++ set +x
dracut: dracut-install not found!

[ -x <not a path to file> ] is not correct and will always be false.
But actually it is available. Let's just allow it to be not an absolute path.
Maybe some other places can be improved to avoid DRACUT_INSTALL being not an absolute path.

Signed-off-by: Mikhail Novosyolov <m.novosyolov@rosalinux.ru>
2020-08-05 17:46:30 +02: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
Mikhail Novosyolov
718aefda13 Ensure that udevadm --version reported an integer
If it is not an integer, further script will fail unexepectedly.
2019-11-05 14:26:14 +01:00
Mikhail Novosyolov
6e761674ad Fail if udevadm could not be run
Fixes: #668
2019-11-05 14:26:14 +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
Daniel Molkentin
b4769b332d dracut-init.sh: remove obsolete for_each_kmod_dep() 2019-10-22 13:50:36 +02:00
Takashi Iwai
f4e38c0da8 dracut-init.sh: Nuke unused install_kmod_with_fw function
Kill the no longer used function, so that anyone won't be confused and
try to modify this function in future.

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
Daniel Molkentin
b6b1bf9202 Consollidate the qemu virtualization detection
Eventually, we could add a full virt detection routine.
This would be useful e.g. to determine inclusion of
ucode for hostonly setups.
2019-07-19 16:26:42 +02:00
Takashi Iwai
3e53195bce dracut-install: Add support for compressed kernel modules
When a module is compressed, uncompress it before packing into initrd.
Since initrd is already compressed, it makes no sense to put the
compressed module files.

The patch contains a slight refactoring and adds a helper function to
get the command for uncompressing a file per extension.
2019-07-19 16:17:35 +02:00
Harald Hoyer
86f4dd0273
Merge branch 'optimization' of https://github.com/ryncsn/dracut into ryncsn-optimization 2019-07-19 15:48:22 +02:00
Kairui Song
19e5758590 squash: also squash systemctl if switch-root is not needed
systemctl need to be accessible on switch-root, but we unmount the
squash image on switch-root, so it will fail. systemctl depends on a lot
of libraries, squash them can save more RAM. So allow modules
(eg. kdump) to tell dracut that switch-root will be intercepted,
then we don't need to take care of that.

Signed-off-by: Kairui Song <kasong@redhat.com>
2019-07-19 15:38:54 +02:00
Takashi Iwai
dc86c12c45 dracut-install: Add support for compressed firmware files
The upcoming kernel will have a support for loading compressed
firmware files, and this patch corresponds to that kernel change.
When a firmware file with the extra .xz extension is found, dracut
copies to initrd as fallback.  Since initrd itself is compressed, the
file is uncompressed in initrd beforehand.
2019-07-18 18:39:56 +02:00
Kairui Song
5916d31b24 dracut: let module handling function accept optional path option
Let the caller pass in the module path instead of try to find the module
path everytime. This helps optimize the overall runtime.

Test results (3 rounds) on Fedora 30 in KVM VM with 8 CPUs, 2G memory, HDD:

    $ time ./dracut.sh --local --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode 'strict' -o 'plymouth dash resume ifcfg' --mount '/dev/mapper/fedora-root /sysroot xfs defaults' --no-hostonly-default-device -f initramfs.img
    Before the commit:
    real    0m11.782s  |  real    0m11.505s  |  real    0m11.958s
    user    0m9.169s   |  user    0m9.218s   |  user    0m9.327s
    sys     0m10.839s  |  sys     0m10.829s  |  sys     0m10.925s

    After this commit:
    real    0m9.866s  |  real    0m9.580s  |  real    0m9.638s
    user    0m9.048s  |  user    0m9.142s  |  user    0m9.120s
    sys     0m7.411s  |  sys     0m7.775s  |  sys     0m7.745s

Test result of building a ordinary image:

    $ time ./dracut.sh --local --quiet -f initramfs.img
    Before the commit:
    real    0m34.697s  |  real    0m34.371s  |  real    0m35.122s
    user    0m27.608s  |  user    0m27.524s  |  user    0m27.705s
    sys     0m22.341s  |  sys     0m22.032s  |  sys     0m22.246s

    After the commit:
    real    0m31.914s  |  real    0m31.006  |  real    0m31.289ss
    user    0m27.315s  |  user    0m27.324  |  user    0m27.290ss
    sys     0m19.051s  |  sys     0m18.916  |  sys     0m19.022ss

This will have an ~2s speed up.

Signed-off-by: Kairui Song <kasong@redhat.com>
2019-02-22 15:51:40 +08:00
Harald Hoyer
8f77326479 dracut-init.sh: fix instmods with zero input
instmods < /dev/null

should not error
2018-07-05 13:39:46 +02:00
Kairui Song
a695250ec7 Introduce tri-state hostonly mode
Add a new option --hostonly-mode which accept an <mode> parameter, so we have a tri-state hostonly mode:

    * generic: by passing "--no-hostonly" or not passing anything.
               "--hostonly-mode" has no effect in such case.
    * sloppy: by passing "--hostonly --hostonly-mode sloppy". This
              is also the default mode when only "--hostonly" is given.
    * strict: by passing "--hostonly --hostonly-mode strict".

Sloppy mode is the original hostonly mode, the new introduced strict
mode will allow modules to ignore more drivers or do some extra job to
save memory and disk space, while making the image less portable.

Also introduced a helper function "optional_hostonly" to make it
easier for modules to leverage new hostonly mode.

To force install modules only in sloppy hostonly mode, use the form:

hostonly="$(optional_hostonly)" instmods <modules>

Signed-off-by: Kairui Song <kasong@redhat.com>
2018-07-05 09:14:02 +02:00
Lukas Nykryn
3aa37cafde all: fix issues found by shellcheck
Error: SHELLCHECK_WARNING:
/usr/lib/dracut/dracut-init.sh:939:20: error: Argument to implicit -n is always true due to literal strings. [SC2157]
  937|   dracut_kernel_post() {
  938|       for _f in modules.builtin.bin modules.builtin modules.order; do
  939|->         [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
  940|       done
  941|

Error: SHELLCHECK_WARNING:
/usr/lib/dracut/modules.d/98syslog/parse-syslog-opts.sh:18:12: error: This expression is constant. Did you forget a $ somewhere? [SC2078]
   16|       elif [ -e /sbin/syslogd ]; then
   17|           syslogtype="syslogd"
   18|->     elif [ /sbin/syslog-ng ]; then
   19|           syslogtype="syslog-ng"
   20|       else

Error: SHELLCHECK_WARNING:
/usr/lib/dracut/modules.d/90crypt/crypt-lib.sh:15:29: error: Since you double quoted this, it will not word split, and the loop will only run once. [SC2066]
   13|               strstr "$d" "${luks##luks-}" && return 0
   14|               if [ -n "$dev" ]; then
   15|->                 for _dev in "$(devnames $d)"; do
   16|                       [ "$dev" -ef "$_dev" ] && return 0
   17|                   done
2018-03-02 13:41:43 +01:00
Mark Fasheh
1f8a7ae799 dracut-emergency: optionally print fs help
Allow filesystem modules to install a fs-specific text file with
instructions on what to do when mount fails. This is printed when we go into
an emergency shell.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2018-01-08 14:14:05 +01:00
Harald Hoyer
d84f4687c3 dracut-init.sh: check for file $DRACUT_KERNEL_MODALIASES
and not for the directory
2017-07-07 15:59:31 +02:00
Harald Hoyer
db17ef6c4f dracut-init.sh: add the kernel directory to the --modalias generation 2017-07-07 15:58:02 +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
Martin Wilck
d13071d7a6 dracut-init.sh: fix typo 2017-03-09 21:57:27 +01:00
Harald Hoyer
647b521fc7 dracut: check for EUID instead of UID 2017-01-18 11:04:36 +01: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
7e51a94f5b Do not "cp" the selinux context
replace "cp -a" with $DRACUT_CP, so in case the selinux policy disallows
root to set the selinux context in /var/tmp, dracut does not fail.
2017-01-16 14:27:39 +01:00
Harald Hoyer
8e01095755 dracut-init.sh: set default firmware path, if not specified 2016-06-07 14:27:03 +02:00
Harald Hoyer
1901500187 move ln_r() to dracut-init.sh 2016-05-25 15:07:08 +02:00
Harald Hoyer
3f60444ec1 removed obsolete kernel module functions and host_modules variable
module_is_host_only()
find_kernel_modules_by_path()
find_kernel_modules()
2016-04-15 16:48:13 +02:00
Harald Hoyer
fa295f0bcd dracut_install: honor --silent flag 2016-04-15 15:25:27 +02:00
Harald Hoyer
9bb030c5d8 dracut-init.sh: beautify instmods() 2016-04-13 14:00:26 +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
Harald Hoyer
ff8f702689 dracut-init.sh: mark error messages with FAILED 2016-04-11 15:25:11 +02:00
Harald Hoyer
374ef3ed2b dracut-init.sh: Add file argument to sed's
fixup for 06a1d07690
2016-04-11 13:37:17 +02:00
Ville Skyttä
06a1d07690 dracut-init.sh: Simplify udev rule grepping 2016-03-28 12:09:06 +03:00
Ville Skyttä
9430ae301e Do not use deprecated egrep/fgrep 2016-03-28 11:38:34 +03:00
Harald Hoyer
456f299ab8 dracut-init.sh: libdir paths need dracut-function.sh 2015-11-13 14:20:54 +01:00
Harald Hoyer
07a081f352 dracut.sh: remove the concept of host_modalias
We can never gather enough information about compiled in modules, so
don't pretend to know and do smart decisions.
2015-11-13 13:40:38 +01:00
Harald Hoyer
561eb42f39 reduce dracut-functions.sh and add to dracut-init.sh
move all dracut specific functions to dracut-init.sh
2015-11-13 13:06:01 +01:00
Harald Hoyer
777f2db037 splitup dracut-init.sh from dracut-functions.sh
other tools want to source dracut-functions.sh without any mkdir side
effects.
2015-07-02 16:04:05 +02:00