From bebc30e7fd6fc2da35bb154593a3c6758c8beb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 22 Nov 2023 10:43:59 +0100 Subject: [PATCH] also copy machine-id into installer This can help with keeping the same dhcp leases when the dhcp server uses DUID rather than mac addresses --- nix/installer.nix | 3 +++ nix/kexec-installer/kexec-run.sh | 2 ++ nix/kexec-installer/test.nix | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nix/installer.nix b/nix/installer.nix index 306e38f..33c07ed 100644 --- a/nix/installer.nix +++ b/nix/installer.nix @@ -58,5 +58,8 @@ fi install -m 400 ssh/ssh_host_* /mnt-root/etc/ssh cp *.json /mnt-root/root/network/ + if [[ -f machine-id ]]; then + cp machine-id /mnt-root/etc/machine-id + fi ''; } diff --git a/nix/kexec-installer/kexec-run.sh b/nix/kexec-installer/kexec-run.sh index 4e5ade6..71b944b 100644 --- a/nix/kexec-installer/kexec-run.sh +++ b/nix/kexec-installer/kexec-run.sh @@ -50,6 +50,8 @@ done "$SCRIPT_DIR/ip" -4 --json route > routes-v4.json "$SCRIPT_DIR/ip" -6 --json route > routes-v6.json +[ -f /etc/machine-id ] && cp /etc/machine-id machine-id + find . | cpio -o -H newc | gzip -9 >> "$SCRIPT_DIR/initrd" if ! "$SCRIPT_DIR/kexec" --load "$SCRIPT_DIR/bzImage" \ diff --git a/nix/kexec-installer/test.nix b/nix/kexec-installer/test.nix index f119bbb..d7b3cf6 100644 --- a/nix/kexec-installer/test.nix +++ b/nix/kexec-installer/test.nix @@ -101,7 +101,7 @@ makeTest' { node1.succeed("ip -6 route >&2") node1.succeed("networkctl status eth0 >&2") - def ssh(cmd: list[str], check: bool = True, stdout: Optional[int] = None) -> subprocess.CompletedProcess: + def ssh(cmd: list[str], check: bool = True, stdout: Optional[int] = None) -> subprocess.CompletedProcess[str]: ssh_cmd = [ "${pkgs.openssh}/bin/ssh", "-o", "StrictHostKeyChecking=no", @@ -128,6 +128,7 @@ makeTest' { # Kexec node1 to the toplevel of node2 via the kexec-boot script node1.succeed('touch /run/foo') + old_machine_id = node1.succeed("cat /etc/machine-id").strip() node1.fail('parted --version >&2') node1.succeed('tar -xf ${kexecTarball}/nixos-kexec-installer-noninteractive-${pkgs.system}.tar.gz -C /root') node1.succeed('/root/kexec/ip -V >&2') @@ -153,6 +154,9 @@ makeTest' { print(ssh(["ip", "-6", "route"])) print(ssh(["networkctl", "status"])) + new_machine_id = ssh(["cat", "/etc/machine-id"], stdout=subprocess.PIPE).stdout.strip() + assert old_machine_id == new_machine_id, f"{old_machine_id} != {new_machine_id}, machine-id changed" + assert ssh(["ls", "-la", "/run/foo"], check=False).returncode != 0, "kexeced node1 still has /run/foo" print(ssh(["parted", "--version"])) host = ssh(["hostname"], stdout=subprocess.PIPE).stdout.strip()