]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi: automatically reset /etc/machine-id to the empty file 39/head
authorLennart Poettering <lennart@poettering.net>
Wed, 7 Dec 2016 11:59:36 +0000 (12:59 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 7 Dec 2016 23:03:57 +0000 (00:03 +0100)
mkosi

diff --git a/mkosi b/mkosi
index 0c3de850407fc081166c64fbefef1c2fbbf1dead..785686df048a129013642b107d7bb52ee93790c6 100755 (executable)
--- 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)