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
This commit is contained in:
Jörg Thalheim 2023-11-22 10:43:59 +01:00
parent 6531732454
commit bebc30e7fd
3 changed files with 10 additions and 1 deletions

View file

@ -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
'';
}

View file

@ -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" \

View file

@ -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()