From dc31a1ea29cae217b71134bf59f888c5a90f630b Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 20 Feb 2017 14:28:53 +0100 Subject: [PATCH] systemd-boot: Unlink loader.conf if it exists Since systemd version 232 the install subcommand of bootctl opens the loader.conf with fopen() modes "wxe", where the "e" stands for exclusive, so the call will fail if the file exists. For installing the boot loader just once this is fine, but if we're using NIXOS_INSTALL_BOOTLOADER on a systemd where the bootloader is already present this will fail. Exactly this is done within the simpleUefiGummiboot installer test, where nixos-install is called twice and thus the bootloader is also installed twice, resulting in an error during the fopen call: Failed to open loader.conf for writing: File exists Removing the file prior to calling bootctl should fix this. I've tested this using the installer.simpleUefiGummiboot test and it now succeeds. Signed-off-by: aszlig Cc: @edolstra, @shlevy, @mic92 Fixes: #22925 --- .../system/boot/loader/systemd-boot/systemd-boot-builder.py | 4 ++++ 1 file changed, 4 insertions(+) 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 9218e1dc8a74..04cf17c1b0b4 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 @@ -118,6 +118,10 @@ def main(): os.environ["NIXOS_INSTALL_BOOTLOADER"] = "1" if os.getenv("NIXOS_INSTALL_BOOTLOADER") == "1": + # bootctl uses fopen() with modes "wxe" and fails if the file exists. + if os.path.exists("@efiSysMountPoint@/loader/loader.conf"): + os.unlink("@efiSysMountPoint@/loader/loader.conf") + if "@canTouchEfiVariables@" == "1": subprocess.check_call(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "install"]) else: