feat: show the kernel's image loading progress while resuming from hibernation
The kernel freezes every process before it loads a hibernated image, so the screen looked hung for as long as the load took. A drop-in on systemd-hibernate-resume.service now opens the kernel console just before resume, draws a band across the middle of tty12 and confines the kernel's progress lines to it. The running bootvine stops drawing and stops taking the console back meanwhile, and repaints if no image was restored.
This commit is contained in:
17 files changed
+433
-13
No files matched your search
@@ -15,6 +15,7 @@ let
|
||||
scripted-initrd = "the slow units with the scripted initrd, so bootvine starts in stage 2";
|
||||
encrypted-volume = "a LUKS volume unlocked in the initrd with the passphrase 'sample passphrase'";
|
||||
failures = "units that fail in every way systemd reports, each with journal messages";
|
||||
hibernate-resume = "a swap disk to hibernate to, showing the kernel's image loading progress on resume";
|
||||
};
|
||||
|
||||
machines = lib.mapAttrs (machineName: _: machineModule machineName) machineDescriptions;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{ machine, pkgs, ... }:
|
||||
{
|
||||
name = "bootvine-hibernate-resume";
|
||||
|
||||
nodes.machine =
|
||||
{ lib, ... }:
|
||||
{
|
||||
imports = [
|
||||
machine
|
||||
../shared/recorded-display.nix
|
||||
"${pkgs.path}/nixos/tests/common/auto-format-root-device.nix"
|
||||
];
|
||||
|
||||
boot.resumeDevice = "/dev/vdc";
|
||||
swapDevices = lib.mkOverride 0 [
|
||||
{
|
||||
device = "/dev/vdc";
|
||||
options = [ "x-systemd.makefs" ];
|
||||
}
|
||||
];
|
||||
|
||||
powerManagement = {
|
||||
powerDownCommands = "systemctl --no-block stop backdoor.service";
|
||||
resumeCommands = "systemctl --no-block restart backdoor.service";
|
||||
};
|
||||
|
||||
virtualisation = {
|
||||
emptyDiskImages = [ 4096 ];
|
||||
useNixStoreImage = true;
|
||||
useEFIBoot = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript =
|
||||
builtins.readFile ../shared/console.py
|
||||
+ builtins.readFile ../shared/screen_recording.py
|
||||
+ builtins.readFile ./check.py;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
RESUME_MARKER = "/run/bootvine/resume-console-open"
|
||||
BOOT_CONSOLE_LEVEL = "3"
|
||||
SENTINEL_TEXT = "held only in memory"
|
||||
|
||||
|
||||
def console_level():
|
||||
return machine.succeed("cut -f1 /proc/sys/kernel/printk").strip()
|
||||
|
||||
|
||||
def assert_console_returned():
|
||||
machine.wait_until_fails("systemctl is-active bootvine")
|
||||
machine.fail(f"test -e {RESUME_MARKER}")
|
||||
assert console_level() == BOOT_CONSOLE_LEVEL, f"kernel console level was not restored: {console_level()}"
|
||||
|
||||
|
||||
recording = ScreenRecording(machine)
|
||||
machine.start()
|
||||
recording.start()
|
||||
|
||||
machine.wait_for_unit("default.target")
|
||||
assert_console_returned()
|
||||
machine.succeed("swapon --show=NAME --noheadings | grep -q .")
|
||||
machine.succeed(
|
||||
"mkdir /run/test",
|
||||
"mount -t ramfs ramfs /run/test",
|
||||
f"echo '{SENTINEL_TEXT}' > /run/test/sentinel",
|
||||
"dd if=/dev/urandom of=/run/test/ballast bs=1M count=500",
|
||||
)
|
||||
|
||||
machine.execute("systemctl hibernate >&2 &", check_return=False)
|
||||
machine.wait_for_shutdown()
|
||||
recording.stop()
|
||||
|
||||
resume_recording = ScreenRecording(machine)
|
||||
resume_recording.frames_directory = os.path.join(machine.out_dir, "resume-recording")
|
||||
resume_recording.frame_seconds = 0.1
|
||||
machine.start()
|
||||
resume_recording.start()
|
||||
machine.wait_for_console_text("Image loading progress")
|
||||
machine.wait_for_console_text("Image loading done")
|
||||
machine.succeed(f"grep '{SENTINEL_TEXT}' /run/test/sentinel")
|
||||
assert console_level() == BOOT_CONSOLE_LEVEL, f"the restored system kept the opened level: {console_level()}"
|
||||
assert foreground_terminal() != f"tty{BOOTVINE_TERMINAL}", "the restored system came back on bootvine's terminal"
|
||||
machine.fail("systemctl is-active bootvine")
|
||||
|
||||
resume_recording.stop()
|
||||
|
||||
machine.crash()
|
||||
machine.start()
|
||||
machine.wait_for_unit("default.target")
|
||||
machine.fail("test -e /run/test/sentinel")
|
||||
assert_console_returned()
|
||||
journal = bootvine_journal()
|
||||
print(journal)
|
||||
assert " in Initrd " in journal, "bootvine did not run in the initrd of the boot without an image"
|
||||
machine.succeed('test "$(systemctl show -p Result --value bootvine)" = success')
|
||||
@@ -0,0 +1,13 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
virtualisation.vmVariant = {
|
||||
boot.resumeDevice = "/dev/vdb";
|
||||
swapDevices = lib.mkOverride 0 [
|
||||
{
|
||||
device = "/dev/vdb";
|
||||
options = [ "x-systemd.makefs" ];
|
||||
}
|
||||
];
|
||||
virtualisation.emptyDiskImages = [ 4096 ];
|
||||
};
|
||||
}
|
||||
@@ -14,6 +14,7 @@ class ScreenRecording:
|
||||
self.recorded_machine = recorded_machine
|
||||
self.frames_directory = os.path.join(recorded_machine.out_dir, "recording")
|
||||
self.raw_frame = os.path.join(recorded_machine.state_dir, "recording-frame.ppm")
|
||||
self.frame_seconds = RECORDING_FRAME_SECONDS
|
||||
self.stopping = threading.Event()
|
||||
self.thread = threading.Thread(target=self.record_frames, daemon=True)
|
||||
|
||||
@@ -64,7 +65,7 @@ class ScreenRecording:
|
||||
while not self.stopping.is_set():
|
||||
self.save_frame(monitor, frame_number)
|
||||
frame_number += 1
|
||||
self.stopping.wait(RECORDING_FRAME_SECONDS)
|
||||
self.stopping.wait(self.frame_seconds)
|
||||
except (OSError, ConnectionError, subprocess.CalledProcessError):
|
||||
pass
|
||||
finally:
|
||||
|
||||
Reference in new issue
Block a user