Ubuntu Linux format USB pen drive

by on May 2, 2007 · 57 comments· LAST UPDATED June 20, 2008

in , ,

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.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 57 comments… read them below or add one }

1 Surja Gain December 12, 2007 at 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.

Reply

2 Axl December 21, 2007 at 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,
Axl

Reply

3 Ed December 24, 2007 at 10:19 pm

Axl:
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.

Sorry,

Ed

Reply

4 Terrell Prude' Jr. January 2, 2008 at 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.

–TP

Reply

5 JD June 20, 2008 at 9:14 pm

Vivek,

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

-JD

Reply

6 buckaroo August 3, 2008 at 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!!

Reply

7 Jiks October 27, 2008 at 12:43 am

Hi,

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?

Regards,
Newbie to Linux :(
Jiks

Reply

8 Going quickly for Vista... December 20, 2008 at 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)…

Reply

9 Erick April 22, 2011 at 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.

Reply

10 john August 10, 2011 at 8:32 am

To find device name
dmesg |tail

Reply

11 Mephisto December 20, 2008 at 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!!!!

Reply

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

Mephisto,
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!

Reply

13 Diabolic Preacher December 22, 2008 at 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.

Reply

14 nixCraft December 22, 2008 at 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

Reply

15 Diabolic Preacher December 22, 2008 at 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?

Reply

16 Diabolic Preacher December 22, 2008 at 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.

Reply

17 nixCraft December 24, 2008 at 7:55 am

No I’ve same man page. Use -F 32 option as described above. Following may provide more info about FAT32
http://en.wikipedia.org/wiki/File_Allocation_Table#FAT32

Reply

18 aj March 7, 2009 at 11:55 am

The above mentioned steps worked with me.
Thnks.

Reply

19 Sureshkumar March 18, 2009 at 8:06 am

HI Vivek Gite ,

Superba ……….. it’s working nice

Reply

20 Howard March 28, 2009 at 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.

Reply

21 Yet another lab admin April 11, 2009 at 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?

Reply

22 nixCraft April 11, 2009 at 3:13 pm

Why not?

Reply

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

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

Reply

24 vandit April 13, 2009 at 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.)

Reply

25 steve April 19, 2009 at 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.

Reply

26 Karri April 30, 2009 at 8:26 am

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

mount

/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

Reply

27 claudio May 5, 2009 at 2:00 pm

Tks ! This tuto hepl me.

Reply

28 Darshana June 10, 2009 at 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?

Reply

29 ashish July 17, 2009 at 5:13 pm

hey…
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……..

Reply

30 Two_Dishes July 19, 2009 at 7:30 pm

wooooowwwwwwww…..
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…

Reply

31 Fernando August 3, 2009 at 5:35 pm

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

Reply

32 david August 5, 2009 at 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.

Reply

33 Tony August 13, 2009 at 10:08 am

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

Reply

34 Orca August 20, 2009 at 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

Reply

35 avinash August 23, 2009 at 7:50 am

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

Reply

36 Arun C N October 3, 2009 at 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)
arun@cn:~$

Remove and insert the pen drive to have mounted again!

Thats it…………..!

Reply

37 Arun C N October 3, 2009 at 8:36 pm

Below is the link for manual reference…

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

Reply

38 Rohit Jadhav October 9, 2009 at 12:40 pm

hi,
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.

Reply

39 shameer November 1, 2009 at 1:22 am

simple but great help…thankz

Reply

40 linuxer November 5, 2009 at 11:18 pm

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

Reply

41 ams amosog November 24, 2009 at 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?.

Reply

42 ben white November 25, 2009 at 3:04 am

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

Reply

43 hsartoris January 15, 2010 at 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.

Reply

44 Pablo January 16, 2010 at 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

Reply

45 Ashok.Konapakula. February 9, 2010 at 3:44 am

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

Reply

46 PAco March 25, 2010 at 11:42 am

Hi,

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?

REgards,

Paco

Reply

47 marcinb April 5, 2010 at 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?

Reply

48 Tom August 18, 2010 at 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.

Reply

49 vinny August 24, 2010 at 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.

Reply

50 Vicky January 23, 2011 at 8:59 am

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

Reply

51 Vicky February 4, 2011 at 6:59 pm

please help me in this…

Reply

52 Mike the BookRaider April 8, 2011 at 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).

Reply

53 ramesh February 4, 2011 at 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….

Reply

54 santosh August 17, 2011 at 4:39 am

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

Reply

55 pandi October 24, 2011 at 2:07 am

hai..
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

Reply

56 Roshan May 20, 2013 at 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?

Reply

57 Tajka June 17, 2013 at 3:51 am

Thanx a lot….really helpful and easy :3

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous Faq:

Next Faq: