Formatting USB pen drive in Linux using Terminal 68

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!

68 thoughts on “Formatting USB pen drive in Linux using Terminal

  1. Reply Jun 30,2007 3:21 pm

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

  2. Reply Jul 24,2007 6:18 pm

    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. Reply Aug 1,2007 4:38 pm

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

  4. Reply Aug 15,2007 5:41 pm

    Pretty interesting.

  5. Pingback: Formatting USB pen drive in Linux using Terminal « Sathya Says

  6. Reply Matsiah Oct 30,2007 1:07 pm

    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. Reply Shashwat Jan 1,2008 10:19 pm

    Thanks a lot ;) gr8 blog post ;)

  8. Reply Linuz Mar 24,2008 11:32 pm

    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. Reply Sathya Mar 25,2008 12:30 pm

    @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. Reply Amit Sep 30,2008 11:55 pm

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

  11. Pingback: Formatting USB pen drive in Linux using Terminal | Herrmann

  12. Reply herbert Jul 17,2009 9:50 am

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

  13. Reply Thirupathi Sep 19,2009 9:18 pm

    really its nice and worked well.thanks lot boss.

  14. Reply saurabh Oct 23,2009 11:10 pm

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

  15. Pingback: Tech??? Live: 39 ?? ????? ??????? ?? ???-??????? - Tech???

  16. Reply saurabh Nov 4,2009 12:09 am

    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

  17. Reply David Temple Nov 20,2009 1:28 am

    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

  18. Pingback: Ashwin Saxena

  19. Pingback: Sathya

  20. Reply srinu Dec 29,2009 3:48 pm

    plz tell any one how to format pen drive in linux

  21. Reply Shayon Jan 25,2010 12:52 pm

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

  22. Pingback: xinita » Blog Archive » ¿Cómo instalar Android en una Acer Aspire One? Es más fácil que burlarse de la iPad y toma menos neuronas que crearla

  23. Reply letian Jun 8,2010 7:16 pm

    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

    • Reply Natraj Dec 30,2011 12:56 pm

      you can check with

      -> parted
      -> print all
      it will show you the entire disks connecte in your sys.. pendrive will appears as special device…

      dont do more experiments with parted command…improper use of parted results in lost of data..

  24. Pingback: Nightshift blog: Call Center Agent's Blog » I Love the Mac

  25. Reply ravi Aug 29,2010 2:31 pm

    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

  26. Reply ravi Aug 31,2010 11:29 pm

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

    Is there any option to make it work?

    Regards

    Ravi

  27. Reply ravi Sep 4,2010 10:34 pm

    @Satya: Actually it was given to me by my friend. I think he purchased it for Rs. 600/- from other person, I am not sure abt it…..

    So now there is no solution to format this drive???

  28. Reply ravi Sep 6,2010 9:22 am

    Thank you 4 info Sathya…

  29. Reply Parth Nov 5,2010 10:18 am

    hey i am following the steps but its not working in my case, probably you may help..

    [root@localhost ~]# dmesg|tail
    sd 12:0:0:0: [sdb] Write Protect is on
    sd 12:0:0:0: [sdb] Mode Sense: 03 00 80 00
    sd 12:0:0:0: [sdb] Assuming drive cache: write through
    sd 12:0:0:0: [sdb] 3860630417 512-byte hardware sectors: (1.97 TB/1.79 TiB)
    sd 12:0:0:0: [sdb] Write Protect is on
    sd 12:0:0:0: [sdb] Mode Sense: 03 00 80 00
    sd 12:0:0:0: [sdb] Assuming drive cache: write through
    sdb: unknown partition table
    sd 12:0:0:0: [sdb] Attached SCSI removable disk
    sd 12:0:0:0: Attached scsi generic sg2 type 0
    [root@localhost ~]# sudo mkfs.vfat -n ‘Label’ -I /dev/sdb
    mkfs.vfat 3.0.1 (23 Nov 2008)
    mkfs.vfat: unable to open /dev/sdb

    my pendrive was working before couple of days but now its not also its 4GB drive but its showing some TBs in the system.. what should i do?

  30. Reply Fabio Varesano Nov 23,2010 5:29 pm

    @Parth the line “sdb: unknown partition table” means that you don’t have any partition table on the pen. This means that you have to remake your partition table. You can use the command cfdisk for doing that. Check google for it.

    @sathya in you article you don’t explain users to replace /dev/sda in the command “sudo mkfs.vfat -n ‘Label’ -I /dev/sda” with the device name readed from dmesg.

    If in dmesg the usb pen is called /dev/sdb they have to use /dev/sdb in the format command like “sudo mkfs.vfat -n ‘Label’ -I /dev/sdb”..

    Without saying so they could end up formatting their own hard disk!

    • Reply Pothi Dec 1,2010 11:29 am

      I just formatted my entire hard drive. ;) jk

      @Sathya: Thanks for the sharing this knowledge! I wish you changed it to sdb or sdx for safety.

  31. Reply Fabio Varesano Nov 23,2010 5:31 pm

    Ops… forget the second part of my comment above.. I overlooked that instruction.. sorry!

  32. Reply swati Feb 4,2011 12:25 pm

    when i follow u i got below output ,what i need to do please help me
    rgukt08@rgukt08-laptop:~$ dmesg |tail
    [ 21.319902] [drm] writeback test succeeded in 1 usecs
    [ 24.042181] atl1c 0000:06:00.0: irq 2300 for MSI/MSI-X
    [ 24.042598] ADDRCONF(NETDEV_UP): eth1: link is not ready
    [ 24.056992] ADDRCONF(NETDEV_UP): wlan1: link is not ready
    [ 74.182031] atl1c 0000:06:00.0: atl1c: eth1 NIC Link is Up
    [ 74.182231] ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
    [ 84.285073] eth1: no IPv6 routers present
    [ 529.126158] wlan1: Selected IBSS BSSID 82:be:8b:f7:80:bb based on configured SSID
    [ 539.921568] wlan1: no IPv6 routers present
    [ 574.261070] wlan1: disassociating by local choice (reason=3)

  33. Reply swati Feb 4,2011 2:16 pm

    hello sathya..!
    see this is the output
    after formating my pen drive i changed it name an other time it is not at all open even there is no devise icon also please help me as early as possible please

    rgukt08@rgukt08-laptop:~$ dmesg |tail
    [ 21.319902] [drm] writeback test succeeded in 1 usecs
    [ 24.042181] atl1c 0000:06:00.0: irq 2300 for MSI/MSI-X
    [ 24.042598] ADDRCONF(NETDEV_UP): eth1: link is not ready
    [ 24.056992] ADDRCONF(NETDEV_UP): wlan1: link is not ready
    [ 74.182031] atl1c 0000:06:00.0: atl1c: eth1 NIC Link is Up
    [ 74.182231] ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
    [ 84.285073] eth1: no IPv6 routers present
    [ 529.126158] wlan1: Selected IBSS BSSID 82:be:8b:f7:80:bb based on configured SSID
    [ 539.921568] wlan1: no IPv6 routers present
    [ 574.261070] wlan1: disassociating by local choice (reason=3)
    after formating pen drive i changed it name an other time it is not at all open even there is no devise icon also please help me as early as possible please

  34. Reply Digambar K Feb 4,2011 5:37 pm

    Note that /dev/sda1 is the device for a partition. /dev/sda is the device for a drive. You want to mount the filesystem contained on a partition.

    Look at “ls -l /dev/sda*”. See if there is both /dev/sda and /dev/sda1
    Also read through the manpage for mount.

    If you system uses udev, you can get more information with:
    udevinfo -q env -n /dev/sda1

    The filesystem uuid number supplied can be used in an /etc/fstab entry in leu of a device name. The next time that you plug the drive in, a different device may be used to access it, so it is better to use either the label or the uuid if the file system instead.

    In the “man mount” manual, be sure to look at the “dmask”, “fmask”, “user”, “uid”, “gid” and “noauto” mount options. The “dmask”,”fmask”, “uid” and maybe “gid” would be used for a fat16, fat32 or ntfs filesystem. The noauto option would be used for any removable device. The “user” option will allow you to mount the filesystem as a regular user.

  35. Reply Vimal Vishwakarma Feb 10,2011 3:10 pm

    dear sathya i tried the formating through linux but not succeed
    as u mentioned above all things was right
    but after giving the command
    sudo mkfs.vfat -n ‘Label’ -I /dev/sdb
    i came back to command prompt but any data was not deleted .
    hence the same problem persisting in my pendrive
    please help
    i did all the things what i can do
    i dont know much about linux
    give some suggestion

  36. Reply 123 Apr 16,2011 8:13 pm

    ditto for me, :(

  37. Reply Sachith K N Jul 28,2011 8:04 pm

    thankuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

  38. Reply Nirtogen Aug 7,2011 8:12 pm

    Thank you Sathya, your guide worked for me, I booted openSUSE from USB, so I wanted to try another LiveUSB OS, but I couldn’t clean my USB. Big thank you

  39. Reply Natraj Dec 30,2011 1:01 pm

    thank you all for sharing your experiences…

  40. Reply venkat Jan 25,2012 8:44 am

    nice instructions

  41. Pingback: Sathya

  42. Reply Niraj Oct 16,2012 10:10 pm

    Thanks for sharing

  43. Reply soni Nov 9,2012 2:28 pm


    dmesg | tail
    [14926.035488] sd 14:0:0:0: [sdb] Write Protect is off
    [14926.035498] sd 14:0:0:0: [sdb] Mode Sense: 00 00 00 00
    [14926.035986] sd 14:0:0:0: [sdb] Asking for cache data failed
    [14926.035994] sd 14:0:0:0: [sdb] Assuming drive cache: write through
    [14926.040881] sd 14:0:0:0: [sdb] Asking for cache data failed
    [14926.040894] sd 14:0:0:0: [sdb] Assuming drive cache: write through
    [14926.157156] sdb:
    [14926.160109] sd 14:0:0:0: [sdb] Asking for cache data failed
    [14926.160114] sd 14:0:0:0: [sdb] Assuming drive cache: write through
    [14926.160120] sd 14:0:0:0: [sdb] Attached SCSI removable disk

  44. Reply syam Nov 10,2012 6:25 pm

    mkfs works fine with fat and ext versions. But is there a way to change the filesystem to exFAT??

  45. Pingback: mp3 powering but ''unknown device'' - Page 2

  46. Reply xpto Mar 22,2013 7:09 am

    Please, courier [new] in command lines… I had copied the commands to gedit before to be able read them…

  47. Reply DensorJOHN Mar 7,2014 7:33 pm

    Sathya!! I can’t express my joy! After a long time of finding the solution to format my mbr write-protected USB, this was the only one that was working!! THANKS A LOT!!! *worshipping Sathya ^_^

  48. Reply chinnu May 6,2014 10:08 am

    hello Satya,
    I encountered a problem with my hard disc mounted in Ubuntu, I could not paste or cut or delete any files from my hard disc.Is there any way to use my harddisk without lossing any data in it?After running the command dmesg |tail , I got the following
    [ 4535.468562] scsi 8:0:0:0: Direct-Access StoreJet Transcend 0001 PQ: 0 ANSI: 2 CCS
    [ 4535.469560] sd 8:0:0:0: Attached scsi generic sg2 type 0
    [ 4535.473436] sd 8:0:0:0: [sdb] 976773167 512-byte logical blocks: (500 GB/465 GiB)
    [ 4535.474168] sd 8:0:0:0: [sdb] Write Protect is off
    [ 4535.474173] sd 8:0:0:0: [sdb] Mode Sense: 28 00 00 00
    [ 4535.474178] sd 8:0:0:0: [sdb] Assuming drive cache: write through
    [ 4535.476502] sd 8:0:0:0: [sdb] Assuming drive cache: write through
    [ 4535.476512] sdb: sdb1
    [ 4535.529101] sd 8:0:0:0: [sdb] Assuming drive cache: write through
    [ 4535.529109] sd 8:0:0:0: [sdb] Attached SCSI disk

    I hope that there will be a solution for this.

    Chinnu

Leave a Reply