Saturday 26 February 2011

Formatting a USB pen drive with the Command Line

The vast majority of users today are probably wandering why I would even consider writing a 'how to' for formatting anything from the command line. The vast majority of distros come with gparted installed and that is an easier option to format any drive with the added convenience of a nice graphical front end.

However for those users who like to test out new distros on a regular basis, a USB pen drive is now the preferred option to boot into a live environment. Why? Well for starters programs like Unetbootin make it very easy to put a live distro onto a pen drive. This can be run, booted straight from the stick, without ever having the need to burn a CD. After testing and/or installing the distro the drive can be reused, unlike the CD which may be used as a coaster before ending up in the bin.

Some programs, when they put the distro onto the pen drive, trick the computer into thinking that the pen drive is a CD. It works fine for testing the distro, but when it comes to wiping it you are unable to do it from the file manager (CDs are read only) and gparted will not format it (it does drives not CDs). So your left with a pen drive that behaves like it can't be altered, but this is where the command line is a useful tool.

This will wipe all the data off the pen stick, for safety reasons I would strongly advise disconnecting any other external USB hard drives or pen sticks at this point.

First of all you need to find out the stick is listed as
1. open up the terminal

2. type: fdisk -l

This will tell you the location of your USB drive, in the case below it is located at /dev/sdd so I'll use that for the rest of the tutorial. Please remember to substitute in the actual location of the drive when you are doing this.
kevie@kev-pc:~$ fdisk -l

Disk /dev/sdd: 4009 MB, 4009754624 bytes
124 heads, 62 sectors/track, 1018 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
3. unmount the drive with the command: umount /dev/sdd

4. I'm going to assume that your wanting the pen drive formatted to FAT32 to allow you to use it on any system. Type: mkdosfs -F 32 -I /dev/sdd

That's it, your done.

14 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Very Nice and Informative Post. Thank admin for sharing such an amazing post.

      --->>Unable to Format Pen Drive? (Format Guaranteed)

      Delete
  2. I ended up stuck with a useless 8GB USB drive.

    NOW EVERYTHING WORKS AGAIN !!!

    Where can I start thanking you ???

    ReplyDelete
  3. help...

    i'm running lubuntu 13.04 from a live usb (hard drive is messed up)

    and fdisk -l does nothing ????

    ReplyDelete
  4. update:
    -----------------------------------------

    its fine i just had to type: sudo
    before the command it must be because im on a live cd or because its
    a newer realese

    ReplyDelete
  5. live@live:~$ mkdosfs -F 32 -I /dev/sdb
    mkdosfs 3.0.14 (23 Jan 2023)
    /dev/sdb: Permission denied
    live@live:~$

    ReplyDelete
  6. Now this same flash drive is showing blank for file system.
    Bulk flash drives

    ReplyDelete
  7. Pen drives are becoming increasingly popular as more people are beginning to recognize their functions. They are sold everywhere that electronic computer devices are found and so people are seeing them and watching them get advertised. For someone who is moving from the old floppy disk to the pen drive, they might want to know which one to get.
    pendrive online purchase

    ReplyDelete
  8. am running ubuntu 14.0.4 lts but it has not worked for me

    ReplyDelete