Format USB Stick with FAT32 on FreeBSD

Formatting USB drive with FAT32 using FreeBSD

Zero disk beginning with
$ dd if=/dev/zero of=/dev/da0 bs=2m count=1

Change first partition type to 12 (FAT32)
$ fdisk -i /dev/da0
[....]
Do you want to change our idea of what BIOS thinks ? [n] n
[...]
fdisk: invalid fdisk partition table found <== No MBR found!!!
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 15663312 (7648 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 974/ head 254/ sector 63
Do you want to change it? [n] y

The static data for the slice 1 has been reinitialized to:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 15663312 (7648 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 974/ head 254/ sector 63
Supply a decimal value for "sysid (165=FreeBSD)" [165] 12
Supply a decimal value for "start" [63]
Supply a decimal value for "size" [15663312]
Explicitly specify beg/end address ? [n]
sysid 12 (0x0c),(DOS or Windows 95 with 32 bit FAT (LBA))
    start 63, size 15663312 (7648 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 974/ head 254/ sector 63
Are we happy with this entry? [n] y

[...]

We haven't changed the partition table yet.  This is your last chance.
parameters extracted from in-core disklabel are:
cylinders=975 heads=255 sectors/track=63 (16065 blks/cyl)

parameters to be used for BIOS calculations are:
cylinders=975 heads=255 sectors/track=63 (16065 blks/cyl)

Information from DOS bootblock is:
1: sysid 12 (0x0c),(DOS or Windows 95 with 32 bit FAT (LBA))
    start 63, size 15663312 (7648 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 974/ head 254/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
Should we write new partition table? [n] y

Initialize fat32 file system
$ newfs_msdos -F32 /dev/da1s1
/dev/da1s1: 15659456 sectors in 244679 FAT32 clusters (32768 bytes/cluster)
BytesPerSec=512 SecPerClust=64 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63
Heads=255 HiddenSecs=0 HugeSectors=15663312 FATsecs=1912 RootCluster=2
FSInfo=1 Backup=2
List existing partitions
$ gpart show da0

Delete existing partitions
$ gpart delete -i 1 da0
1 being partition index, you might need to repeat this depending on output from gpart show

destroy label after deleting all partitions
$ gpart destroy da0

create new mbr spanning entire disk
$ gpart create -s mbr da0

create new fat32 partition spanning entire disk
$ gpart add -t fat32 da0

Initialize fat32 file system
$ newfs_msdos -F32 /dev/da0s1

3 thoughts on “Format USB Stick with FAT32 on FreeBSD

  1. Pingback: Create Ubuntu USB Stick | Andreas' Blog

  2. Steve

    Hiya. You change the partition on /dev/da0, and then you format /dev/da1s1 — small error, but could result in someone else messing up 🙂

    Reply
    1. te-bachi Post author

      I don’t remember why I wrote this, but maybe a copy/paste problem. Thanks for pointing this out.

      Reply

Leave a Reply to Steve Cancel reply

Your email address will not be published. Required fields are marked *