1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Formatting a USB stick

Discussion in 'Peripheral Hardware' started by michaelrmgreen, Feb 5, 2010.

  1. michaelrmgreen

    michaelrmgreen Member

    Messages:
    210
    Likes Received:
    0
    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:
    Code:
    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:

    Code:
    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?
     
  2. michaelrmgreen

    michaelrmgreen Member

    Messages:
    210
    Likes Received:
    0
    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.
     
  3. J65nko

    J65nko New Member

    Messages:
    422
    Likes Received:
    0
    I just wonder why did not check the USB disk with fdisk ;)
     
  4. Ruler2112

    Ruler2112 New Member

    Messages:
    421
    Likes Received:
    0
    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 fdisk /dev/sdx - 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 dd if=/dev/zero of=/dev/sdx bs=1M 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 mkfs -t vfat /dev/sdx1 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! fdisk -l 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!!!
     
  5. barberry

    barberry New Member

    Messages:
    2
    Likes Received:
    0
    I've used the FreeBSD install cd to format a thumb drive with
    FAT.
     
  6. michaelrmgreen

    michaelrmgreen Member

    Messages:
    210
    Likes Received:
    0
    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
     
  7. fronclynne

    fronclynne New Member

    Messages:
    1,297
    Likes Received:
    0
    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!
     
  8. michaelrmgreen

    michaelrmgreen Member

    Messages:
    210
    Likes Received:
    0
    Alright fronclynne, your advice was bang on. I've taken the liberty of making them into a How-To.
     
  9. Ruler2112

    Ruler2112 New Member

    Messages:
    421
    Likes Received:
    0
    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.