From 4daccf208feccb027731d3fc8dc2686ab9ef3428 Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 20 Feb 2017 13:25:08 +0100 Subject: systemd-boot: Make sure /etc/machine-id exists This leads to the following error when trying to install a new machine where the machine ID wasn't yet initialized during boot: Failed to get machine did: No such file or directory In addition this was also detected by the simpleUefiGummiboot installer test. So let's generate a fallback machine ID by using systemd-machine-id-setup before actually running bootctl. Tested this by running the installer.simpleUefiGummiboot test, it still fails but not because of the machine ID. Signed-off-by: aszlig Cc: @edolstra, @shlevy, @mic92 Fixes: #22561 --- .../boot/loader/systemd-boot/systemd-boot-builder.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'nixos/modules/system/boot/loader/systemd-boot') diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py index b91d64bb0a7..9218e1dc8a7 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py @@ -101,6 +101,18 @@ def main(): parser.add_argument('default_config', metavar='DEFAULT-CONFIG', help='The default NixOS config to boot') args = parser.parse_args() + try: + with open("/etc/machine-id") as machine_file: + machine_id = machine_file.readlines()[0] + except IOError as e: + if e.errno != errno.ENOENT: + raise + # Since systemd version 232 a machine ID is required and it might not + # be there on newly installed systems, so let's generate one so that + # bootctl can find it and we can also pass it to write_entry() later. + cmd = ["@systemd@/bin/systemd-machine-id-setup", "--print"] + machine_id = subprocess.check_output(cmd).rstrip() + if os.getenv("NIXOS_INSTALL_GRUB") == "1": warnings.warn("NIXOS_INSTALL_GRUB env var deprecated, use NIXOS_INSTALL_BOOTLOADER", DeprecationWarning) os.environ["NIXOS_INSTALL_BOOTLOADER"] = "1" @@ -113,13 +125,6 @@ def main(): mkdir_p("@efiSysMountPoint@/efi/nixos") mkdir_p("@efiSysMountPoint@/loader/entries") - try: - with open("/etc/machine-id") as machine_file: - machine_id = machine_file.readlines()[0] - except IOError as e: - if e.errno != errno.ENOENT: - raise - machine_id = None gens = get_generations("system") remove_old_entries(gens) -- cgit 1.4.1