Commit Graph

323 Commits (c6a2ebffe5812bf45a17d90208d9bb1044b6dba0)

Author SHA1 Message Date
Harald Hoyer dfe2247a43 dracut.sh: add check for invalid configuration files
Emit a warning about possible misconfigured configuration files, where
the spaces around values are missing for +=""

Better report a possible source of problems. We can fix annoying false
positives later.
2020-03-18 16:34:35 +01:00
Dusty Mabe 97a931c7d9 don't prefer $TMPDIR over --tmpdir
Ability to use `$TMPDIR` was introduced in bc1e69b but
causes the `--tmpdir` option on the command line to be
ignored. Switch to only using `$TMPDIR` if `--tmpdir`
wasn't specified.
2020-03-16 14:45:01 +01:00
Topi Miettinen bc1e69b691 Use TMPDIR if available
Use environment variable TMPDIR (typically /run/user/$UID) as default
temporary directory, if available. This should be more private
location than /var/tmp. Path specified with --tmpdir is takes
precedence over TMPDIR and /var/tmp is still used as last resort if
neither TMPDIR is set nor --tmpdir is used.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
2020-03-06 11:40:00 +01:00
Martin Wilck 0386e46277 dracut.sh: don't call fsfreeze on subvol of root file system
dracut.sh already doesn't call fsfreeze if the output file is on
the root file system. For btrfs, however, this is not sufficient.
Because fsfreeze is a superblock operation, and all btrfs subvolumes
share the same superblock, fsfreeze may freeze the entire system
if the subvolume on which the output file is written and / are
subvolumes of the same file system. Avoid this by comparing file
system UUIDs for btrfs.

Fixes: de576db3c2 ("call fsfreeze(8) on /boot to flush initramfs data & metadata to media")
2020-03-06 11:37:16 +01:00
Daniel Molkentin 5b1d8bcc58
Merge branch 'master' into regenerate_all 2020-03-03 19:25:16 +01:00
Topi Miettinen ecbdff68af Don't resolve libraries lazily if tmpdir is mounted with 'noexec'
If the temporary directory for images is mounted with 'noexec', dracut
would construct unbootable images because most dynamic libraries
aren't installed. Avoid this by not resolving library dependencies
lazily if the temporary directory is mounted with 'noexec'.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
2020-03-02 09:56:26 +01:00
Donovan Tremura 4237aeb040 Support the EFI Stub loader's splash image feature.
Checks if `uefi_splash_image` exists in `dracutsysroot` if not unset
`uefi_splash_image`. Alternate Value parameter expansion adds section-vma
for splash image to EFI stub loader when the path to image is valid and
not an empty file.

I did not test on other distributions, but on Arch Linux the `systemd`
package includes a splash image at the path
`/usr/share/systemd/bootctl/splash-arch.bmp`. Perhaps, if this is a
common practice, a default image could be gathered from that directory.

It is required that the image be in bitmap (`.bmp`) format according to
`splash.c`.

The code for `stub.c` and `splash.c` can be found at:
https://github.com/systemd/systemd/blob/master/src/boot/efi/stub.c
https://github.com/systemd/systemd/blob/master/src/boot/efi/splash.c
2020-02-20 11:03:30 +01:00
Renaud Métrich cdc9cd0e41 dracut.sh: added help for --regenerate-all 2020-02-13 11:37:13 +01:00
Daniel Cordero f668e7174e dracut.sh: check kmoddir is properly formed
Due to the way dracut-install handles modules from custom kmoddirs, add
a test that ensures the kmoddir argument seems sane.

In addition to erroring out, provide some guidance on how to proceed, as
well as a method of skipping the test via environment variable.
2020-01-27 09:02:46 +01:00
Jonas Witschel d613d88dd2 ucode: use microcode found in packed cpio images
Some distributions (Arch, Gentoo) ship prepacked microcode images. These
are cpio images that follow the structure specified in the Linux kernel
documentation (x86/microcode.rst, "Early load microcode"), the same
structure dracut uses for its early microcode images.

In case of Arch Linux, the microcode for Intel CPUs is currently only
available in this packed form, /usr/lib/firmware/intel-ucode does not
exist. This commit adds a way to make use of these images on such
systems by unpacking them to the early cpio directory. (Note that the
packed image cannot be used directly since dracut might need to add ACPI
tables to the early initramfs.)

This approach has the drawback that it is not possible to control the
selection of CPUs to be included in the microcode file in host-only
mode, so we only try it as a last ressort if no unpacked microcode could
be found in fw_dir.

