From 40df39634be08d11fbd8df389395f3c49d3080ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 5 Sep 2022 05:32:46 +0000 Subject: [PATCH 1/3] kexec: redue memory usage in test --- nix/kexec-installer-test.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/kexec-installer-test.nix b/nix/kexec-installer-test.nix index 17a0eed..dc613fb 100644 --- a/nix/kexec-installer-test.nix +++ b/nix/kexec-installer-test.nix @@ -16,7 +16,7 @@ in makeTest' { nodes = { node1 = { ... }: { virtualisation.vlans = [ ]; - virtualisation.memorySize = 4 * 1024; + virtualisation.memorySize = 2 * 1024 + 512; virtualisation.diskSize = 4 * 1024; virtualisation.useBootLoader = true; virtualisation.useEFIBoot = true; From b630b3fb37320efd1ee827f55da4cff5b793dedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 5 Sep 2022 05:35:19 +0000 Subject: [PATCH 2/3] kexec: create toplevel kexec directory for unpacking --- nix/kexec-installer-test.nix | 6 ++---- nix/kexec-installer.nix | 16 ++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/nix/kexec-installer-test.nix b/nix/kexec-installer-test.nix index dc613fb..c38ab27 100644 --- a/nix/kexec-installer-test.nix +++ b/nix/kexec-installer-test.nix @@ -55,10 +55,8 @@ in makeTest' { # Kexec node1 to the toplevel of node2 via the kexec-boot script node1.succeed('touch /run/foo') node1.fail('hello') - node1.succeed('mkdir -p /root/kexec') - node1.succeed('mkdir -p /root/kexec') - node1.succeed('tar -xf ${nodes.node2.config.system.build.kexecTarball}/tarball/nixos-kexec-installer-${pkgs.system}.tar.xz -C /root/kexec') - node1.execute('/root/kexec/kexec-boot') + node1.succeed('tar -xf ${nodes.node2.config.system.build.kexecTarball}/tarball/nixos-kexec-installer-${pkgs.system}.tar.xz -C /root') + node1.execute('/root/kexec/run') # wait for machine to kexec node1.execute('sleep 9999', check_return=False) node1.succeed('! test -e /run/foo') diff --git a/nix/kexec-installer.nix b/nix/kexec-installer.nix index 6115a77..643a267 100644 --- a/nix/kexec-installer.nix +++ b/nix/kexec-installer.nix @@ -9,7 +9,7 @@ # This is a variant of the upstream kexecScript that also allows embedding # a ssh key. - system.build.kexecBoot = lib.mkForce (pkgs.writeScript "kexec-boot" '' + system.build.kexecRun = lib.mkForce (pkgs.writeScript "kexec-run" '' #!/usr/bin/env bash set -ex shopt -s nullglob @@ -17,7 +17,7 @@ INITRD_TMP=$(mktemp -d) cd "$INITRD_TMP" pwd - mkdir initrd initrd/ssh + mkdir -p initrd/ssh pushd initrd if [ -e /root/.ssh/authorized_keys ]; then cat /root/.ssh/authorized_keys >> ssh/authorized_keys @@ -28,7 +28,7 @@ for p in /etc/ssh/ssh_host_*; do cp -a "$p" ssh done - find -type f | cpio -o -H newc | gzip -9 > ../extra.gz + find | cpio -o -H newc | gzip -9 > ../extra.gz popd cat "''${SCRIPT_DIR}/initrd.gz" extra.gz > final.gz @@ -55,19 +55,19 @@ fileName = "nixos-kexec-installer-${pkgs.stdenv.hostPlatform.system}"; contents = [ { - target = "/initrd.gz"; + target = "/kexec/initrd.gz"; source = "${config.system.build.netbootRamdisk}/initrd"; } { - target = "/bzImage"; + target = "/kexec/bzImage"; source = "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}"; } { - target = "/kexec-boot"; - source = config.system.build.kexecBoot; + target = "/kexec/run"; + source = config.system.build.kexecRun; } { - target = "/kexec"; + target = "/kexec/kexec"; source = "${pkgs.pkgsStatic.kexec-tools}/bin/kexec"; } ]; From 2913702b16844e07426b7f32a2daebf663e5a6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 5 Sep 2022 05:35:55 +0000 Subject: [PATCH 3/3] kexec: add reboot message --- nix/kexec-installer.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/kexec-installer.nix b/nix/kexec-installer.nix index 643a267..c135052 100644 --- a/nix/kexec-installer.nix +++ b/nix/kexec-installer.nix @@ -40,6 +40,7 @@ rm -r "$INITRD_TMP" # Disconnect our background kexec from the terminal + echo "machine will boot into nixos in in 6s..." if [[ -e /dev/kmsg ]]; then # this makes logging visible in `dmesg`, or the system consol or tools like journald exec > /dev/kmsg 2>&1