mallory.computer

HOWTO: Create a Windows-readable disk with FreeBSD

This HOWTO will describe the process of using FreeBSD to format a disk with the FAT32 filesystem so that it can be read by Windows and macOS.

Steps

  1. Open a terminal and run geom disk list to view all attached disks. You should be able to identify it by the size of the disk (“mediasize”) and the manufacturer’s name (“descr”).

    Sample output of geom disk list:

    Geom name: da0
    Providers:
    1. Name: da0
    Mediasize: 8166703104 (7.6G)
    Sectorsize: 512
    Mode: r0w0e0
    descr: Verbatim micro USB
    ident: 11122488000854
    rotationrate: unknown
    fwsectors: 63
    fwheads: 255

    The name is what we need. Here that’s da0, but for the remainder of this document I’ll refer to it as XXX to prevent copy/paste accidents.

  2. Run su to switch to root.
  3. As root, run the following commands.

    WARNING

    The following commands are destructive. The disk’s existing data will be overwritten and will become impossible to retrieve. Only proceed if you’re sure you’re using the correct disk.

    1. Destroy the existing partition scheme (if any).

      gpart destroy -F XXX
    2. Create a new MBR partition scheme.

      gpart create -s MBR XXX
    3. Create a FAT32 (LBA) partition.

      gpart add -t fat32lba XXX
    4. Write a filesystem to the partition we just created.

      newfs_msdos XXXs1
    5. mount -t msdos XXXs1 /mnt
    6. Put some files on /mnt.
    7. umount /mnt
    8. It is now safe to remove the disk.

Notes

gpart supports two FAT32 partition types: fat32 and fat32lba (also known as 0x0b and 0x0c). It's unclear what the precise difference is, but some random forum posts seem to suggest the LBA variant supports filesystems larger than 2GiB.