# Formatting a USB stick



## michaelrmgreen (Feb 5, 2010)

Someone has given me a Kingston Mini Slim Datatraveller 8Gb flash memory stick to 'fix'.

She complains that it 'doesn't work under Vista but works OK under XP'. She has tried multiple systems.

I've been here before with USB sticks with a funny format. Sure enough FBSD 8.0 reports:

```
ugen1.3: <Kingston> at usbus1
umass0: <Kingston DT Mini Slim, class 0/0, rev 2.00/2.00, addr 3> on usbus1
umass0: SCSI over Bulk-Only; quirks = 0x0000
umass0:0:0:-1: Attached to scbus0
da0 at umass-sim0 bus 0 target 0 lun 0
da0: <Kingston DT Mini Slim 1.00> Removable Direct Access SCSI-2 device
da0: 1.000MB/s transfers
da0: 7696MB (15761408 512 byte sectors: 255H 63S/T 981C)
GEOM: da0: partition 1 does not start on a track boundary.
GEOM: da0: partition 1 does not end on a track boundary.
```

and, with the Mtools installed and /dev/da0s1 configured as u:


```
mdir u:
Total number of sectors (15759336) not a multiple of sectors per track (63)!
```

Hmmm, wonky formatting, "bad Kingston, bad". What to do? Well the first thing I tried was copious Googling. Lots of matches but little constructive advice. Next try, reformatting with the HP tool using XP. Some improvement, no complaints about the partition start, but still a problem with the partition end. Mtools still complains about the number of sectors (now slightly different) not being a multiple of the number of sectors-per-track.

Maybe the problem with Vista is fixed, maybe not. I won't be happy until there are no error messages. I'm difficult like that.

So, long story short (tl;dr as they say) how do I format a USB stick with a 'tidy' FAT32 format that starts and ends on a track boundary?


----------



## michaelrmgreen (Feb 5, 2010)

Additional information.

Using another Widnows utility 'Swissknife' or using the 'format f: /FS:FAT32' command line utility in XP creates formats which don't have a partition/slice on them as recognised by FBSD 8.0. In other words, with the HP utility I get da0 AND da0s1 in /dev, but with Swissknife and 'format ...' I only get da0 in /dev, no da0s1!

Further additional information.

The free version of Paragon Partition Manager can create and format a slice/partiton that doesn't prompt any error messages from GEOM or Mtools! Go Paragon!.

Lesson? USB factory formats are all the rubbish. Kill them with fire.


----------



## J65nko (Feb 5, 2010)

I just wonder why did not check the USB disk with *fdisk*


----------



## Ruler2112 (Feb 5, 2010)

First off, dude, you're showing your windoze-ness - one does not 'format' a drive, one partitions it and then creates a file system inside the partition.   'Format' is a term invented by M$ so that the masses might semi-understand what's going on.  (It's not really accurate in reflecting actual reality, but this really isn't at all unusual for M$ either...)  Also, mtools is for people who don't want to learn a real OS.  :e 

I've run into problems with this type of thing before.  Being very unimpressed with the FreeBSD fdisk utility, I use the System Rescue CD for stuff like this, which is Gentoo based.  (Don't get me wrong - FreeBSD is a fantastic OS and much more stable and easier to administer than my Linux boxes, but I find that a tool like this is more appropriate for tasks like this.  Pretty much any Linux LiveCD will work with what I describe here, except for gParted, which is optional.)  First off, boot from the CD and it'll bring up a shell.  If you want a GUI, start X and run gParted.  If not, simply use [cmd=]fdisk /dev/sdx[/cmd] - I find the actual fdisk to be easier and it's certainly much faster.  Either way, delete all current partitions.  If you want to be 100% certain that _everything_ is gone before doing this, and save the step of deleting the existing partitions, do [cmd=]dd if=/dev/zero of=/dev/sdx bs=1M[/cmd] beforehand - this will wipe the entire drive with all 0s.  Then create a new partition (or more, depending on your needs).  This will be type 83 by default - change it to type 0Bh.  Write out the partition table, then do a [cmd=]mkfs -t vfat /dev/sdx1[/cmd] to create a FAT32 file system.  Repeat as needed if you created more than one partition.

!!!WARNING!!! The above will erase EVERYTHING on the drive.  Be *ABSOLUTELY POSITIVELY CERTAIN* that you are operating on the correct device node!  [cmd=]fdisk -l[/cmd] will show a list of partitions without changing anything - I suggest using it before and after plugging your flash drive in and comparing the results to determine which node to use.  !!!WARNING!!!


----------



## barberry (Feb 8, 2010)

I've used the FreeBSD install cd to format a thumb drive with
FAT.


----------



## michaelrmgreen (Feb 10, 2010)

Stung by Ruler2112s criticism "First off, dude, you're showing your windoze-ness" I determined to discover the 'right' way to solve my USB stick problem. 

First I reviewed the Handbook, and (as per barberry above) used sysinstall to create a new slice. During that successful proceedure I noticed that it would be easy to operate on the wrong disk.

With that in mind I decieded to use fdisk(8). Long story short, fdisk failed with the message:
fdisk: Class not found.

Googling lead me to a message suggesting I should have used gpart(8).

Perusal of man 8 gpart doesn't immediately indicate how it should be used to create a new slice.

