summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-05-26 22:15:42 +0000
committerAlyssa Ross <hi@alyssa.is>2023-05-27 21:44:43 +0000
commit59546e9055a3efdc67ec21a6edd7a22769b3b107 (patch)
tree3c7ba687e4ac17ed1387aba6cc23953e481c3eb8
parent6b34ec8a8ba7c48837edcec06be808d773ce793a (diff)
downloadspectrum-59546e9055a3efdc67ec21a6edd7a22769b3b107.tar
spectrum-59546e9055a3efdc67ec21a6edd7a22769b3b107.tar.gz
spectrum-59546e9055a3efdc67ec21a6edd7a22769b3b107.tar.bz2
spectrum-59546e9055a3efdc67ec21a6edd7a22769b3b107.tar.lz
spectrum-59546e9055a3efdc67ec21a6edd7a22769b3b107.tar.xz
spectrum-59546e9055a3efdc67ec21a6edd7a22769b3b107.tar.zst
spectrum-59546e9055a3efdc67ec21a6edd7a22769b3b107.zip
host/initramfs: panic if roothash is missing
We're not going to be able to boot if we don't know what roothash
we're looking for, so abort the boot at that point rather than hanging
forever.

This should never happen on an actual system, but it makes things
clearer in testing if something has gone wrong with the kernel command
line.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
-rwxr-xr-xhost/initramfs/etc/getuuids7
-rw-r--r--release/checks/default.nix2
-rw-r--r--release/checks/no-roothash.nix31
3 files changed, 39 insertions, 1 deletions
diff --git a/host/initramfs/etc/getuuids b/host/initramfs/etc/getuuids
index 90fda10..62f8935 100755
--- a/host/initramfs/etc/getuuids
+++ b/host/initramfs/etc/getuuids
@@ -1,6 +1,6 @@
 #!/bin/awk -f
 # SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2021, 2023 Alyssa Ross <hi@alyssa.is>
 
 function to_uuid(hex) {
     return substr(hex, 1, 8) "-" substr(hex, 9, 4) "-" substr(hex, 13, 4) "-" \
@@ -8,6 +8,11 @@ function to_uuid(hex) {
 }
 
 BEGIN {
+    if (length(ENVIRON["roothash"]) != 64) {
+	system("echo 'roothash invalid or missing' >&2")
+	exit 1
+    }
+
     print to_uuid(substr(ENVIRON["roothash"], 1, 32))
     print to_uuid(substr(ENVIRON["roothash"], 33, 32))
 }
diff --git a/release/checks/default.nix b/release/checks/default.nix
index bf26b9a..bae9159 100644
--- a/release/checks/default.nix
+++ b/release/checks/default.nix
@@ -10,6 +10,8 @@ import ../../lib/eval-config.nix ({ ... } @ args:
 
   pkg-tests = import ./pkg-tests.nix args;
 
+  no-roothash = import ./no-roothash.nix args;
+
   reuse = import ./reuse.nix args;
 
   rustfmt = import ./rustfmt.nix args;
diff --git a/release/checks/no-roothash.nix b/release/checks/no-roothash.nix
new file mode 100644
index 0000000..4c5c19c
--- /dev/null
+++ b/release/checks/no-roothash.nix
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: MIT
+# SPDX-FileCopyrightText: 2023 Alyssa Ross <hi@alyssa.is>
+
+import ../../lib/eval-config.nix ({ config, ... }:
+
+let
+  rootfs = import ../../host/rootfs { inherit config; };
+  initramfs = import ../../host/initramfs { inherit config rootfs; };
+in
+
+config.pkgs.nixosTest ({ stdenv, ... }: {
+  name = "spectrum-test-initramfs-no-roothash";
+  nodes = {};
+
+  testScript = ''
+    import shlex
+
+    flags = " ".join(map(shlex.quote, [
+      "qemu-kvm",
+      "-m", "512",
+      "-kernel", "${rootfs.kernel}/${stdenv.hostPlatform.linux-kernel.target}",
+      "-initrd", "${initramfs}",
+      "-append", "console=ttyS0 panic=-1",
+    ]))
+
+    machine = create_machine({"startCommand": flags})
+
+    machine.start()
+    machine.wait_for_console_text("roothash invalid or missing")
+  '';
+}))