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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 57 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
57 comments… add one
  • Surja Gain Dec 12, 2007 @ 2:00

    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 Dec 21, 2007 @ 5:01

    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 Dec 24, 2007 @ 22:19

    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. Jan 2, 2008 @ 21:12

    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 Jun 20, 2008 @ 21:14


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


  • buckaroo Aug 3, 2008 @ 21:55

    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 Oct 27, 2008 @ 0:43


    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... Dec 20, 2008 @ 11:59

    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 Apr 22, 2011 @ 18:39

      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 Aug 10, 2011 @ 8:32

      To find device name
      dmesg |tail

  • Mephisto Dec 20, 2008 @ 19:37

    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... Dec 20, 2008 @ 23:37

    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 Dec 22, 2008 @ 14:35

    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 Dec 22, 2008 @ 15:46

    @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 Dec 22, 2008 @ 16:13

    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 Dec 22, 2008 @ 18:09

    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 Dec 24, 2008 @ 7:55

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

  • aj Mar 7, 2009 @ 11:55

    The above mentioned steps worked with me.

  • Sureshkumar Mar 18, 2009 @ 8:06

    HI Vivek Gite ,

    Superba ……….. it’s working nice

  • Howard Mar 28, 2009 @ 17:55

    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 Apr 11, 2009 @ 14:14

    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 Apr 11, 2009 @ 15:15

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

  • vandit Apr 13, 2009 @ 19:06

    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 Apr 19, 2009 @ 7:32

    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 Apr 30, 2009 @ 8:26

    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 @ 14:00

    Tks ! This tuto hepl me.

  • Darshana Jun 10, 2009 @ 6:38

    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 Jul 17, 2009 @ 17:13

    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 Jul 19, 2009 @ 19:30

    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 Aug 3, 2009 @ 17:35

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

  • david Aug 5, 2009 @ 20:48

    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 Aug 13, 2009 @ 10:08

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

  • Orca Aug 20, 2009 @ 9:44

    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 Aug 23, 2009 @ 7:50

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

  • Arun C N Oct 3, 2009 @ 20:31

    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 Oct 3, 2009 @ 20:36

    Below is the link for manual reference…


  • Rohit Jadhav Oct 9, 2009 @ 12:40

    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 Nov 1, 2009 @ 1:22

    simple but great help…thankz

  • linuxer Nov 5, 2009 @ 23:18

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

  • ams amosog Nov 24, 2009 @ 9:42

    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 Nov 25, 2009 @ 3:04

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

  • hsartoris Jan 15, 2010 @ 21:11

    @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 Jan 16, 2010 @ 23:21

    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. Feb 9, 2010 @ 3:44

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

  • PAco Mar 25, 2010 @ 11:42


    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 Apr 5, 2010 @ 18:38

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

    • Tom Aug 18, 2010 @ 16:03

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

  • vinny Aug 24, 2010 @ 16:59

    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 Jan 23, 2011 @ 8:59

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

    • Vicky Feb 4, 2011 @ 18:59

      please help me in this…

      • Mike the BookRaider Apr 8, 2011 @ 7:02

        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 Feb 4, 2011 @ 7:25

    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 Aug 17, 2011 @ 4:39

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

  • pandi Oct 24, 2011 @ 2:07

    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

    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 Jun 17, 2013 @ 3:51

    Thanx a lot….really helpful and easy :3

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum