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



## michaelrmgreen (Feb 12, 2010)

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.


----------



## graudeejs (Feb 12, 2010)

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


----------



## michaelrmgreen (Feb 12, 2010)

Hmmm, now I'm going to have to find another USB drive with a wonky filesystem to try that on.


----------



## Ruler2112 (Feb 12, 2010)

killasmurf86 said:
			
		

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



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.)


----------



## fronclynne (Feb 12, 2010)

*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



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


----------



## ikbendeman (Dec 1, 2013)

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 j_ust 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).


----------



## vieron (Aug 27, 2021)

I know this is old, nevertheless  I would like to post the following link which I found informative and helpful to format a USB drive for Windows: https://lists.freebsd.org/pipermail/freebsd-questions/2010-May/215819.html

It is very similar to michaelrmgreen's answer at the top but with a bit more explanation of the steps involved.


----------



## grahamperrin@ (Aug 28, 2021)

The FreeBSD Handbook mentions `newfs_msdos` in only two places:

floppy disks (yes, _floppy_) under <https://docs.freebsd.org/en/books/handbook/disks/#floppies>
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?



michaelrmgreen said:


> … If you have a malfunctioning USB stick …



If the data is disposable, I usually:

repartition the drive to have just one UFS partition, as large as possible
give the partition to UFS
mount the file system
test it with StressDisk, sysutils/stressdisk
if testing succeeds, repartition the drive to use a different file system, typically ZFS.


----------

