Bug 210661 - geom_part does not recognize MBR partition type !12 (0Ch) used by BeagleBone Black
Summary: geom_part does not recognize MBR partition type !12 (0Ch) used by BeagleBone ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-28 13:33 UTC by Ed Maste
Modified: 2023-03-01 00:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2016-06-28 13:33:48 UTC
Using the most recent snapshot sd card image on a BeagleBone Black, gpart does not recognize the FAT-formatted boot partition type:

root@beaglebone:~ # gpart show
=>      63  61896641  mmcsd0  MBR  (30G)
        63      4095       1  !12  [active]  (2.0M)
      4158  61886402       2  freebsd  (30G)
  61890560      6144          - free -  (3.0M)

=>       0  61886402  mmcsd0s2  BSD  (30G)
         0        66            - free -  (33K)
        66  61886336         1  freebsd-ufs  (30G)

=>      1  3751935  mmcsd1  MBR  (1.8G)
        1       62          - free -  (31K)
       63   144522       1  !12  [active]  (71M)
   144585  3598560       2  linux-data  (1.7G)
  3743145     8791          - free -  (4.3M)

=>      1  3751935  diskid/DISK-56856FEC  MBR  (1.8G)
        1       62                        - free -  (31K)
       63   144522                     1  !12  [active]  (71M)
   144585  3598560                     2  linux-data  (1.7G)
  3743145     8791                        - free -  (4.3M)

For comparison Linux fdisk reports this as:

root@beaglebone:~# fdisk -l /dev/mmcblk0  

Disk /dev/mmcblk0: 1920 MB, 1920991232 bytes
255 heads, 63 sectors/track, 233 cylinders, total 3751936 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *          63      144584       72261    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          144585     3743144     1799280   83  Linux

Wikipedia concurs that this is FAT32 with LBA. Despite this, the filesystem contained in the stock eMMC on the BBB is actually FAT12:

/dev/mmcsd0s1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "BSD4.4  ", root entries 512, sectors 4095 (volumes <=32 MB) , sectors/FAT 12, sectors/track 63, heads 255, serial number 0x5de21501, label: "MSDOSBOOT  ", FAT (12 bit), followed by FAT

For comparison the filesystem on the snapshot SD card image is:

root@beaglebone:~ # file -s /dev/mmcsd1s1
/dev/mmcsd1s1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "mkdosfs", Media descriptor 0xf8, sectors/track 16, heads 4, sectors 144522 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 1112, serial number 0x51470be5, label: "BEAGLEBONE "
Comment 1 Ed Maste freebsd_committer freebsd_triage 2023-02-28 20:45:44 UTC
See also

commit d98a4eb807e972ac207264043ba3c50ba94f5df5
Author: Jose Luis Duran <jlduran@gmail.com>
Date:   Fri Jun 18 11:55:24 2021 -0300

    mkimg: Add fat32lba partition type
    
    Syntactic sugar for a `gpart add -t '!12' ...` equivalent.
    
    Reviewed by:    emaste
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/484

 usr.bin/mkimg/ebr.c    | 1 +
 usr.bin/mkimg/mbr.c    | 1 +
 usr.bin/mkimg/scheme.c | 1 +
 usr.bin/mkimg/scheme.h | 1 +
 4 files changed, 4 insertions(+)
Comment 2 Jose Luis Duran 2023-02-28 22:54:45 UTC
Is there something I can help with?

I believe BBB images are still built using [1]:
    gpart add -t '!12' -a 512k -s ${FAT_SIZE} ${mddev}

Where FAT_SIZE is 16.

I do not have a BBB board, I only have a couple of RPis (3 and 4).

I used to build its SD cards using a modified in-tree NanoBSD/embedded script, which consumed the change referenced in comment #1 [2] (private archived repo, can grant access upon request), essentially:

    if [ -n "$NANO_SLICE_FAT" ]; then
    	eval $NANO_SLICE_FAT=fat32lba
    fi

Instead of fat16b.

This work was unfinished, and not upstreamed, sorry... I shifted towards creating those images using poudriere [3]. However, I have never created an ARM image using release.sh.

I believe adding something like [3] could probably work in choosing the right type/size.

I'm not sure if it is of much help.

[1]: https://cgit.freebsd.org/src/tree/release/tools/arm.subr?id=5e54bb1ea9e904075225dc96641c2ede3fc3273c#n79
[2]: https://github.com/jlduran/NanoBSD-Pi/blob/0ec1758009c31b04b35f49efd82979945ccfe309/common#L300-L302 (private repo)
[3]: https://github.com/jlduran/rpi/blob/aaf547dd03e4c6de020757da281d2d39b6add07d/pre-script-ufs.sh#L14-L63
Comment 3 Jose Luis Duran 2023-02-28 23:39:17 UTC
Oh I think it's just the label in gpart show that needed a human name?

If yes, then, this can be closed (MWE?):

# mdconfig -a -t swap -s 5m -u 1

# newfs -U md1
/dev/md1: 5.0MB (10240 sectors) block size 32768, fragment size 4096
	using 4 cylinder groups of 1.28MB, 41 blks, 256 inodes.
	with soft updates
super-block backups (for fsck_ffs -b #) at:
 192, 2816, 5440, 8064

# gpart create -s mbr /dev/md1
md1 created

# gpart add -t fat32lba md1
md1s1 added

# gpart show md1
=>    1  10239  md1  MBR  (5.0M)
      1  10239    1  fat32lba  (5.0M)
Comment 4 Ed Maste freebsd_committer freebsd_triage 2023-03-01 00:42:53 UTC
Hmm, you're right

https://cgit.freebsd.org/src/commit/?id=b525a10ac02d7918fa581753bec5d5e54d8c8998

commit b525a10ac02d7918fa581753bec5d5e54d8c8998
Author: Ed Maste <emaste@FreeBSD.org>
Date:   Fri May 4 00:34:27 2018 +0000

    gpart: add fat32lba MBR partition type
    
    FAT32 partition with LBA addressing.
    
    Reviewed by:    marcel
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D15266

Notes:
    svn path=/head/; revision=333233