OK, still with me? How do I use gpart to create a new slice on a USB drive (/dev/da0)? Am I even on the right track? TIA


----------



## fronclynne (Feb 10, 2010)

*Tada is a very important thing.  Do not cornfuse with Tata or Tatu.*

I have had success with the following method:

`# dd if=/dev/zero of=/dev/da0 bs=2m` (this zeros the whole drive.  if you're worried about wearing it out, just append count=1)
`# fdisk -i /dev/da0` change the partition type to 12, & accept the rest of the defaults that it hands you.  [red]you will get the "fdisk: Class not found." error.  you can safely ignore it[/red]
`# newfs_msdos -F32 /dev/da0s1`
Tada.

Notes:  newfs_msdos(8), fdisk(8), dd(1), Tada!


----------



## michaelrmgreen (Feb 12, 2010)

Alright fronclynne, your advice was bang on. I've taken the liberty of making them into a How-To.


----------



## Ruler2112 (Feb 12, 2010)

michaelrmgreen said:
			
		

> Stung by Ruler2112s criticism "First off, dude, you're showing your windoze-ness" I determined to discover the 'right' way to solve my USB stick problem.



It wasn't meant as criticism, more a gentle jab at your using the 'format' terminology intended to be humorous.  'Formatting' a drive is really just creating a file system on it with a rudimentary surface scan included.  (Unless doing a 'quick format', which is a term that indicates that the surface scan should be skipped.)

It's just a difference in saying what's really happening versus the M$ way of hiding it behind not-so-clever terms.


----------



## Rastko (Feb 6, 2018)

Ruler2112 said:


> First off, dude, you're showing your windoze-ness - one does not 'format' a drive, one partitions it and then creates a file system inside the partition.   'Format' is a term invented by M$ so that the masses might semi-understand what's going on.  (It's not really accurate in reflecting actual reality, but this really isn't at all unusual for M$ either...)  Also, mtools is for people who don't want to learn a real OS.  :e



Your criticism was well versed, except

Typing 





> M$


 is a symptom of addiction to UNIXanax  :e

Yeah we all get it. Gates was in it for the money. So are Int€l and AMD, but seen no one's complaining as of ¥et.
I'll grant you this, MS is also an acronym for a very crappy immuno-disease.
May I remind you that Gates wrote the first microcomputer's operating system? Stop with this non$en$e. That's for pa$$word$.


----------



## Maelstorm (Feb 6, 2018)

The quick and easy way of fixing this is as follows:


On the XP machine, copy any data that is on the drive.
Go to a machine with a newer version of Windows (Vista in this case).
Reformat the drive on that machine.
Go back to the XP machine and copy the data back.
Problem Fixed.
As for the strange format, I have formatted USB drives like that.  Since a USB does not have the concepts of geometry like a HDD does, the tools that I wrote pack down the format as much as possible to eliminate any unused space.  Microsoft treats it the same way like a very large floppy disk.  No partitioning, just format so you kinda have to know that it's going to be either FAT32 or FATex.  Usually USB sticks these days are formatted as FATex.


----------



## tobik@ (Feb 6, 2018)

Rastko has resurrected an 8 years old thread for no well-explained reason. I doubt any of the original posters care anymore.


----------



## CraigHB (Feb 6, 2018)

It's easy to overlook the dates on these threads, it's in tiny print at the bottom of the post.  IMO it should be in bold with normal size font at the top of the post. 

Anyway, since this thread was originally created things are more standardized with flash sticks.  Still Windows does not treat them in the manner they should be.  I've not used Win10, but Win7 looks at the stick like a big floppy drive not recognizing multiple partitions or allowing them to be created so yeah, fscking Windows.


----------



## Deleted member 30996 (Feb 6, 2018)

I don't use Windows but this is how I format my unmounted Flash Drives up to and including 128GB to store data:


```
# dd if=/dev/zero of=/dev/da0 bs=2m count=1
# fdisk -BI /dev/da0
# newfs_msdos /dev/da0s1
```
I've had larger USB HDD I needed to use the FAT32 format with but this works as stated.

And I always use it on new drive.


----------



## Maelstorm (Feb 6, 2018)

tobik@ said:


> Rastko has resurrected an 8 years old thread for no well-explained reason. I doubt any of the original posters care anymore.



Oh great.  I responded to a zombie thread.  I didn't even catch that.

Damnit.


----------



## Rastko (Feb 7, 2018)

tobik@ said:


> Rastko has resurrected an 8 years old thread for no well-explained reason. I doubt any of the original posters care anymore.



Without trying to sound apologetic, I understand where you come from. But consider that newbies dig through old threads. Off-topic, though, I fully admit.


----------



## Rastko (Feb 7, 2018)

CraigHB said:


> It's easy to overlook the dates on these threads, it's in tiny print at the bottom of the post.  IMO it should be in bold with normal size font at the top of the post.
> 
> Anyway, since this thread was originally created things are more standardized with flash sticks.  Still Windows does not treat them in the manner they should be.  I've not used Win10, but Win7 looks at the stick like a big floppy drive not recognizing multiple partitions or allowing them to be created so yeah, fscking Windows.



It would be cool if older threads emphasized a year, or age. Or I've missed it? Or at least, not bump it up if it's too old.


----------

