≡ Menu

Ubuntu Linux format USB pen drive

Q. How do I format a USB pen drive under Ubuntu Linux for ext3 file system?
A. You can format USB pen drive with the help of following commands:

[a] fdisk : Partition table manipulator for Linux

[b] mkfs.ext3 : Create an ext2/ext3 filesystem by formatting given partition name (/dev/partition)

[c] e2label : Change the label on an ext2/ext3 filesystem

First make sure USB pen is not mounted. Click on Places > Computer > Select USB pen > Right click > Select Unmount Volume.

Let us assume that /dev/sda1 is your partition name for USB pen. To format type the following command (Open X terminal and type the command)
$ sudo mkfs.ext3 /dev/sda1
Caution: Careful while entering device/partition name; wrong name can wipe out entire hard disk!!!
Now use e2label command to change the filesystem label on the ext3 filesystem located on device /dev/sda1:
$ sudo e2label /dev/sda1 usb-pen
You can also create an MS-DOS/Windows XP file system under Linux, enter:
$ sudo mkfs.vfat /dev/sda1

Now you are ready to use USB pen.

{ 57 comments… add one }

  • Surja Gain December 12, 2007, 2:00 am

    This guide was simple and effective. I have a Kingston 2 Gb pen drive. When I transferred some files into it from Ubuntu, the pen drive stopped working normally in Windows. When I right clicked it’s icon in windows, instead of ‘Open’ in the context menu, it showed some garbled characters. I could not format it in windows. Following the instructions given above I was able to format it to FAT32 and use it again normally.

  • Axl December 21, 2007, 5:01 am

    Dear Mr. Gain,

    With regard to your posting, I wish to bring to you notice that nobody the phaque cares what you do with your pen drive. The problems you have stated are bound to happen since the hardware/software that you are using are totally jali as you yourself. If in future, if such a problem arises, I would give you a plain and simple solution and that is, you can take your pen drive and shove it up…you know know where…sideways.

    With regards,

  • Ed December 24, 2007, 10:19 pm

    The problem you demonstrate is called narcissism. I have known at least two persons with your symptoms. Unfortunately, psychiatric help for this condition is very rare.



  • Terrell Prude' Jr. January 2, 2008, 9:12 pm

    Hey, come on, be nice folks. Mr. Gain brought up a valid point. I do use VFAT on USB sticks for the exact purpose of going back and forth between my GNU/Linux box and MS Windows. What Mr. Gain shared above is actually yet more evidence that our favorite platform (GNU/Linux) is superior to the offerings from Microsoft. GNU/Linux made that USB stick of his *truly* interoperable, not the farce that Microsoft pretends to promise.


  • JD June 20, 2008, 9:14 pm


    Thanks for the great Q&A. It helped me to format my USB drive to ext3 quickly and without problems.


  • buckaroo August 3, 2008, 9:55 pm

    I have a solution more easy:
    Just install gparted from synaptic.

    Is easy, simple and you can format and partition in all formats.
    You can format pendrive, zip, diskette, disk, etc.

    Buckaroo from Argentina.

    Viva Ubuntu!!

  • Jiks October 27, 2008, 12:43 am


    I loved the article, excellent read. But I have a question. Not sure if this can be asked here: Can we have something done so that in the right click contextual menu of the USB pen drive another option appears, so that clicking on it can format the drive .. to the selected file system? :) ..

    Sorry i am new to Linux and I find it hard to do the command line stuff.

    I am not exactly sure even what to search for?

    Newbie to Linux :(

  • Going quickly for Vista... December 20, 2008, 11:59 am

    Question 1:
    how do i find this device name /dev/sda1.
    the only thing i found is something like /media/KINGSTON that doesn’t work.

    Question 2:
    i have spent already 20 minutes trying to do something that takes around 3 seconds to do in win XP (right click, format)…

    • Erick April 22, 2011, 6:39 pm

      And with a virus gift attached to it. I once formatted in that simple way you describe only to realize that some executables “passengers files” stay on it, I formatted the memory in linux and problem solved.

    • john August 10, 2011, 8:32 am

      To find device name
      dmesg |tail

  • Mephisto December 20, 2008, 7:37 pm

    Dear Going quickly for Vista…
    To see the right path just type in terminal “mount” with the pen drive mounted and you will see the path to format it. Then unmount it, and format it.

    Hope this work to you like it work to me.
    Happy Holidays to everyone!!!!

  • Going less quickly for Vista... December 20, 2008, 11:37 pm

    Before your reply I went to menu: system monitor-file systems and saw the name of the drive.

    Thanks anyway,

    Merry Christmas and a happy new year!

  • Diabolic Preacher December 22, 2008, 2:35 pm

    hi vivek,
    how do you specifically format a usb drive to fat 32 or to fat16. my observations.
    1. fat16 wastes a lot of space but upto 2gb pen drives that’s been the standard, i’m assuming.

    2. i formatted my usb drive as fat32 for the time being from a windows XP machine. since I’d had this pen drive since long and just wondered why i hadn’t got it to fat32 earlier. On linux, as you wrote in your post, there is vfat but how do we know whether it will select fat16 or fat32?

    3. the reason i feel that vfat might format with fat16 is since that is something i saw from a latest DamnSmallLinux distro, which on going thru the steps to create a bootable DSL usb, formatted the data partition as FAT16. I thought it would atleast support FAT32 in a time where other distros are supporting NTFS read/write.

    Thanks for the article.

  • nixCraft December 22, 2008, 3:46 pm

    @Diabolic Preacher,

    Use the -F FAT-size option

    Specifies the type of file allocation tables used (12, 16 or 32 bit). If nothing is specified, mkdosfs will automatically select between 12, 16 and 32 bit, whatever fits better for the file system size. In short for fat32 do:

    mkfs.vfat -F 32 /dev/sda1

  • Diabolic Preacher December 22, 2008, 4:13 pm

    Hey Vivek,
    I just went thru http://linux.die.net/man/8/mkfs.vfat and figured out the answer and came here to add a comment with the answer to help others know…and thankfully you’d already explained with code example.

    N.B fat32 needs atleast 2 reserved sectors. any details on what this is?

  • Diabolic Preacher December 22, 2008, 6:09 pm

    One thing I read in the man page is that 32 bit is never automatically selected. Its the only option that you have to explicitly specify. do you think this must be an old version of the man page?

    mkdosfs will automatically select between 12 and 16 bit, whatever fits better for the filesystem size. 32 bit FAT (FAT32 format) must (still) be selected explicitly if you want it. from the mkdosfs/mkfs.vfat man page.

  • nixCraft December 24, 2008, 7:55 am

    No I’ve same man page. Use -F 32 option as described above. Following may provide more info about FAT32

  • aj March 7, 2009, 11:55 am

    The above mentioned steps worked with me.

  • Sureshkumar March 18, 2009, 8:06 am

    HI Vivek Gite ,

    Superba ……….. it’s working nice

  • Howard March 28, 2009, 5:55 pm

    Your information about usb formating is great. I have to say that it gets my goat when people post terrible comments about beginners asking questions that others take for granted. I began computing in 1987. I learned everything on my own and have chased Windows through each distribution. I work in simulation and our device has over 250 computers with almost all running Linux. It was time for me to change. I prefer to use command line when possible but that is not the norm. The average person wants a GUI and simplicity. Linux is almost there and gets better each day. For all you gurus out there, remember, there was a time when you needed help also. There will always be new users needing help and finding simple answers is not always easy. Offer them help or point them in the right direction, if not, don’t post.

  • Yet another lab admin April 11, 2009, 2:14 pm

    Hi Vivek Gite,

    I am an admin of a Lab with Ubuntu on all comps and would like to provide the users a means to format their pen drives. As the aforementioned method uses sudo, i cant use it in the lab. Any suggestions?

  • Yet another lab admin April 11, 2009, 3:15 pm

    Well, the users dont have root access. So they wont be able to use sudo mkfs.vfat…

  • vandit April 13, 2009, 7:06 pm

    thats what I dont get… why the need kept to sudo everytime we want to tinker with some filesystem. I mean why to build it that way when you can have normal users needing to do something like formatting or even mounting their devices.
    OR am I mistaken somewhere ??
    can we specify such permissions for explicitly for users (like modifying certain folders , device contents etc.)

  • steve April 19, 2009, 7:32 am

    Thanks for useful help. Now use Jaunty and this latest version is a real improvement. Gparted is a superb program and easy to use. Thanks for help.

  • Karri April 30, 2009, 8:26 am

    To find what device you should format you can enter the command “mount”. It should show somethiong like


    /dev/sdf1 on /media/KINGSTON type vfat

    To format the USB pen with the right name you can use

    mkfs.vfat /dev/sdf1 -n KINGSTON

  • claudio May 5, 2009, 2:00 pm

    Tks ! This tuto hepl me.

  • Darshana June 10, 2009, 6:38 am

    Hey guys im in a big prblem! I got a verbatim pendrive. It had a pre installed Software on it which allowed me to split my pen into different partitions and make it password protected. Well i did that and then I got 3 MB as notpassword protected space. My pendrive is no longer functioning properly, and now when i try the properties, I get only 3 MB displayed.. How do i go from here?

  • ashish July 17, 2009, 5:13 pm

    when i try to format the usb drive in windows it shows the error
    “windows unable to format the usb ”
    than any solution for this problem……in windows?
    otherwise its necessary to format the USB in Linux..

    thanking you……..

  • Two_Dishes July 19, 2009, 7:30 pm

    I was driven to drink this afternoon, wasting an hour and a half with hidden files that would not delete for anything.
    Your tip, the first one mkfs.ext3
    was one I had not seen anywhere…
    It worked, you totally saved my day.
    But now I am a little drunk from the beer…

  • Fernando August 3, 2009, 5:35 pm

    Ok, i formated, but i can’t rename my 2gb pen drive ;’-(

  • david August 5, 2009, 8:48 pm

    all these methods are not user friendly, you would think by now 2009 Ubuntu would have implemented a simple right-click format as (filesystem) option.

    come on programmer community use your creative minds.

  • Tony August 13, 2009, 10:08 am

    after creating ext3 filesystem on my USB pen ‘no permission to open lost&found file ??

  • Orca August 20, 2009, 9:44 am

    Awesome, quick and easy command.
    (I tried Gparted, but the best bit about that program was the error message if you don’t sudo launch it)
    By coincidence, dev/sda1 is my root HDD, so I was careful to choose which drive with system monitor.
    The actually format was basically instant.
    Yeah though, an easier interface would be nice, but on the other hand, Terminal is a good system, I can see why linux people want to make windows people use it.
    It promotes learning :D

  • avinash August 23, 2009, 7:50 am

    I like to format my pendrive in ntfs file system through shell prompt.any one help me out.

  • Arun C N October 3, 2009, 8:31 pm

    Hi friends… You have a sequence of steps….
    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

    arun@cn:~$ 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
    arun@cn:~$ mkfs.vfat -n ’sandhya’ -I /dev/sda
    mkfs.vfat 2.11 (12 Mar 2005)

    Remove and insert the pen drive to have mounted again!

    Thats it…………..!

  • Arun C N October 3, 2009, 8:36 pm

    Below is the link for manual reference…


  • Rohit Jadhav October 9, 2009, 12:40 pm

    I am in deep trouble my pen-drive has become a read only pen drive. Tried out the tutorial above to format my pen-drive but it did not work.Also tried out every possible way to format my pen-drive but could not format my drive.Also not allowed to change permission for the drive even as root user…please HELP.

  • shameer November 1, 2009, 1:22 am

    simple but great help…thankz

  • linuxer November 5, 2009, 11:18 pm

    This how-to doc was soooo helpful. Thanks a lot!

  • ams amosog November 24, 2009, 9:42 am

    when I try to open my pen drive after inserting it into my PC, it tells me to insert a disk into Drive E.
    why?, and how can solve this problem?.

  • ben white November 25, 2009, 3:04 am

    Do NOT do this.
    on some machines /dev/sda is the hardrive.
    you will lose all your data.

  • hsartoris January 15, 2010, 9:11 pm

    @ben white:
    clearly, you are not supposed to enter dev/sda1 when you are actually formatting. That was an example, and you need to replace it with the drive address of your unmounted pen drive.

  • Pablo January 16, 2010, 11:21 pm

    Hey! sda usually is the hard disk!! pen drive usually is sdb, so you will try to format /dev/sdb1 !!
    Using GParted is much more user-friendly and secure:
    sudo apt-get install gparted
    sudo gparted

  • Ashok.Konapakula. February 9, 2010, 3:44 am

    can any body give me instructions or commands to format the memory card in the terminal of ubuntu…

  • PAco March 25, 2010, 11:42 am


    My HP 8GB pendrive turns “read only” after a few use. I tried to format it without success nor in windws nor in linux.

    The error is always de same: “read only filesystem” or similar.

    Can anybody help me please?



  • marcinb April 5, 2010, 6:38 pm

    ive got the same as you. my pendrive turns “read only”. formating helps, but problem every time comes back. anyone knows why?

    • Tom August 18, 2010, 4:03 pm

      Sometimes a system is configured in such a way that when errors are on the device the device is remounted read-only.

  • vinny August 24, 2010, 4:59 pm

    Yet Another Lab Admin and vandit:

    All you have to do is run visudo and edit the /etc/sudoers file.
    You can give specific users access to run specific programs as su.

    Though I don’t think giving lab users the rights to run fdisk or mkfs is a good idea at all.

  • Vicky January 23, 2011, 8:59 am

    What are the commands for unmounting the drives in ubuntu………..

    • Vicky February 4, 2011, 6:59 pm

      please help me in this…

      • Mike the BookRaider April 8, 2011, 7:02 am

        Vicky: I’ll bet you’ve already found your answer elsewhere; thanks a lot for not posting back.

        Anyway, the answer to this question, for all newbies, is umount /dev/*da* , where *da* is replaced either by hda[number] (for EIDE drives) or sda[number] (for serial/USB drives).

  • ramesh February 4, 2011, 7:25 am

    i have formated my 2 GB, HP pen drive and i copied data into that and after removed insert pen drive is not even show desktop icon also please help me….

  • santosh August 17, 2011, 4:39 am

    Thanks a lot for this tip,it works super ;)

  • pandi October 24, 2011, 2:07 am

    see my memory card is corrupted (ie) its actual memory 1GB but now its showing only 24KB.. while formating it show 1ly “FAT” not other… i tried in command mode, no use..

    “””””” format j: /fs:fat32″”””””””””””
    after enter-
    “”‘”””the volume too small for FAT”””””
    wat to do… give some idea

  • Roshan May 20, 2013, 5:30 am

    Hello, i followed this guide. Worked fine, but i did a big mistake.
    actually, i was to format my usb pen drive, which was /dev/sdb. But, by mistake, i choose fdisk /dev/sda, when asked to choose an option, i gave ‘o’. And then rebooted, now i cannot start my laptop. Will all my data be lost? Is there a way to recover it?

  • Tajka June 17, 2013, 3:51 am

    Thanx a lot….really helpful and easy :3

Leave a Comment

   Tagged with: , , , , , , , , , , , , ,