From 9c779ab42626a90f23a2d7709d3c7dddbb1ebbca Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 9 Nov 2023 19:30:39 +0100 Subject: [PATCH] Set ESP output minimum size based on sector size Based on the sector size, a minimum size is required for FAT32 to be bootable by OVMF. Instead of wasting space by always using 512MB, let's set the minimum size based on the given sector size. --- mkosi/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 5f2abc64c..f941e6321 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -2107,9 +2107,17 @@ def make_esp(state: MkosiState, uki: Path) -> list[Partition]: definitions = state.workspace / "esp-definitions" definitions.mkdir(exist_ok=True) - # Use a minimum of 512MB because otherwise the generated FAT filesystem will have too few clusters to be considered - # a FAT32 filesystem by OVMF which will refuse to boot from it. Always reserve 10MB for filesystem metadata. - size = max(uki.stat().st_size, 502 * 1024**2) + 10 * 1024**2 + # Use a minimum of 36MB or 260MB depending on sector size because otherwise the generated FAT filesystem will have + # too few clusters to be considered a FAT32 filesystem by OVMF which will refuse to boot from it. + # See https://superuser.com/questions/1702331/what-is-the-minimum-size-of-a-4k-native-partition-when-formatted-with-fat32/1717643#1717643 + if state.config.sector_size == 512: + m = 36 + # TODO: Figure out minimum size for 2K sector size + else: + m = 260 + + # Always reserve 10MB for filesystem metadata. + size = max(uki.stat().st_size, (m - 10) * 1024**2) + 10 * 1024**2 # TODO: Remove the extra 4096 for the max size once https://github.com/systemd/systemd/pull/29954 is in a stable # release.