Formatting USB pen drive in Linux using Terminal

Sathya | June 13th, 2007 - 9:56 pm


Insert your USB pen drive. Let it get detected and mounted. Open Terminal. Type The Following commands
1. dmesg |tail –> here the ‘|’ key is the pipe, ie, the key before the backspace key(the upper one, so press shift)
You’ll get something like

sathya@shaman:~$ dmesg |tail
[ 9921.681164] sda: Write Protect is off
[ 9921.681174] sda: Mode Sense: 23 00 00 00
[ 9921.681178] sda: assuming drive cache: write through
[ 9921.709138] SCSI device sda: 4030464 512-byte hdwr sectors (2064 MB)
[ 9921.720951] sda: Write Protect is off
[ 9921.720963] sda: Mode Sense: 23 00 00 00
[ 9921.720967] sda: assuming drive cache: write through
[ 9921.721225] sda:
[ 9921.727896] sd 0:0:0:0: Attached scsi removable disk sda
[ 9921.744187] sd 0:0:0:0: Attached scsi generic sg0 type 0
Note the terms in bold. In your system it will be different, maybe sdb or something. Whatever it may be, make sure to substitute it in the commands below, else your hard disk may get formatted.

2. Unmount your pen drive by using
sudo umount /dev/sda (In your case, please substitute sda with the appropriate device, listed above.

3. use the mkfs.vfat command to format to FAT32 filesystem, or mkfs.ext3 to format to ext3 filesystem
sudo mkfs.vfat -n ‘Label’ -I /dev/sda Replace Label with the name you want the pen drive to have.

4. That’s it! When done formatting, you’ll be returned to the prompt
sathya@shaman:~$ mkfs.vfat -n ‘sathya’ -I /dev/sda
mkfs.vfat 2.11 (12 Mar 2005)
sathya@shaman:~$

Remove and insert the pen drive to have mounted again!

If you enjoyed this post, make sure you subscribe to my RSS feed!

37 Responses to “Formatting USB pen drive in Linux using Terminal”

  1. says:

    Hmm, Interesting, Never quite tried to do that in linux, I always used to do that in Windoze.

  2. says:

    Please how do i solve the problem below?
    how do i insert sbaah in sudoers file and where can i find the file
    iam a linux newbie

    [sbaah@Maint-Engineers ~]$ sudo umount /dev/sdb
    Password:
    Sorry, try again.
    Password:
    Sorry, try again.
    Password:
    sbaah is not in the sudoers file. This incident will be reported.
    [sbaah@Maint-Engineers ~]$ sudo umount /dev/sdb1
    sbaah is not in the sudoers file. This incident will be reported.

  3. says:

    Please umount the /dev/sda using root account.
    # sudo umount /dev/sda

  4. says:

    Pretty interesting.

  5. [...] Posted in formatting, operating systems, linux, commands at 9:56 pm by ~sathya~ This article has been shifted to my new site [...]

  6. Matsiah says:

    This was very helpful. I have a few difficulties — I interpreted the -I option as -l — but I found my errors and make it happen. Thanks.

  7. Shashwat says:

    Thanks a lot ;) gr8 blog post ;)

  8. Linuz says:

    Hey..can u explain in detail what the process behind this “mkfs.vfat” or “mkdosfs” is.what does it exactly do?i don quite get how the formatting is happening :)

  9. Sathya says:

    @Above, Explaining how they work is pretty technical stuff, I dont know how it works.

    You can have a look at the man pages:

    http://linux.die.net/man/8/mkfs.vfat

  10. Amit says:

    mkfs.ext3: invalid inode size – /dev/sdc1
    what has happened here??/

  11. herbert says:

    Thanks. It works. I was even able to get a 2 year old non-working USB (or so I thought) after following your steps.

  12. Thirupathi says:

    really its nice and worked well.thanks lot boss.

  13. saurabh says:

    Nice piece of article. I got some errors. May be I should solve it and put on my blog. Thanks

  14. [...] Linux ?? pen drive ???? ?????? ????? (Formatting USB pen drive in Linux) [...]

  15. saurabh says:

    I got these errors at terminal-

    mkfs.vfat 3.0.1 (23 Nov 2008)
    mkfs.vfat: Device partition expected, not making filesystem on entire device ‘/dev/sdb’ (use -I to override)

    Now command is working with ‘I’ instead of ‘L’. It is ninth alphabet rather then 12th. I think theme font of blog is somewhat confusing between ‘l’ and ‘I’. I have read manual documentation of this command and experimented for different different formats on it . Thanks and God bless

  16. David Temple says:

    after the dmesg |tail command I get the following:

    FAT: Filesystem panic (dev sdb)
    fat_get_cluster: invalid cluster chain (i_pos 0)
    FAT: Filesystem panic (dev sdb)
    fat_get_cluster: invalid cluster chain (i_pos 0)
    FAT: Filesystem panic (dev sdb)
    fat_get_cluster: invalid cluster chain (i_pos 0)
    FAT: Filesystem panic (dev sdb)
    fat_get_cluster: invalid cluster chain (i_pos 0)
    FAT: Filesystem panic (dev sdb)
    fat_get_cluster: invalid cluster chain (i_pos 0)

    Can anyone help.

    It is a 16GB Kingston USB drive

  17. LOl! In morning I forwarded two of my friends to @sathyabhat's following article: http://bit.ly/5oC0Fb without realizing that it's his blog.

  18. srinu says:

    plz tell any one how to format pen drive in linux

  19. Shayon says:

    Dude, did you really think that the pipe key was placed at the same position, in every single keyboard? :-o

  20. [...] derecho a su USB y pucharle en “formatear”. Si están en Linux entonces pueden hacerlo vía terminal o si estan en Ubuntu y son huevones como yo pueden usar el USB Startup Disk Creator, este lo [...]

  21. letian says:

    omg, i formatted my windows partition C instead of usb!!!! “thanks” for help, could u please be MORE specific about sda and sbd, which do I choose, so next time I wont f..k my system

  22. [...] a virus-infected USB drive, but I cannot get it to work using my Xandros on my EEEPC (instructions here). What would take hours of trying to figure out how to do it, was done in a matter of seconds in [...]

  23. tower says:

    thanks

  24. ravi says:

    root@ravi:/home/ravi# dmesg |tail
    [ 5639.791402] sd 4:0:0:0: [sdb] 65617920 512-byte hardware sectors: (33.5 GB/31.2 GiB)
    [ 5639.794872] sd 4:0:0:0: [sdb] Write Protect is on
    [ 5639.794879] sd 4:0:0:0: [sdb] Mode Sense: 03 00 80 00
    [ 5639.794887] sd 4:0:0:0: [sdb] Assuming drive cache: write through
    [ 5639.794898] sdb:
    [ 6589.481197] sd 4:0:0:0: [sdb] 65617920 512-byte hardware sectors: (33.5 GB/31.2 GiB)
    [ 6589.485998] sd 4:0:0:0: [sdb] Write Protect is on
    [ 6589.486005] sd 4:0:0:0: [sdb] Mode Sense: 03 00 80 00
    [ 6589.486016] sd 4:0:0:0: [sdb] Assuming drive cache: write through
    [ 6589.486033] sdb:
    root@ravi:/home/ravi# sudo umount /dev/sdb
    umount: /dev/sdb: not mounted
    root@ravi:/home/ravi# mkfs.vfat -n ‘ravi’ -I /dev/sdb
    mkfs.vfat 3.0.1 (23 Nov 2008)
    mkfs.vfat: unable to open /dev/sdb

    this is what happening…..
    could u help me out…..
    I was not able to open my pendrive

  25. ravi says:

    Yes u are exactly right, it is Kingston 32 GB flash drive…

    Is there any option to make it work?

    Regards

    Ravi

You can leave a response, or trackback from your own site.

Leave a Reply