From efbca7d01307a319f270ab65c30871ac31b43e4a Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sun, 10 Dec 2023 17:06:51 +0100 Subject: [PATCH] Install kernels to /boot If users want to use XBOOTLDR partitions, then we have to put the kernels in a separate location from the ESP stuff. Currently we put everything in /efi when building the image, which means that users don't have a way to specify that the kernels should be put in an XBOOTLDR partition. Let's fix this by installing kernels to /boot so that users can populate an XBOOTLDR partition by simply using CopyFiles=/boot:/ in a repart xbootldr partition definition. --- NEWS.md | 12 ++++++++++++ mkosi/__init__.py | 15 ++++++++------- mkosi/resources/mkosi.md | 1 + tests/test_initrd.py | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 175851ae1..0c36ff59b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,17 @@ # mkosi Changelog +## v20 + +- During the image build we now install UKIs/kernels/initrds to `/boot` + instead of `/efi`. While this will generally not be noticeable, users + with custom systemd-repart ESP partition definitions will need to add + `CopyFiles=/boot:/` along with the usual `CopyFiles=/efi:/` to their + ESP partition definitions. By installing UKIs/kernels/initrds to + `/boot`, it becomes possible to use `/boot` to populate an XBOOTLDR + partition which wasn't possible before. Note that this is also safe to + do before `v20` so `CopyFiles=/boot:/` can unconditionally be added to + any ESP partition definition files. + ## v19 - Support for RHEL was added! diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 9abce4185..5420bab4d 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1039,12 +1039,12 @@ def prepare_grub_efi(state: MkosiState) -> None: with config.open("a") as f: f.write('if [ "${grub_platform}" == "efi" ]; then\n') - for uki in (state.root / "efi/EFI/Linux").glob("*.efi"): + for uki in (state.root / "boot/EFI/Linux").glob("*.efi"): f.write( textwrap.dedent( f"""\ menuentry "{uki.stem}" {{ - chainloader /{uki.relative_to(state.root / "efi")} + chainloader /{uki.relative_to(state.root / "boot")} }} """ ) @@ -1065,7 +1065,7 @@ def prepare_grub_bios(state: MkosiState, partitions: Sequence[Partition]) -> Non token = find_entry_token(state) - dst = state.root / "efi" / token + dst = state.root / "boot" / token with umask(~0o700): dst.mkdir(exist_ok=True) @@ -1089,10 +1089,10 @@ def prepare_grub_bios(state: MkosiState, partitions: Sequence[Partition]) -> Non ] initrds += [Path(shutil.copy2(kmods, kdst / "kmods"))] - image = Path("/") / kimg.relative_to(state.root / "efi") + image = Path("/") / kimg.relative_to(state.root / "boot") cmdline = " ".join(state.config.kernel_command_line) initrds = " ".join( - [os.fspath(Path("/") / initrd.relative_to(state.root / "efi")) for initrd in initrds] + [os.fspath(Path("/") / initrd.relative_to(state.root / "boot")) for initrd in initrds] ) f.write( @@ -1567,9 +1567,9 @@ def install_uki(state: MkosiState, partitions: Sequence[Partition]) -> None: token = find_entry_token(state) if roothash: _, _, h = roothash.partition("=") - boot_binary = state.root / f"efi/EFI/Linux/{token}-{kver}-{h}{boot_count}.efi" + boot_binary = state.root / f"boot/EFI/Linux/{token}-{kver}-{h}{boot_count}.efi" else: - boot_binary = state.root / f"efi/EFI/Linux/{token}-{kver}{boot_count}.efi" + boot_binary = state.root / f"boot/EFI/Linux/{token}-{kver}{boot_count}.efi" microcode = build_microcode_initrd(state) @@ -2291,6 +2291,7 @@ def make_disk( [Partition] Type=esp Format=vfat + CopyFiles=/boot:/ CopyFiles=/efi:/ SizeMinBytes={"1G" if bios else "512M"} SizeMaxBytes={"1G" if bios else "512M"} diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 6efc52750..10c19e786 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -1868,6 +1868,7 @@ local directory: [Partition] Type=esp Format=vfat + CopyFiles=/boot:/ CopyFiles=/efi:/ SizeMinBytes=512M SizeMaxBytes=512M diff --git a/tests/test_initrd.py b/tests/test_initrd.py index 428edc36a..f2730ce27 100644 --- a/tests/test_initrd.py +++ b/tests/test_initrd.py @@ -117,6 +117,7 @@ def test_initrd_luks(initrd: Image, passphrase: Path) -> None: [Partition] Type=esp Format=vfat + CopyFiles=/boot:/ CopyFiles=/efi:/ SizeMinBytes=512M SizeMaxBytes=512M -- 2.47.2