Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage-1: Log to secondary consoles #123039

Closed
wants to merge 3 commits into from

Conversation

samueldr
Copy link
Member

@samueldr samueldr commented May 14, 2021

Motivation for this change

The output from init will only be present on the last valid console= parameter from the kernel command-line.

This is extremely inconvenient, when not harmful, for generic images. On many ARM platforms the serial console names differ, so there is no absolute truthful console name to use here. Additionally, this prevents logging to be shown on both the connected display, and the serial output at once.

With bootlogd, the output is redirected to all console= parameters. It also replaces the ad-hoc logging to /run/log and the logging to /dev/kmsg.

This way we should be able to get rid of one of the main annoyance with ARM platforms early boot debugging.

This has been used for a good while in Mobile NixOS.

Ideally we'd somehow do a system test that confirms it logs to multiple serial consoles, but I really don't know how we'd pull that off.

TODO

  • Investigate input redirection
  • Decide how we handle killing bootlogd
  • Verify operation on an ARM machine

Input redirection

While opening this PR, I realized that this probably doesn't cover input during stage-1. Only the last console= would be usable as an input in that case. This is important for boot.debug1* use cases, and also useful if only to answer r to reboot the machine.

We probably can, could, and should merge this even without this being handled, as it would already be a net improvement compared to the current situation.

Killing bootlogd

Right now I haven't handled it at all. It gets culled at Kill any remaining processes, which means it will be missing all messages up to systemd starting in stage-2.

Should we:

  • Cheat and mark it as a storage daemon by prefixing its argv0 with a @?
  • Special case it in the loop?

Then, we can add a late boot.postBootCommands which includes ${pkgs.procps}/bin/pkill -x bootlogd to kill it. Ideally order it to happen last before we exec into systemd.

What even is bootlogd??

It's a minified part of sysvinit. The main core hasn't been touched by me. Really the main thing I did was delete the sysvinit around it. Then I added features that helps either Mobile NixOS or NixOS in some ways.

Things done

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

This closes #42255.

This obsoletes NixOS#42255.

bootlogd is both a console multiplexer, and console logger. This allows
us to drop the fiddly redirecting we were doing in shell script, and
ensures each console= parameters on the kernel command-line gets the
stage-1 output.

This also gives us *way earlier* stage-1 logging than before.
This verifies:

 - That the very first output is logged
 - That logging to /dev/kmsg works
@grahamc
Copy link
Member

grahamc commented May 14, 2021

While opening this PR, I realized that this probably doesn't cover input during stage-1. Only the last console= would be usable as an input in that case. This is important for boot.debug1* use cases, and also useful if only to answer r to reboot the machine.

It might be useful to print a message like "This is <currentconsoledevice>, input is only accepted on <consoledevice>.".

I'm anxious about merging this in before 21.05 branchoff so soon to cutoff, but would be +1 on the next release.

@samueldr
Copy link
Member Author

It might be useful to print a message like "This is , input is only accepted on .".

bootlogd doesn't know about any input at this time. So it wouldn't really be able to. Adding support for it is probably not that much less work than adding input multiplexing. Additionally, it wouldn't really be able to say it at a useful time. It would likely state it early during boot. So a few dozen stage-1 lines, probably combined with dozens of kernel log, it wouldn't be visible when input is needed.

The stage-1 sh script could loop on console= parameters to state so. It would know when input is handed-off to the user.


# `-f true` to force bootlogd to fork itself. bootlogd will only fork once it's ready to consume logs. Otherwise it could skip the first few lines.
# `-p` ensures required mount points are mounted.
# `-l` logs to /dev/kmsg too
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# `-l` logs to /dev/kmsg too
# `-k` logs to /dev/kmsg too

@stale
Copy link

stale bot commented Apr 19, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 19, 2022
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 23, 2022
@samueldr
Copy link
Member Author

samueldr commented Jul 5, 2023

Closing in favour of systemd's stage-1 infra, which I assume intrinsically supports console multiplexing just like its stage-2 does.

I won't get back to dealing with the complexity of this.

@samueldr samueldr closed this Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants