Bug 290857 - bsdinstall: install produces fat16 EFI filesystem - should be fat32
Summary: bsdinstall: install produces fat16 EFI filesystem - should be fat32
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
URL:
Keywords: install, uefi
Depends on:
Blocks:
 
Reported: 2025-11-07 16:19 UTC by ykla
Modified: 2025-11-12 18:47 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ykla 2025-11-07 16:19:42 UTC
Background: According to the UEFI specification ([https://uefi.org/specs/UEFI/2.11/13_Protocols_Media_Access.html](https://uefi.org/specs/UEFI/2.11/13_Protocols_Media_Access.html)), section 13.3 “File System Format,” system drives such as SSDs or HDDs should use FAT32. Only removable media are allowed to use FAT16 or FAT12. In fact, this is also a discouraged practice — UEFI recommends using FAT32 whenever possible:

"EFI encompasses the use of FAT32 for a system partition, and FAT12 or FAT16 for removable media. The FAT32 system partition is identified by an OSType value other than that used to identify previous versions of FAT. This unique partition type distinguishes an EFI defined file system from a normal FAT file system. The file system supported by EFI includes support for long file names."

---------------------

According to [https://reviews.freebsd.org/D28897](https://reviews.freebsd.org/D28897) and [https://cgit.freebsd.org/src/tree/usr.sbin/bsdinstall/scripts/zfsboot](https://cgit.freebsd.org/src/tree/usr.sbin/bsdinstall/scripts/zfsboot), the partition editor will reuse an existing ESP; otherwise, it will create one and format it as FAT32.

--------------

According to `NEWFS_ESP='newfs_msdos "%s"'`, `"$align_small" efiboot$index efi 260M \`, and the source code of `newfs_msdos` ([https://cgit-dev.freebsd.org/src-test/plain/sbin/newfs_msdos/mkfs_msdos.c?h=main](https://cgit-dev.freebsd.org/src-test/plain/sbin/newfs_msdos/mkfs_msdos.c?h=main)), the result of running `newfs_msdos` on a 260M partition is always FAT16 unless the `-F 32` option is specified. However, due to incorrect cluster allocation, it is effectively impossible to manually reformat it as FAT32.

---------------

root@ykla:/home/ykla/FreeBSD-Ask/netbsd/src # gpart show
=>       40  209715120  nda0  GPT  (100G)
         40     532480     1  efi  (260M)
     532520       1024     2  freebsd-boot  (512K)
     533544        984        - free -  (492K)
     534528    4194304     3  freebsd-swap  (2.0G)
    4728832  204984320     4  freebsd-zfs  (98G)
  209713152       2008        - free -  (1.0M)

root@ykla:/home/ykla/FreeBSD-Ask/netbsd/src # file -s /dev/nda0p1
/dev/nda0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "BSD4.4  ", sectors/cluster 32, root entries 512, sectors/FAT 65, sectors/track 63, heads 255, sectors 532480 (volumes > 32 MB), serial number 0x40cc140d, unlabeled, FAT (16 bit)

root@ykla:~ # newfs_msdos -F 32 /dev/nvd0p1
newfs_msdos: 16630 clusters too few clusters for FAT32, need 65525
Comment 1 Marek Zarychta 2025-11-07 16:34:22 UTC
Please try: 
newfs_msdos -c 8 -F 32 /device/path
and you should be fine.
Comment 2 Marek Zarychta 2025-11-07 16:41:41 UTC
Perhaps issuing 
newfs_msdos -F 32 
should pick something other than the current defaults. In newfs_msdos(8) we can read:
   
   -c cluster-size
             Sectors per cluster, also called allocation size.  Acceptable
             values are powers of 2 in the range 1 through 128.  If the block
             or cluster size are not specified, the code uses a cluster
             between 512 bytes and 32K depending on the filesystem size

It degrades the user experience for the average FreeBSD user. Our newfs_msdos(8) should work out of the box in such use cases like formatting thumb drives etc, where user specifies only -F 32 as an option without deeply investigating any cluster size issues.
Comment 3 ykla 2025-11-07 16:47:25 UTC
If you choose GPT (UEFI) during installation, the result will be the same:

root@ykla:/home/ykla # gpart show
=>      40  33554352  nda0  GPT  (16G)
        40    532480     1  efi  (260M)
    532520      2008        - free -  (1.0M)
    534528   4194304     2  freebsd-swap  (2.0G)
   4728832  28823552     3  freebsd-zfs  (14G)
  33552384      2008        - free -  (1.0M)


root@ykla:/home/ykla # file -s /dev/nda0p1
/dev/nda0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "BSD4.4  ", sectors/cluster 32, root entries 512, sectors/FAT 65, sectors/track 63, heads 255, sectors 532480 (volumes > 32 MB), serial number 0x74e20813, unlabeled, FAT (16 bit)

root@ykla:/home/ykla #  newfs_msdos -F 32 /dev/nvd0p1
newfs_msdos: 16630 clusters too few clusters for FAT32, need 65525
Comment 4 ykla 2025-11-07 16:49:36 UTC
(In reply to Marek Zarychta from comment #2)
I'm also not sure whether it would actually affect 4K alignment.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2025-11-07 17:01:15 UTC
Remove URL, the mentioned review (D28897) is not a fix for this issue.
https://reviews.freebsd.org/D28897
Comment 6 Ed Maste freebsd_committer freebsd_triage 2025-11-07 17:58:19 UTC
(In reply to Marek Zarychta from comment #1)
> newfs_msdos -c 8 -F 32 /device/path

The default ESP partition is 100MB and newfs_msdos won't create a fat32 filesystem:

root@framework:/home/emaste # newfs_msdos -F32 -c8 md0
newfs_msdos: cannot get number of sectors per track: Operation not supported
newfs_msdos: cannot get number of heads: Operation not supported
newfs_msdos: 25546 clusters too few clusters for FAT32, need 65525

It succeeds with -c1 or -c2.

As a point of comparison I'm looking at a Windows 10 VM, which has a 100MB FAT32 ESP.
Comment 7 Warner Losh freebsd_committer freebsd_triage 2025-11-07 18:17:24 UTC
So EFI standard 2.9 says a few paragraphs later
"The EFI firmware must support the FAT32, FAT16, and FAT12 variants of the EFI file system."

There's a minimal size for FAT32 as well, and there's no *REQUIREMENT* that the ESP be a minimum size to support it. And the word 'encompasses' to me reads as 'typically includes' not 'prescriptively limits'. Partitions smaller than the minimum size for FAT32 can't be FAT32.

So is this a bug on a specific system? Are there systems that won't boot if we don't do this? Are we limiting storage on a large partition by only formatting it with FAT16?
Comment 8 ykla 2025-11-07 18:42:39 UTC
(In reply to Ed Maste from comment #5)
Sorry, not onle ZFS but also UFS install

----------
root@ykla:/home/ykla # gpart show
=>      40  33554352  nda0  GPT  (16G)
        40    532480     1  efi  (260M)
    532520  30924800     2  freebsd-ufs  (15G)
  31457320   1677312     3  freebsd-swap  (819M)
  33134632    419760        - free -  (205M)

root@ykla:/home/ykla # file -s /dev/nda0p1
/dev/nda0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "BSD4.4  ", sectors/cluster 32, root entries 512, sectors/FAT 65, sectors/track 63, heads 255, sectors 532480 (volumes > 32 MB), serial number 0x22db0a0c, unlabeled, FAT (16 bit)
root@ykla:/home/ykla # umount /boot/efi
root@ykla:/home/ykla #  newfs_msdos -F 32 /dev/nvd0p1
newfs_msdos: 16630 clusters too few clusters for FAT32, need 65525

-------------------

Furthermore, both [https://reviews.freebsd.org/D28897](https://reviews.freebsd.org/D28897) and [https://wiki.freebsd.org/UEFI](https://wiki.freebsd.org/UEFI) — “Create the ESP as a 40MB FAT32 filesystem to maximize compatibility” — were intended to achieve that stated goal.

Most Linux distributions, Windows, and even Intel-based macOS systems also use FAT32 for their EFI partitions.
Comment 9 Ed Maste freebsd_committer freebsd_triage 2025-11-07 20:22:47 UTC
(In reply to Ed Maste from comment #6)
> The default ESP partition is 100MB
I must have looked at a VM installed from an older version; I tried a 15.0-alpha just now it's 260MB.
Comment 10 Ed Maste freebsd_committer freebsd_triage 2025-11-07 23:03:28 UTC
Fix part 1: https://reviews.freebsd.org/D53639
Comment 11 ykla 2025-11-08 02:24:44 UTC
Additionally, the ESP of USB boot drives created from -.img image files is also FAT16 rather than FAT32. The ESP in some SBC devices' -.img image files is also FAT16, such as the Raspberry Pi. According to my tests, FreeBSD-14.3-RELEASE-amd64-memstick.img is now FAT32 (I’m not sure when this change happened, but it used to be FAT16). However, FreeBSD-14.3-RELEASE-arm64-aarch64-RPI.img.xz, although labeled as FAT32-LBA, is actually FAT16 after being written to media, and 7-Zip also identifies it as FAT16.

According to information from the Raspberry Pi forum and documentation, this boot partition should be FAT32:

https://www.raspberrypi.com/documentation/computers/linux_kernel.html

“If sdb represents your boot media, sdb1 represents the FAT32-formatted boot partition and sdb2 represents the (likely ext4-formatted) root partition.”

https://forums.raspberrypi.com/viewtopic.php?t=360552

https://hub.mender.io/t/raspberry-pi-3b-boot-partition-filesystem/2158

Currently, the FAT16 filesystem on the Raspberry Pi frequently triggers fsck errors (though it doesn’t prevent booting), but fsck cannot actually fix them, even when invoked with the msdos parameter.
Comment 12 commit-hook freebsd_committer freebsd_triage 2025-11-08 15:06:57 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e36942420712c2ab6ebc2c646e61d47b2b68e7b

commit 4e36942420712c2ab6ebc2c646e61d47b2b68e7b
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-11-07 22:53:01 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-11-08 15:01:35 +0000

    bsdinstall: Fix newfs bsddialog menu

    The second and third members of struct bsddialog_menuitem are `bool on`
    and `unsigned int depth`. The newfs dialog options in bsdinstall's
    partition tool had these two swapped, so the default selection did not
    work.

    PR: 290857
    Reviewed by: asiciliano
    Fixes: 50e244964e9b ("bsdinstall/partedit: Replace libdialog with libbsddialog")
    Sponsored by: The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53639

 usr.sbin/bsdinstall/partedit/gpart_ops.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2025-11-10 03:07:35 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=980aa8d4cfdf57a1f99401fa4160c0d82c927d7c

commit 980aa8d4cfdf57a1f99401fa4160c0d82c927d7c
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-11-07 22:53:01 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-11-10 03:06:53 +0000

    bsdinstall: Fix newfs bsddialog menu

    The second and third members of struct bsddialog_menuitem are `bool on`
    and `unsigned int depth`. The newfs dialog options in bsdinstall's
    partition tool had these two swapped, so the default selection did not
    work.

    PR: 290857
    Reviewed by: asiciliano
    Fixes: 50e244964e9b ("bsdinstall/partedit: Replace libdialog with libbsddialog")
    Sponsored by: The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53639

    (cherry picked from commit 4e36942420712c2ab6ebc2c646e61d47b2b68e7b)

 usr.sbin/bsdinstall/partedit/gpart_ops.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Comment 14 commit-hook freebsd_committer freebsd_triage 2025-11-10 19:01:08 UTC
A commit in branch releng/15.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e55b2f03215ed91df015445c40f9caf052cbb343

commit e55b2f03215ed91df015445c40f9caf052cbb343
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-11-07 22:53:01 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-11-10 19:00:15 +0000

    bsdinstall: Fix newfs bsddialog menu

    The second and third members of struct bsddialog_menuitem are `bool on`
    and `unsigned int depth`. The newfs dialog options in bsdinstall's
    partition tool had these two swapped, so the default selection did not
    work.

    Approved by:    re (cperciva)
    PR: 290857
    Reviewed by: asiciliano
    Fixes: 50e244964e9b ("bsdinstall/partedit: Replace libdialog with libbsddialog")
    Sponsored by: The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53639

    (cherry picked from commit 4e36942420712c2ab6ebc2c646e61d47b2b68e7b)
    (cherry picked from commit 980aa8d4cfdf57a1f99401fa4160c0d82c927d7c)

 usr.sbin/bsdinstall/partedit/gpart_ops.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Comment 15 commit-hook freebsd_committer freebsd_triage 2025-11-12 13:25:34 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=65e347d315449e8c28dbcb0c5bb64f79d822d024

commit 65e347d315449e8c28dbcb0c5bb64f79d822d024
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-11-07 22:48:30 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-11-12 13:23:51 +0000

    bsdinstall: Use fat32 EFI system partition for ZFS

    This is consistent with other operating systems and with bsdinstall's
    UFS config and with bsdinstall's ZFS config prior to commit
    0b7472b3d8d2.

    PR:             290857
    Fixes: 0b7472b3d8d2 ("Mount the EFI system partition (ESP) on newly-installed systems.")
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53642

    (cherry picked from commit 4109cdf0f817162cf3032aa589dd180dfa910025)

 usr.sbin/bsdinstall/scripts/zfsboot | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 16 commit-hook freebsd_committer freebsd_triage 2025-11-12 15:48:58 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ad17166c57bb0ccd683b3136c170d8f66304d5b2

commit ad17166c57bb0ccd683b3136c170d8f66304d5b2
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-11-07 22:48:30 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-11-12 15:47:42 +0000

    bsdinstall: Use fat32 EFI system partition for ZFS

    This is consistent with other operating systems and with bsdinstall's
    UFS config and with bsdinstall's ZFS config prior to commit
    0b7472b3d8d2.

    PR:             290857
    Fixes: 0b7472b3d8d2 ("Mount the EFI system partition (ESP) on newly-installed systems.")
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53642

    (cherry picked from commit 4109cdf0f817162cf3032aa589dd180dfa910025)
    (cherry picked from commit 65e347d315449e8c28dbcb0c5bb64f79d822d024)

 usr.sbin/bsdinstall/scripts/zfsboot | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 17 commit-hook freebsd_committer freebsd_triage 2025-11-12 15:48:59 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3ced4a2b482f50672bba26de3f26273a73f75b9c

commit 3ced4a2b482f50672bba26de3f26273a73f75b9c
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-11-07 22:53:01 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-11-12 15:47:42 +0000

    bsdinstall: Fix newfs bsddialog menu

    The second and third members of struct bsddialog_menuitem are `bool on`
    and `unsigned int depth`. The newfs dialog options in bsdinstall's
    partition tool had these two swapped, so the default selection did not
    work.

    PR: 290857
    Reviewed by: asiciliano
    Fixes: 50e244964e9b ("bsdinstall/partedit: Replace libdialog with libbsddialog")
    Sponsored by: The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53639

    (cherry picked from commit 4e36942420712c2ab6ebc2c646e61d47b2b68e7b)
    (cherry picked from commit 980aa8d4cfdf57a1f99401fa4160c0d82c927d7c)

 usr.sbin/bsdinstall/partedit/gpart_ops.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Comment 18 commit-hook freebsd_committer freebsd_triage 2025-11-12 18:47:34 UTC
A commit in branch releng/15.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c5977a934c6ac4f8a6483829486a489aec6aacdd

commit c5977a934c6ac4f8a6483829486a489aec6aacdd
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-11-07 22:48:30 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-11-12 18:46:12 +0000

    bsdinstall: Use fat32 EFI system partition for ZFS

    This is consistent with other operating systems and with bsdinstall's
    UFS config and with bsdinstall's ZFS config prior to commit
    0b7472b3d8d2.

    Approved by:    re (cperciva)
    PR:             290857
    Fixes: 0b7472b3d8d2 ("Mount the EFI system partition (ESP) on newly-installed systems.")
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53642

    (cherry picked from commit 4109cdf0f817162cf3032aa589dd180dfa910025)
    (cherry picked from commit 65e347d315449e8c28dbcb0c5bb64f79d822d024)

 usr.sbin/bsdinstall/scripts/zfsboot | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)