Skip to content

Commit

Permalink
Set ESP output minimum size based on sector size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaanDeMeyer committed Nov 9, 2023
1 parent c10aa71 commit 9c779ab
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9c779ab

Please sign in to comment.