dracutdevs / dracut

dracut the event driven initramfs infrastructure
https://github.com/dracutdevs/dracut/wiki
GNU General Public License v2.0
602 stars 400 forks source link

Stored kernel commandline should be passed to systemd #1513

Open rkjnsn opened 3 years ago

rkjnsn commented 3 years ago

Describe the bug In host-only mode, dracut auto-generates a kernel command-line and stores it in the generated initramfs. This is super convenient, as it will automatically detect the proper values for root=, rootflags=, resume=, rd.luks.uuid=, et cetera. However, this information is never passed to systemd, meaning that operations managed by systemd rather than dracut scripts, such as resuming from swsusp, don't have access to this stored command-line information and thus fail to work.

Distribution used Gentoo

Dracut version 050

Init system Systemd

To Reproduce

  1. Generate a host-only initramfs that includes the "resume" Dracut module.
  2. Verify that the stored kernel commandline printed when running dracut includes the correct value for resume=
  3. Hibernate the system.
  4. Boot using the initramfs generated in (1)

Expected behavior The system properly resumes from hibernation.

Actual behavior The stored commandline is not passed to systemd, so systemd-hibernate-resume-generator never instantiates systemd-hibernate-resume@.service, causing the system to boot from scratch rather than resuming from hibernation.

Additional context Passing a custom kernel command-line to systemd appears to be as simple as setting the SYSTEMD_PROC_CMDLINE environment variable. To test, I replaced the /init symlink in the initramfs with the following script:

#!/bin/sh
mount -t proc proc /proc
source /lib/dracut-lib.sh
export SYSTEMD_PROC_CMDLINE="$(getcmdline)"
umount /proc
exec /lib/systemd/systemd

With that change in place, my system properly resumes from hibernation.

tpgxyz commented 3 years ago

@rkjnsn Does adding export SYSTEMD_PROC_CMDLINE="$(getcmdline)" to https://github.com/dracutdevs/dracut/blob/2d83bce21bfc874b29c1fb99e8fabb843f038725/modules.d/98dracut-systemd/dracut-cmdline.sh#L18 help to resolve this issue ?

rkjnsn commented 3 years ago

It does not. It appears that systemd units (such as dracut-cmdline.service) run with their own clean environments distinct from the one used to run systemd itself and the generators. As such, setting SYSTEMD_PROC_CMDLINE there isn't enough for systemd-hibernate-resume-generator to see it.