rpi-make-boot-image - Make FAT12/FAT16 images cluster-exact - #388
Merged
Conversation
…SIZE Left to itself mkfs.fat picks the FAT width from the size of the device alone, so an explicit IMAGE_SIZE of 64MB or more failed outright: at the default one sector per cluster the resulting cluster count lies well beyond what the chosen width can address. Determine the width from the number of clusters the image will actually hold, and pass that to mkfs.fat.
The 8.3 name pattern required an extension, and was matched against the full path rather than the file name. Both caused the number of directory entries needed for long file names to be over-estimated.
The image size was derived from a cluster count that counted the root directory entries as data but never accounted for the root directory area itself, which on FAT12 and FAT16 sits outside the data region, and the number of root entries was fixed at 256 regardless of the source files. Size the image instead from the reserved sectors, the FAT, the root directory and the data clusters in turn, allocate it with truncate and drop the -C option so that mkfs.fat is given an exact sector count. Take the number of root directory entries from the source files, rounded up to a whole sector so that the Linux vfat driver will mount the result, and enforce a minimum data region so that very small payloads still produce a filesystem. FAT_OVERHEAD now specifies spare space to leave free in the filesystem and defaults to none, rather than being an allowance for metadata that is now accounted for exactly.
timg236
approved these changes
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.