How-To repartiton (format) a USB flash drive.

The partition and formatting on a USB flash memory drive is sometimes a bit faulty.

Symptoms include (but are not limited to) FreeBSD complaining about the start and/or end of the partiton not being on a track boundary, the total number of sectors not being a multiple of the number of tracks, the drive not being recognised especially in MS Vista and errors when saving files in Windows.

If you have a malfunctioning USB stick try this:

Copy off any files you want to keep. (important)

Plug in the stick and check what device it is recognised as. It's usually da0 if you don't have any SCSI drives. But CHECK.

Now remove the existing partiton information:
# dd if=/dev/zero of=/dev/da0 bs=2m count=1

Create a new slice/partiton
# fdisk -i /dev/da0
In the interactive section accept the defaults except for sysid, which is 165 for FreeBSD but for FAT32 is 12.
Ignore the 'fdisk: Class not found' error.

Create a new file system ('format')
# newfs_msdos -F32 /dev/da0s1

Enjoy working USB drive.
 
killasmurf86 said:
Why would one want to partition usb flash?
Simply run newfs_msdos /dev/da0, and it works well :D

I've seen a flash drive get a corrupted partition table before. No idea how it got that way, but the above is exactly how I was able to make it usable again. (After playing with it to recover the data off of it of course, but that's another discussion.)
 
not to have some secret install that I use for unsavoury activities

killasmurf86 said:
Why would one want to partition usb flash?
Simply run newfs_msdos /dev/da0, and it works well :D

8g flash drive, don't need 8G of fat32 storage*, would like to also have a small install of freebsd (for testing, obviously).



*okay, I didn't need an 8G flash drive at all, but the dang thing was on sale for less than a 4G drive
 
I know this was a few years ago, and sorry to revive a dead thread. But you didn't mention what you paid for that 8g 8 GB flash drive. I just wanted to point out I got a 64 GB USB 2.0 flash drive for $11 US yesterday (I couldn't justify the price increase for USB 3.0, especially when I don't know exact speeds, I'm pretty sure a 2.0 will give me about 15 MB/s which is enough to test drive the other BSDs (a reason to partition, as somebody asked why above).
 
The FreeBSD Handbook mentions newfs_msdos in only two places:
  1. floppy disks (yes, floppy) under <https://docs.freebsd.org/en/books/handbook/disks/#floppies>
  2. zvols under <https://docs.freebsd.org/en/books/handbook/zfs/#zfs-zfs-volume>
– is some other command preferred for this type of file system, or does the Handbook lack a simple example that involves neither archaic media nor ZFS?

… If you have a malfunctioning USB stick …

If the data is disposable, I usually:
  1. repartition the drive to have just one UFS partition, as large as possible
  2. give the partition to UFS
  3. mount the file system
  4. test it with StressDisk, sysutils/stressdisk
  5. if testing succeeds, repartition the drive to use a different file system, typically ZFS.
 
Back
Top