boot-tree: portable unit, dracut and mkinitcpio hooks, self-quieting console, minimal NixOS module
This commit is contained in:
1 parent
2b1447965a
commit
1482d4437a
13 files changed
+208
-121
No files matched your search
@@ -4,10 +4,27 @@ A live dependency tree of systemd jobs on the boot console, in the spirit of
|
||||
nix-output-monitor. It replaces the scrolling kernel and systemd lines with a
|
||||
tree of pending units and a timeline bar per row.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Linux with **systemd ≥ 246 as PID 1** (private socket `/run/systemd/private`,
|
||||
`Manager.SetShowStatus`).
|
||||
- Runs as **root**, from the shipped `boot-tree.service`.
|
||||
- **libdbus-1** at runtime.
|
||||
- A **virtual terminal** (`CONFIG_VT`); the unit draws on `/dev/tty12`.
|
||||
- Optional: a **systemd-based initrd** (NixOS `boot.initrd.systemd`, dracut, or
|
||||
mkinitcpio's `systemd` hook). Without one the tree starts in stage 2, once the
|
||||
real root is mounted.
|
||||
- Optional: a large console font on HiDPI screens, e.g. Terminus `ter-v32n`
|
||||
through the distro's console font setting.
|
||||
|
||||
No kernel parameters are needed: while it runs, boot-tree lowers the kernel
|
||||
console log level and turns systemd's status output off, and restores both when
|
||||
it hands the console over.
|
||||
|
||||
## How it works
|
||||
|
||||
- Starts as an initrd unit (needs `boot.initrd.systemd.enable`), about a second
|
||||
after the kernel.
|
||||
- Starts as an initrd unit when the initrd runs systemd, about a second after
|
||||
the kernel.
|
||||
- Talks to PID 1 over the private socket `/run/systemd/private` with libdbus:
|
||||
`Subscribe`, `ListJobs`, unit properties, and the `JobNew`/`JobRemoved`/
|
||||
`PropertiesChanged` signals.
|
||||
@@ -18,17 +35,39 @@ tree of pending units and a timeline bar per row.
|
||||
previous one when the display manager starts or the default target is
|
||||
reached, so gettys and greeters on tty1 cannot draw over it.
|
||||
|
||||
## Usage
|
||||
## Installing
|
||||
|
||||
The package ships everything a system needs under `lib/`:
|
||||
|
||||
| File | Purpose |
|
||||
| --- | --- |
|
||||
| `lib/systemd/system/boot-tree.service` | the unit, used in both the initrd and stage 2 |
|
||||
| `lib/dracut/modules.d/90boot-tree/` | dracut module |
|
||||
| `lib/initcpio/install/sd-boot-tree` | mkinitcpio hook |
|
||||
|
||||
### NixOS
|
||||
|
||||
```nix
|
||||
inputs.boot-tree.url = "git+file:/home/wvhulle/Code/boot-tree?ref=refs/heads/main";
|
||||
# in a host's modules:
|
||||
# in the host's modules:
|
||||
boot-tree.nixosModules.default
|
||||
{ services.boot-tree.enable = true; }
|
||||
```
|
||||
|
||||
Options: `tty`, `holdMs`, `quietConsole` (silences kernel/systemd console
|
||||
output and loads a Terminus font in the initrd), `consoleFont`.
|
||||
With `boot.initrd.systemd.enable` the unit is added to the initrd as well.
|
||||
|
||||
### Other distributions
|
||||
|
||||
1. Install `boot-tree` to `/usr/bin` and the files above under `/usr/lib`.
|
||||
2. `systemctl enable boot-tree.service`.
|
||||
3. To start it in the initrd:
|
||||
- dracut: `add_dracutmodules+=" boot-tree "` in `/etc/dracut.conf.d/boot-tree.conf`,
|
||||
then `dracut --force`;
|
||||
- mkinitcpio: add `sd-boot-tree` after `systemd` in `HOOKS`, then
|
||||
`mkinitcpio -P`.
|
||||
|
||||
To draw on another terminal, override `TTYPath=` with
|
||||
`systemctl edit boot-tree.service`.
|
||||
|
||||
## Testing
|
||||
|
||||
|
||||
+5
-3
@@ -35,9 +35,11 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
services.boot-tree = {
|
||||
enable = true;
|
||||
consoleFont = "ter-v20n";
|
||||
services.boot-tree.enable = true;
|
||||
|
||||
console = {
|
||||
earlySetup = true;
|
||||
font = "${pkgs.terminus_font}/share/consolefonts/ter-v20n.psf.gz";
|
||||
};
|
||||
|
||||
systemd.services = lib.mapAttrs (_: demoService) demoUnits.services // {
|
||||
|
||||
+16
-9
@@ -3,16 +3,19 @@
|
||||
name = "boot-tree";
|
||||
enableOCR = true;
|
||||
|
||||
nodes.machine = {
|
||||
imports = [ demoHost ];
|
||||
virtualisation = {
|
||||
memorySize = 2048;
|
||||
qemu.options = [
|
||||
"-vga none"
|
||||
"-device virtio-vga,xres=1280,yres=800"
|
||||
];
|
||||
nodes.machine =
|
||||
{ lib, ... }:
|
||||
{
|
||||
imports = [ demoHost ];
|
||||
systemd.settings.Manager.ShowStatus = lib.mkForce true;
|
||||
virtualisation = {
|
||||
memorySize = 2048;
|
||||
qemu.options = [
|
||||
"-vga none"
|
||||
"-device virtio-vga,xres=1280,yres=800"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.start()
|
||||
@@ -36,6 +39,10 @@
|
||||
assert "handing the console over" in journal, "never handed the console over"
|
||||
|
||||
machine.succeed("test \"$(systemctl show -p Result --value boot-tree)\" = success")
|
||||
console_level = machine.succeed("cut -f1 /proc/sys/kernel/printk").strip()
|
||||
assert console_level != "1", f"kernel console level was not restored: {console_level}"
|
||||
show_status = machine.succeed("systemctl show -p ShowStatus --value").strip()
|
||||
assert show_status == "yes", f"systemd status output was not restored: {show_status}"
|
||||
machine.screenshot("handed-over")
|
||||
'';
|
||||
}
|
||||
@@ -67,8 +67,23 @@
|
||||
{
|
||||
default = craneLib.buildPackage {
|
||||
inherit (buildInputsFor pkgs) nativeBuildInputs buildInputs;
|
||||
src = craneLib.cleanCargoSource ./.;
|
||||
src = lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset = lib.fileset.unions [
|
||||
(craneLib.fileset.commonCargoSources ./.)
|
||||
./packaging
|
||||
];
|
||||
};
|
||||
strictDeps = true;
|
||||
postInstall = ''
|
||||
install -Dm644 packaging/systemd/boot-tree.service $out/lib/systemd/system/boot-tree.service
|
||||
substituteInPlace $out/lib/systemd/system/boot-tree.service \
|
||||
--replace-fail /usr/bin/boot-tree $out/bin/boot-tree
|
||||
install -Dm755 packaging/dracut/90boot-tree/module-setup.sh \
|
||||
$out/lib/dracut/modules.d/90boot-tree/module-setup.sh
|
||||
install -Dm644 packaging/mkinitcpio/install/sd-boot-tree \
|
||||
$out/lib/initcpio/install/sd-boot-tree
|
||||
'';
|
||||
meta.mainProgram = "boot-tree";
|
||||
meta.platforms = lib.platforms.linux;
|
||||
};
|
||||
|
||||
+17
-101
@@ -7,120 +7,36 @@
|
||||
}:
|
||||
let
|
||||
cfg = config.services.boot-tree;
|
||||
|
||||
unit = {
|
||||
description = "Live dependency tree of boot jobs on ${cfg.tty}";
|
||||
wantedBy = [ "sysinit.target" ];
|
||||
after = [ "systemd-vconsole-setup.service" ];
|
||||
before = [
|
||||
"display-manager.service"
|
||||
"shutdown.target"
|
||||
];
|
||||
conflicts = [ "shutdown.target" ];
|
||||
unitConfig = {
|
||||
DefaultDependencies = false;
|
||||
IgnoreOnIsolate = true;
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = "@${lib.getExe cfg.package} @boot-tree --hold-ms ${toString cfg.holdMs}";
|
||||
StandardInput = "tty";
|
||||
StandardOutput = "tty";
|
||||
StandardError = "journal";
|
||||
TTYPath = cfg.tty;
|
||||
TTYReset = true;
|
||||
TTYVTDisallocate = false;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.boot-tree = {
|
||||
enable = lib.mkEnableOption ''
|
||||
a live dependency tree of systemd jobs on the boot console. It starts in
|
||||
the systemd initrd, survives the switch to the real root, and hands the
|
||||
console over once the display manager starts or the default target is
|
||||
reached
|
||||
a live dependency tree of systemd jobs on the boot console. With a
|
||||
systemd initrd it starts there and survives the switch to the real root;
|
||||
otherwise it starts in stage 2. It hands the console back once the
|
||||
display manager starts or the default target is reached
|
||||
'';
|
||||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||
defaultText = lib.literalExpression "boot-tree.packages.\${system}.default";
|
||||
description = "The boot-tree package.";
|
||||
};
|
||||
|
||||
tty = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/dev/tty12";
|
||||
description = ''
|
||||
Virtual terminal the tree is drawn on. boot-tree switches to it while
|
||||
it runs, so gettys, greeters and kernel output on other terminals
|
||||
cannot draw over the tree, and switches back to the previously active
|
||||
terminal when it hands the console over.
|
||||
'';
|
||||
};
|
||||
|
||||
holdMs = lib.mkOption {
|
||||
type = lib.types.ints.unsigned;
|
||||
default = 0;
|
||||
description = "Milliseconds the final frame stays on screen before the console is handed over.";
|
||||
};
|
||||
|
||||
quietConsole = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Silence kernel, udev and systemd status output on the console so it
|
||||
does not draw over the tree, and load a large Terminus console font in
|
||||
the initrd.
|
||||
'';
|
||||
};
|
||||
|
||||
consoleFont = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "ter-v32n";
|
||||
example = "ter-v20n";
|
||||
description = "Terminus console font loaded when {option}`services.boot-tree.quietConsole` is set.";
|
||||
description = "The boot-tree package, which ships the systemd unit.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
{
|
||||
assertions = [
|
||||
{
|
||||
assertion = config.boot.initrd.systemd.enable;
|
||||
message = "services.boot-tree needs boot.initrd.systemd.enable to start before the root switch.";
|
||||
}
|
||||
];
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
systemd = {
|
||||
packages = [ cfg.package ];
|
||||
services.boot-tree.wantedBy = [ "sysinit.target" ];
|
||||
};
|
||||
|
||||
systemd.services.boot-tree = unit;
|
||||
|
||||
boot.initrd.systemd = {
|
||||
services.boot-tree = unit;
|
||||
storePaths = [ (lib.getExe cfg.package) ];
|
||||
};
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.quietConsole {
|
||||
boot = {
|
||||
consoleLogLevel = lib.mkDefault 3;
|
||||
kernelParams = [
|
||||
"quiet"
|
||||
"systemd.show_status=error"
|
||||
"rd.systemd.show_status=error"
|
||||
"udev.log_level=3"
|
||||
"rd.udev.log_level=3"
|
||||
];
|
||||
};
|
||||
|
||||
console = {
|
||||
earlySetup = true;
|
||||
font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/${cfg.consoleFont}.psf.gz";
|
||||
};
|
||||
})
|
||||
]
|
||||
);
|
||||
boot.initrd.systemd = lib.mkIf config.boot.initrd.systemd.enable {
|
||||
packages = [ cfg.package ];
|
||||
storePaths = [ (lib.getExe cfg.package) ];
|
||||
services.boot-tree.wantedBy = [ "sysinit.target" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
disable=SC2154
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
check() {
|
||||
require_binaries boot-tree || return 1
|
||||
return 255
|
||||
}
|
||||
|
||||
depends() {
|
||||
echo systemd
|
||||
}
|
||||
|
||||
install() {
|
||||
inst_binary boot-tree
|
||||
inst_simple "$systemdsystemunitdir/boot-tree.service"
|
||||
$SYSTEMCTL -q --root "$initdir" enable boot-tree.service
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
build() {
|
||||
add_binary boot-tree
|
||||
add_systemd_unit boot-tree.service
|
||||
add_symlink /usr/lib/systemd/system/sysinit.target.wants/boot-tree.service \
|
||||
/usr/lib/systemd/system/boot-tree.service
|
||||
}
|
||||
|
||||
help() {
|
||||
cat <<HELP
|
||||
Shows a live dependency tree of systemd jobs while the initramfs boots.
|
||||
Requires the systemd hook; add sd-boot-tree after it in HOOKS.
|
||||
HELP
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
[Unit]
|
||||
Description=Live dependency tree of boot jobs
|
||||
DefaultDependencies=no
|
||||
IgnoreOnIsolate=yes
|
||||
After=systemd-vconsole-setup.service
|
||||
Before=display-manager.service shutdown.target
|
||||
Conflicts=shutdown.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=@/usr/bin/boot-tree @boot-tree
|
||||
StandardInput=tty
|
||||
StandardOutput=tty
|
||||
StandardError=journal
|
||||
TTYPath=/dev/tty12
|
||||
TTYReset=yes
|
||||
TTYVTDisallocate=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sysinit.target
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::fs;
|
||||
|
||||
use rustix::{
|
||||
io::Errno,
|
||||
ioctl::{Getter, IntegerSetter, Opcode, ioctl},
|
||||
@@ -9,6 +11,27 @@ const VT_GETSTATE: Opcode = 0x5603;
|
||||
const VT_ACTIVATE: Opcode = 0x5606;
|
||||
const VT_WAITACTIVE: Opcode = 0x5607;
|
||||
const VIRTUAL_TERMINAL_PREFIX: &str = "/dev/tty";
|
||||
const KERNEL_PRINTK: &str = "/proc/sys/kernel/printk";
|
||||
const ALERTS_ONLY: &str = "1";
|
||||
|
||||
pub struct QuietKernelConsole {
|
||||
previous_level: String,
|
||||
}
|
||||
|
||||
impl QuietKernelConsole {
|
||||
pub fn take() -> Option<Self> {
|
||||
let levels = fs::read_to_string(KERNEL_PRINTK).ok()?;
|
||||
let previous_level = levels.split_whitespace().next()?.to_owned();
|
||||
fs::write(KERNEL_PRINTK, ALERTS_ONLY).ok()?;
|
||||
Some(Self { previous_level })
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for QuietKernelConsole {
|
||||
fn drop(&mut self) {
|
||||
let _ = fs::write(KERNEL_PRINTK, &self.previous_level);
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct VtState {
|
||||
|
||||
+15
@@ -18,6 +18,8 @@ use crate::{
|
||||
|
||||
const RECONNECT_PATIENCE: Duration = Duration::from_secs(60);
|
||||
const SWITCH_ROOT_UNIT: &str = "initrd-switch-root.service";
|
||||
const SILENT_STATUS: &str = "no";
|
||||
const CONFIGURED_STATUS: &str = "";
|
||||
|
||||
pub struct Feed {
|
||||
scope: Scope,
|
||||
@@ -91,6 +93,9 @@ impl Feed {
|
||||
fn connect(&mut self, state: &mut BootState) -> Result<Session, Error> {
|
||||
let session = Session::open(self.scope)?;
|
||||
session.subscribe()?;
|
||||
if self.scope == Scope::System {
|
||||
session.set_show_status(SILENT_STATUS).ok();
|
||||
}
|
||||
let requested_root = match &self.target {
|
||||
Some(target) => target.clone(),
|
||||
None => session.default_target()?,
|
||||
@@ -176,3 +181,13 @@ impl Feed {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Feed {
|
||||
fn drop(&mut self) {
|
||||
if let Some(session) = &self.session
|
||||
&& self.scope == Scope::System
|
||||
{
|
||||
session.set_show_status(CONFIGURED_STATUS).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -21,7 +21,11 @@ use rustix::system::uname;
|
||||
use signal_hook::{consts::SIGTERM, flag};
|
||||
|
||||
use crate::{
|
||||
clock::monotonic_now, console::ForegroundVt, error::Error, feed::Feed, sysroot::INITRD_RELEASE,
|
||||
clock::monotonic_now,
|
||||
console::{ForegroundVt, QuietKernelConsole},
|
||||
error::Error,
|
||||
feed::Feed,
|
||||
sysroot::INITRD_RELEASE,
|
||||
systemd::Scope,
|
||||
};
|
||||
|
||||
@@ -44,6 +48,9 @@ pub fn run(options: Options) -> Result<(), Error> {
|
||||
};
|
||||
let mut state = BootState::new(phase);
|
||||
let mut feed = Feed::new(options.scope, options.target);
|
||||
let _quiet_kernel = (options.scope == Scope::System)
|
||||
.then(QuietKernelConsole::take)
|
||||
.flatten();
|
||||
let _foreground = ForegroundVt::take();
|
||||
let mut terminal = ratatui::try_init()?;
|
||||
let watched = watch(
|
||||
|
||||
@@ -129,6 +129,17 @@ impl Session {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_show_status(&self, mode: &str) -> Result<(), Error> {
|
||||
self.call(
|
||||
DESTINATION,
|
||||
MANAGER_PATH,
|
||||
MANAGER_INTERFACE,
|
||||
"SetShowStatus",
|
||||
(mode,),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn default_target(&self) -> Result<String, Error> {
|
||||
let reply = self.call(
|
||||
DESTINATION,
|
||||
|
||||
Reference in new issue
Block a user