Commit Graph

291 Commits (01ffcf342ae65984c655f10a2fd35019a492ee5c)

Author SHA1 Message Date
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
Fabian Vogt dcacd2b072 Fix parsing of "-i" and "--include"
- dracut replaced every instance of "-i" in the cmdline,
  even if it was part of a kernel image name, e.g. "vmlinuz-i"
- Fixes boo#908452

Signed-off-by: Fabian Vogt <fvogt@suse.com>

Adjusted to not support "dracut -ifoo bar", as this breaks expected
upstream behavior.
2018-01-08 10:43:46 +01:00
Harald Hoyer 29a9e92999
Merge pull request #331 from fcami/master-fsfreeze
call fsfreeze(8) on /boot to flush initramfs data & metadata to media
2017-12-19 15:35:18 +01:00
François Cami de576db3c2 call fsfreeze(8) on /boot to flush initramfs data & metadata to media 2017-12-19 14:47:11 +01:00
Fabian Vogt d53bb5c017 Fix possible hang in dracut
- Caused by add_drivers+=" " in dracut.conf (bsc#923116)

Signed-off-by: Fabian Vogt <fvogt@suse.com>
2017-12-19 00:04:35 +01:00
Harald Hoyer ed9281d6d1 dracut.sh: after doing the lazy resolve always install dependencies
Exit the lazy resolving mode after doing the lazy resolve, because there
won't be any lazy resolving anymore after this step.

Fixes https://github.com/dracutdevs/dracut/issues/152
Obsoletes https://github.com/dracutdevs/dracut/pull/225
2017-10-26 09:31:27 +02:00
Harald Hoyer faabcb2360 dracut.sh: quote sync file argument 2017-10-11 15:28:20 +02:00
Harald Hoyer 791d801689 dracut.sh: if /boot/vmlinuz-$version exists use /boot/ as output dir
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1475565
2017-10-10 10:30:44 +02:00
tpgxyz 7dbadcc749 add support for Zstandard 2017-09-05 01:23:38 +02:00
Ziyue Yang bd93e9287d dracut.sh: disable lsinitrd logging when quiet
Currently in Fedora/RedHat dracut installs its fedora.conf.example
as the default config file, in which sysloglvl is set 5. This leads
to maxloglvl=5 in dracut calls, making unnecessary lsinitrd calls
during initramfs builds by kdump.

This patch disables lsinitrd logging when --quiet option is given,
which is controlled by maxloglvl only before. This will speed up
dracut image building as the following if --quiet is used in kdump:

1) Before this patch
$ kdumpctl stop; touch /etc/kdump.conf; time kdumpctl start
kexec: unloaded kdump kernel
Stopping kdump: [OK]
Detected change(s) in the following file(s):
  /etc/kdump.conf
Rebuilding /boot/initramfs-4.13.0-0.rc1.git4.1.fc27.x86_64kdump.img
kexec: loaded kdump kernel
Starting kdump: [OK]
real    0m26.824s
user    0m9.958s
sys     0m15.106s

2) After this patch
$ kdumpctl stop; touch /etc/kdump.conf; time kdumpctl start
kexec: unloaded kdump kernel
Stopping kdump: [OK]
Detected change(s) in the following file(s):
  /etc/kdump.conf
Rebuilding /boot/initramfs-4.13.0-0.rc1.git4.1.fc27.x86_64kdump.img
kexec: loaded kdump kernel
Starting kdump: [OK]
real    0m20.420s
user    0m8.385s
sys     0m10.468s

Signed-off-by: Ziyue Yang <ziyang@redhat.com>
2017-08-23 11:23:34 +08:00
Xunlei Pang 5634a31156 rootfs-block/module-setup.sh: check root_devs in cmdline_rootfs()
In case of "--no-hostonly-default-device", we do not need
the root device, thus add this check.

Also fixed the stale "root_dev" export.

Signed-off-by: Xunlei Pang <xlpang@redhat.com>
2017-08-18 14:44:19 +08:00
Xunlei Pang 37f2fe55d1 dracut.sh: introduce "--no-hostonly-default-device" argument
Kdump doesn't need default host devices like root, swap, fstab, etc,
we only care about the dump target which can be added via "--mount"
or "--add-device". We met several issues that kdump kernel failed
due to one of those host devices added by dracut, additionally, the
needless devices(e.g. LVM) consume some appreciable amount of memory
which is more likely to cause OOM under memory-limited kdump.

So this patch introduced "--no-hostonly-default-device" to avoid
adding those default devices as host_devs.

Signed-off-by: Xunlei Pang <xlpang@redhat.com>
2017-08-18 09:58:08 +08:00
Ankit Kumar e316ae0e43 Sync initramfs after creation
If we trigger crash just after creating initramfs, sometimes it is
observed that initramfs is not written to disk causing the subsequent
boot to fail. A sync should resolve this.