The list of possible file names for the packed microcode image is taken
from GRUB (cf. GRUB_EARLY_INITRD_LINUX_STOCK), but can be adapted by
setting "early_microcode_image_name" (and "early_microcode_image_dir")
in a dracut configuration file.
2020-01-24 09:06:32 +01:00
Böszörményi Zoltán 0595a79b19 Fix version reported by dracut --help
Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
2019-10-25 11:58:58 +02:00
Böszörményi Zoltán 9d88e89350 Set systemdutildir correctly
Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
2019-10-25 11:58:58 +02:00
Böszörményi Zoltán b552d364a3 Handle -r / --sysroot option in dracut.sh
It was documented but not implemented.

Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
2019-10-25 11:58:58 +02: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
Kairui Song 89bc1aa324 Fine tune mksquashfs options for squash module
Drop some unneeded metadata in the squash image, and print the error
message if something went wrong.

Signed-off-by: Kairui Song <kasong@redhat.com>
2019-10-25 11:52:05 +02:00
Daniel Molkentin feebf17187 ucode: properly include early only ucode
Intel has notified us that some microcode updates are not safe
to be applied during runtime. To accomodate for that, microcode
files shipped by SUSE and openSUSE have an '.early' postfix such
that triggering

/sys/devices/system/cpu/microcode/reload

from a booted system cannot pick up the ucode by accident, while
still allowing the code to be picked up during initrd time.

This change is needed to make this scheme work also in a hostonly
situation.

Currently, this affects only 06-4f-01, which is now 06-4f-01.early.

If a distro does not change the filename, the behavior does not
change.

Reference: osc#1098915
2019-10-25 11:39:16 +02:00
Kairui Song a69e6c4eae Only generate hostonly-kernel-modules list in strict mode
Fixes #617.
2019-10-23 14:33:36 +02:00
Jonas Witschel 0a01086456 dracut.sh: suppress "ignored null byte in input" warning
Since Bash 4.4, command substitutions containing null bytes produce a
warning of the form

/usr/sbin/dracut: line 1958: warning: command substitution: ignored null byte in input

Remove the trailing null byte from the UEFI kernel command line file
before printing it to suppress this warning.
2019-09-03 11:28:56 +00:00
Renaud Métrich 7a3d661971 Print an error if included item ('-i' option) doesn't exist or is neither a directory nor a regular file
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
2019-08-29 13:46:34 +00:00
Kairui Song 6a74c03b4a dracut.sh: Adjust squash and strip order
Previously with squash module, some binaries will be reinstalled, but
stripping happens before that so new installed binaries is not stripped.
So adjust the squash and strip order, ensure new installed binaries are
stripped just the same way with the old binaries.

Also split squash into two stage to make the split easier, move the
squash temp dir into initdir so stripping will cover that too,
and print more usefule message.

Signed-off-by: Kairui Song <kasong@redhat.com>
2019-08-09 13:11:47 +02:00
Jonas Witschel 12f023ab03 Replace $(arch) by $(uname -m) 2019-07-19 16:25:03 +02:00
Дамјан Георгиевски c8b35bf96a move setting the "systemdutildir" variable before it's used
on line 1086 it's used to check for the uefi_stub:
"${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"

so it needs to be defined before that
2019-07-19 16:23:57 +02:00
Jonas Witschel 305c6f91bb dracut.sh: fix EFI directory if ESP is mounted to /efi
The EFI executables produced by dracut --uefi must be placed in the
subdirectory /EFI/Linux of the EFI system partition (ESP) according to
the Boot Loader Specification, see
https://systemd.io/BOOT_LOADER_SPECIFICATION#logic

This is done correctly for the mount points /boot and /boot/efi, but for
the mount point /efi, the files are placed in /efi/Linux instead of the
correct /efi/EFI/Linux. This commit fixes the directory so that the EFI
executables are picked up correctly by conforming boot loaders.

Apart from complying to the specification, the change is also in line
with the commit message of 5c57209ba5
("dracut.sh: add default path for --uefi") which introduced this feature
as well as the documentation in dracut.8.asc.
2019-07-19 16:23:24 +02:00
Max Resch 5a962b5939 add support for creating secureboot signed UEFI images 2019-07-19 16:09:41 +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
Kairui Song f6bbd024d9 squash: fix and simplify required_in_root
If required target is a symbol link, create the link then following the
link. If it's a directory, create new directory, else just move it.

