From: Daan De Meyer Date: Thu, 9 Nov 2023 18:30:39 +0000 (+0100) Subject: Set ESP output minimum size based on sector size X-Git-Tag: v19~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2060%2Fhead;p=thirdparty%2Fmkosi.git 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. --- 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.