Signed-off-by: Ankit Kumar <ankit@linux.vnet.ibm.com>
2017-08-09 12:04:16 +02:00
Harald Hoyer ae989390a1 dracut.sh: --nofscks does not take parameters
fixes: https://github.com/dracutdevs/dracut/issues/264
2017-08-07 11:39:45 +02:00
Daniel Molkentin 76dd870bfd Do generate error when hostonly_cmdline is set to "no"
Reference: bsc#1048748
2017-07-17 17:01:07 +02:00
Harald Hoyer 106255afd4 bail out if module directory does not exist
this basically reverts commit 05214a0bed

if people want to build the initramfs without kernel modules,
then --no-kernel should be specified
2017-06-29 17:09:50 +02:00
Harald Hoyer 940169e8d8 check for CONFIG_ACPI_TABLE_UPGRADE
additionally as for CONFIG_ACPI_INITRD_TABLE_OVERRIDE
config parameter got renamed
2017-06-27 12:29:07 +02:00
Daniel Molkentin 8b6d136e62 Make binutils optional when elfutils are available
This is intended for minimum host OSes where 36 MB used by binutils
are deemed too expensive. We only need "strip", which exists as eu-strip
in elfutils, which in turn is < 1 MB in size.

Note that the tests (TEST-04-FULL-SYSTEMD/test.sh) still depend on
strip from binutils. It could use sstrip in the future.
2017-04-10 11:28:04 +02:00
Harald Hoyer f0bfada399 dracut.sh: strip NUL bytes in stream before push in string
seems like bash-4.4 does not like NUL bytes in variables
2017-03-30 12:52:11 +02:00
Harald Hoyer 53475faa81 Correct path for UEFI stub
respect any $prefix given to the systemd installation

https://github.com/dracutdevs/dracut/pull/196
2017-03-20 11:43:04 +01:00
Harald Hoyer 647b521fc7 dracut: check for EUID instead of UID 2017-01-18 11:04:36 +01:00
Harald Hoyer 83a6d6f928 dracut.sh: add /dev/random and /dev/urandom to static device nodes
otherwise libgcrypt might complain

https://bugzilla.redhat.com/show_bug.cgi?id=1401444
2017-01-18 10:37:10 +01:00
Harald Hoyer 8a32bf6107 dracut: unset LC_* after setting LANG and LC_ALL
otherwise bash/glibc might complain verbosely about not finding locales
2017-01-18 10:35:41 +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 5c57209ba5 dracut.sh: add default path for --uefi
The default output filename for --uefi is
<EFI>/EFI/Linux/linux-$kernel$-<MACHINE_ID>-<BUILD_ID>.efi.
<EFI> might be /efi, /boot or /boot/efi depending on where the ESP partition
is mounted. The <BUILD_ID> is taken from BUILD_ID in /usr/lib/os-release or
if it exists /etc/os-release and is left out, if BUILD_ID is non-existant or
empty.

Also a new option --no-machineid was added, which affects the default output
filename of --uefi and will discard the <MACHINE_ID> part.
2017-01-16 14:27:39 +01:00
Harald Hoyer 39c725dc4e Merge pull request #157 from ddiss/fix_relative_tmpdir
dracut.sh: support --tmpdir as a relative path
2017-01-09 10:42:40 +01:00
Andreas Stieger 0db98910a1 dracut.sh: create the initramfs non-world readable also if early cpio is used
Fixes: 5f2c30d9bc
Previously fixed CVE-2012-4453: e1b48995c2

Signed-off-by: Andreas Stieger <astieger@suse.com>
2016-11-07 10:41:38 +01:00
David Disseldorp bafc82e732 dracut.sh: support --tmpdir as a relative path
Dracut changes working directory before attempting to output files under
$DRACUT_TMPDIR , resulting in an IO failure if $DRACUT_TMPDIR is a path
relative to the working directory when dracut was started.

Fixes: https://github.com/dracutdevs/dracut/issues/156

Signed-off-by: David Disseldorp <ddiss@suse.de>
2016-10-10 16:27:47 +02:00
Harald Hoyer f367b73852 dracut.sh: document --hostonly-i18n and --no-hostonly-i18n
show description in --help

https://bugzilla.redhat.com/show_bug.cgi?id=1266448
(cherry picked from commit 91896ab68e)
2016-08-19 15:49:33 +02:00
Harald Hoyer 3889234f71 dracut.sh: make tmp dirs after the trap function is installed
otherwise a good timed ctrl-c will leave the tmp dir around
2016-06-29 17:32:31 +02:00
Colin Guthrie 55b99a0e4c dracut.sh: fix $tmpfilesdir fallback when systemd-devel is not installed.
Bug introduced in 3a04bddeed in Dec 2014.
2016-06-07 10:48:49 +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 0297fdcb3e Merge pull request #123 from dracut-mailing-devs/40374262.eB5p3XdtTH@linux-lm3i.site
Correctly handle module aliases
2016-04-15 12:05:44 +02:00