Signed-off-by: Kairui Song <kasong@redhat.com>
2019-07-19 15:38:54 +02:00
Kairui Song ab703f44b4 squash: squash systemd binary and udevadm
systemd binary and udevadm are not needed to be outside the squash
image. Some binaries are kept outside because they are required before
mounting the image, or after umounting the image (when switching root),
or they may block umounting the image. But we are using lazy umounting,
so actually nothing will block the umount.

Keep more binaries outside the squash image won't hurt but cost extra
memories, the idea of squash image is to save memory usage.

So, there is no reason to keep udevadm outside, that should be a debug
left over. For systemd binary, it's running when switch root happens,
But we have lazy umounted the image and overlay, once systemd process
exec the new systemd in new root, everything will be cleared by kernel.

Also tidy up the comment make it less confussing.

Signed-off-by: Kairui Song <kasong@redhat.com>
2019-07-19 15:38:54 +02:00
Kairui Song a0d9ad6f70 dracut.sh: record the actual hostonly modules for hostonly mode
Previous in commit 7047294, dracut will include the loaded kernel module
list in initramfs, so other tools could check if the loaded kernel
module is changed and rebuild the host only initramfs in case some
module required to boot the machine is missing due to host only install.

It's better to use modalias list generated by dracut-install, that
list includes the device modalias list combined with current loaded
kernel module list. In this way, if any kernel module is yet to be
loaded when the initramfs is built, or got unloaded by accident the
module list will not change. This make the list more stable over
initramfs builds.

Signed-off-by: Kairui Song <kasong@redhat.com>
2019-07-19 15:38:13 +02:00
Hongxu Jia dddcb80945 dracut.sh: Fix udevdir detection
In commit [9d1b81c dracut.sh: improve udevdir and systemdutildir
fallback logic] , it checked a common binary `collect' to location
udevdir.

But upstream systemd drop binary `collect' since systemd v240
[a168792c2d]

So check binary `ata_id' to instead.

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
2019-07-19 11:01:32 +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
Attila Bruncsak 7e944c77c0 the strip command should avoid changing the file modification time 2018-12-20 17:06:26 +01:00
Kairui Song a60af53413 squash: unsquash the root image instead of mounting it on shutdown
When building squash image, squash module forgot to install the new
shutdown.sh, and the shutdown hooks are always skipped on ordinary
shutdown if squash module is enabled.

The new shutdown.sh will remount the squash image and then everything
will just work, but currently re-mounting the squash image on shutdown
may have selinux problem and make the system hang, and there is no
easy way to fix it.

So skip fixing the shutdown.sh not being install problem, instead
just drop the new shutdown.sh, and unsquash the image on ordinary
shutdown, which is safer and should always work.

Signed-off-by: Kairui Song <kasong@redhat.com>
2018-11-12 09:04:14 +01:00
Pedro Monreal f18d069d46 Fixed some SUSE specific typos and outputs 2018-11-08 14:43:08 +01:00
Pedro Monreal db4d6bb42c Added space in Resolving executable dependencies done as in the rest of the messages 2018-10-09 13:41:55 +02:00
Kairui Song 095e1f37c4 Add support for building a squashed initramfs
With all files stored in ramfs, and most of them are not compressed,
the initramfs will take up a lot of memory. Besides, if the file number
is large, each file will waste some memory due to page fragmetation.
This is due to ramfs' design, at least one page will be allocated for
one file however small the file is. On machine with large page size,
this will become worse and waste too many memory.

One approach to reducing the memory usage is to reduce the number of
files that got directly loaded into the root ramfs, and compress files
by put most files will into a read-only squash image and keep a minimum
set of executable and libraries outside as the loader for the squash
image. After the squash image is mounted, the real 'init' will be
executed and then everything behaves as usual.

This patch will introduce a '99squash' module which will never be
included by default. User can force add it, and if it is included,
dracut will perform some extra steps before creating the final image:

For now, "/etc" and "/usr" will be moved into the squashfs image.
"/init" will be renamed to "/init.stock" and replaced by "/init.squash".
Files and folders need to be accessible before mounting the image will
be still avaliable at their original place. And due to squashfs is
readonly, an overlayfs layer will be created on top of squashfs mount
point, as many dracut module require readwrite access to "/etc" and
"/usr", "init.squash" will ultimately call "/init.stock".

An extra systemd service will be installed. This service will umount all
squashfs related mount points right before switch-root to release
resources properly. This service will not actually do anything if
switch-root is not used.

This is very helpful when mem resource is very limited, like Kdump.
According to my tests, this squash module can help save about 35MB of
memory with 64K page size, or about 15MB with 4K page size on an
ordinary kdump capture routine. This module could also help reduce
memory usage for normal boot up process.

Won't change any behavior if squash module is not enabled.

Signed-off-by: Kairui Song <kasong@redhat.com>
2018-09-21 10:32:04 +02:00
Harald Hoyer 3111988680 dracut.sh: remove bogus dir removal for --rebuild 2018-08-16 09:19:52 +02:00
Kairui Song 7047294617 Record loaded kernel modules when hostonly mode is enabled
A hostonly image will not include every possibly required kernel module,
so if any hardware or configuration changed, the image may fail to boot.

One way to know if there are any hardware change or configuration change
that will require an image rebuild or not is to check the loaded kernel
module list. If the loaded kernel module list differs from last build
time, then the image may require to be rebuilt.

This commit will let dracut record the loaded kernel module list when
the image is being built, so other tools or services can compare this
list with currently loaded kernel modules to decide if dracut should be
called to rebuild the image.

To retrieve the loaded kernel modules list when an image is built, use
lsinitrd command:

lsinitrd $image -f */lib/dracut/loaded-kernel-modules.txt
2018-07-18 11:50:18 +02:00
Mike Gilbert 9d1b81c0d1 dracut.sh: improve udevdir and systemdutildir fallback logic
Check for a common binary in systemdutildir. This resolves an issue on
split-usr systems, where it is common to have both /lib/systemd[/system]
and /usr/lib/systemd[/user] present.

Check for systemd-udevd specifically, since some distros (Gentoo) allow
udev to be installed without the rest of the systemd stack.

Similar logic is applied to udevdir simply for consistency.
2018-07-05 13:57:43 +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
Daniel Molkentin d00cfc2a7b Remove obsolete prelinking functionality 2018-06-14 12:58:59 +02:00
Renaud Métrich c1c78f8a91 Harden dracut against BASH_ENV environment variable
When dracut silently produces a broken initramfs, then the system will
likely not boot and this can be very problematic. Typical use case is
after the kernel has been updated.

It appears that dracut is not protected against the BASH_ENV variable,
causing various scripts called by dracut to possibly fail or provide
wrong output (e.g. "ldd" is one of these).
Having a broken output for "ldd" makes the generated initramfs be not
usable, typically because vital binaries will be missing (e.g.
"awk", "udevadm", ...).

Note: because the shebang line cannot contain more than one argument,
the '--norc' option had to be removed. IMHO, it was useless anyway.

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
2018-06-08 10:48:45 +02:00
Harald Hoyer f6e777ec4b cleanup empty ldconfig_paths directories
https://bugzilla.redhat.com/show_bug.cgi?id=1324746
2018-05-22 09:51:12 +02:00
Harald Hoyer bfa4e45fa7 s/find_btrfs_devs/btrfs_devs 2018-05-07 10:26:45 +02:00
Colin Walters 740e41b843 Suppress sync/fsfreeze if not running on a live system
It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
and there's no reason to sync, and *definitely* no reason to fsfreeze.

Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
globally.  See e.g. 8642ef5ab3
2018-05-02 17:44:45 +02:00
Thomas Backlund b25ef46f93 Enable 'early_microcode' by default
We initially enabled it for Haswell TSX bug (mga#16657)

Now there is also Meltdown and Spectre security issues,
and more microcode issues will most likely show up...

So the sane default for 'early_microcode' to have it enabled,
as theese changes must be done early in boot process to take
effect as intended.

Update documentation accordingly.

Reference: https://bugs.mageia.org/show_bug.cgi?id=16657

Signed-off-by: Thomas Backlund <tmb@mageia.org>
Signed-off-by: Neal Gompa <ngompa13@gmail.com>
2018-01-18 05:30:28 -05:00
Harald Hoyer 8e7d0856d0
Merge pull request #351 from danimo/91zipl
Add 91zipl, which adds support for indirect booting on s390.
2018-01-12 09:34:08 +01:00
Thomas Renninger 33260dac6e Add /boot/zipl to host devs if it is a mount point
bnc#892187

Signed-off-by: Thomas Renninger <trenn@suse.de>
2018-01-11 11:40:06 +01:00
Yu Watanabe 7bc681fd88 dracut.sh: do not invoke fsfreeze on EFI System Partition
When the system boots with EFI, then initrd image is stored
on EFI System Partition. Thus dracut always warn about the
failure to invoke fsfreeze on the partition.
This prevents to run fsfreeze on ESP and suppress the warning.
2018-01-11 13:55:14 +09:00
Harald Hoyer 577f109243
Merge pull request #339 from danimo/fix_include_parsing
Fix parsing of "-i" and "--include"
2018-01-08 13:31:55 +01:00