From f5cafba17214c02f9f80bc5283a165054f6dc828 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Dec 2016 12:59:36 +0100 Subject: [PATCH] mkosi: automatically reset /etc/machine-id to the empty file --- mkosi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mkosi b/mkosi index 0c3de8504..785686df0 100755 --- a/mkosi +++ b/mkosi @@ -761,6 +761,22 @@ def install_distribution(args, workspace, run_build_script): install[args.distribution](args, workspace, run_build_script) +def reset_machine_id(args, workspace): + + # Make /etc/machine-id an empty file. This way, on the next boot + # is either initialized and commited (if /etc is writable) or the + # image runs with a transient machine ID, that changes on each + # boot (if the image is read-only). + + print_step("Resetting machine ID...") + + machine_id = os.path.join(workspace, 'root', 'etc/machine-id') + + os.unlink(machine_id) + open(machine_id, "w+b").close() + + print_step("Resetting machine ID completed.") + def set_root_password(args, workspace): "Set the root account password, or just delete it so it's easy to log in" if args.password == '': @@ -1908,6 +1924,7 @@ def build_image(args, workspace, run_build_script): prepare_tree(args, workspace.name, run_build_script) mount_cache(args, workspace.name) install_distribution(args, workspace.name, run_build_script) + reset_machine_id(args, workspace.name) install_boot_loader(args, workspace.name) install_extra_trees(args, workspace.name) install_build_src(args, workspace.name, run_build_script) -- 2.47.2