Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd-boot: allow splitting entries to xbootldr part #226692

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def copy_from_profile(profile: Optional[str], generation: int, specialisation: O
store_dir = os.path.basename(os.path.dirname(store_file_path))
efi_file_path = "/efi/nixos/%s-%s.efi" % (store_dir, suffix)
if not dry_run:
copy_if_not_exists(store_file_path, "@efiSysMountPoint@%s" % (efi_file_path))
copy_if_not_exists(store_file_path, "@entriesMountPoint@%s" % (efi_file_path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/entriesMountPoint/xbootMountPoint/ everywhere no?

return efi_file_path


Expand Down Expand Up @@ -117,7 +117,7 @@ def write_entry(profile: Optional[str], generation: int, specialisation: Optiona

try:
append_initrd_secrets = profile_path(profile, generation, specialisation, "append-initrd-secrets")
subprocess.check_call([append_initrd_secrets, "@efiSysMountPoint@%s" % (initrd)])
subprocess.check_call([append_initrd_secrets, "@entriesMountPoint@%s" % (initrd)])
except FileNotFoundError:
pass
except subprocess.CalledProcessError:
Expand All @@ -129,7 +129,7 @@ def write_entry(profile: Optional[str], generation: int, specialisation: Optiona
f'for "{title} - Configuration {generation}", an older generation', file=sys.stderr)
print("note: this is normal after having removed "
"or renamed a file in `boot.initrd.secrets`", file=sys.stderr)
entry_file = "@efiSysMountPoint@/loader/entries/%s" % (
entry_file = "@entriesMountPoint@/loader/entries/%s" % (
generation_conf_filename(profile, generation, specialisation))
tmp_path = "%s.tmp" % (entry_file)
kernel_params = "init=%s " % profile_path(profile, generation, specialisation, "init")
Expand Down Expand Up @@ -188,13 +188,13 @@ def get_specialisations(profile: Optional[str], generation: int, _: Optional[str


def remove_old_entries(gens: List[SystemIdentifier]) -> None:
rex_profile = re.compile("^@efiSysMountPoint@/loader/entries/nixos-(.*)-generation-.*\.conf$")
rex_generation = re.compile("^@efiSysMountPoint@/loader/entries/nixos.*-generation-([0-9]+)(-specialisation-.*)?\.conf$")
rex_profile = re.compile("^@entriesMountPoint@/loader/entries/nixos-(.*)-generation-.*\.conf$")
rex_generation = re.compile("^@entriesMountPoint@/loader/entries/nixos.*-generation-([0-9]+)(-specialisation-.*)?\.conf$")
known_paths = []
for gen in gens:
known_paths.append(copy_from_profile(*gen, "kernel", True))
known_paths.append(copy_from_profile(*gen, "initrd", True))
for path in glob.iglob("@efiSysMountPoint@/loader/entries/nixos*-generation-[1-9]*.conf"):
for path in glob.iglob("@entriesMountPoint@/loader/entries/nixos*-generation-[1-9]*.conf"):
if rex_profile.match(path):
prof = rex_profile.sub(r"\1", path)
else:
Expand All @@ -205,7 +205,7 @@ def remove_old_entries(gens: List[SystemIdentifier]) -> None:
continue
if not (prof, gen_number, None) in gens:
os.unlink(path)
for path in glob.iglob("@efiSysMountPoint@/efi/nixos/*"):
for path in glob.iglob("@entriesMountPoint@/efi/nixos/*"):
if not path in known_paths and not os.path.isdir(path):
os.unlink(path)

Expand Down Expand Up @@ -286,8 +286,8 @@ def main() -> None:
print("updating systemd-boot from %s to %s" % (installed_version, available_version))
subprocess.check_call(["@systemd@/bin/bootctl", "--esp-path=@efiSysMountPoint@"] + bootctl_flags + ["update"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an explicit boot-path?

if "@xbootMountPoint@" != "@efiSysMountPoint@":
        bootctl_flags.append("--boot-path=@xbootMountPoint@")


mkdir_p("@efiSysMountPoint@/efi/nixos")
mkdir_p("@efiSysMountPoint@/loader/entries")
mkdir_p("@entriesMountPoint@/efi/nixos")
mkdir_p("@entriesMountPoint@/loader/entries")

gens = get_generations()
for profile in get_profiles():
Expand All @@ -309,9 +309,9 @@ def main() -> None:
else:
raise e

for root, _, files in os.walk('@efiSysMountPoint@/efi/nixos/.extra-files', topdown=False):
relative_root = root.removeprefix("@efiSysMountPoint@/efi/nixos/.extra-files").removeprefix("/")
actual_root = os.path.join("@efiSysMountPoint@", relative_root)
for root, _, files in os.walk('@entriesMountPoint@/efi/nixos/.extra-files', topdown=False):
relative_root = root.removeprefix("@entriesMountPoint@/efi/nixos/.extra-files").removeprefix("/")
actual_root = os.path.join("@entriesMountPoint@", relative_root)

for file in files:
actual_file = os.path.join(actual_root, file)
Expand All @@ -324,17 +324,17 @@ def main() -> None:
os.rmdir(actual_root)
os.rmdir(root)

mkdir_p("@efiSysMountPoint@/efi/nixos/.extra-files")
mkdir_p("@entriesMountPoint@/efi/nixos/.extra-files")

subprocess.check_call("@copyExtraFiles@")

# Since fat32 provides little recovery facilities after a crash,
# it can leave the system in an unbootable state, when a crash/outage
# happens shortly after an update. To decrease the likelihood of this
# event sync the efi filesystem after each update.
rc = libc.syncfs(os.open("@efiSysMountPoint@", os.O_RDONLY))
rc = libc.syncfs(os.open("@entriesMountPoint@", os.O_RDONLY))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a second syncfs command:

if "@xbootMountPoint@" != "@efiSysMountPoint@":
        rc = libc.syncfs(os.open("@efiSysMountPoint@", os.O_RDONLY))
        if rc != 0:
            print("could not sync @efiSysMountPoint@: {}".format(os.strerror(rc)), file=sys.stderr)

if rc != 0:
print("could not sync @efiSysMountPoint@: {}".format(os.strerror(rc)), file=sys.stderr)
print("could not sync @entriesMountPoint@: {}".format(os.strerror(rc)), file=sys.stderr)


if __name__ == '__main__':
Expand Down
12 changes: 12 additions & 0 deletions nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ let
inherit (config.system.nixos) distroName;

memtest86 = optionalString cfg.memtest86.enable pkgs.memtest86plus;

xbootMountPoint = if cfg.xbootMountPoint != null
then cfg.xbootMountPoint
else efi.efiSysMountPoint;

netbootxyz = optionalString cfg.netbootxyz.enable pkgs.netbootxyz-efi;

Expand Down Expand Up @@ -96,6 +100,14 @@ in {
'';
};

xbootMountPoint = mkOption {
default = null;
type = types.nullOr types.string;
description = ''
The vfat mount point for installling entries to an XBOOTLOADER partition.
'';
};

configurationLimit = mkOption {
default = null;
example = 120;
Expand Down
Loading