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:
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 so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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.
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
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
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
Vivek,
Thanks for the great Q&A. It helped me to format my USB drive to ext3 quickly and without problems.
-JD
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!!
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
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)…
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.
To find device name
dmesg |tail
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!!!!
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!
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.
@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
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?
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.
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
The above mentioned steps worked with me.
Thnks.
HI Vivek Gite ,
Superba ……….. it’s working nice
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.
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?
Why not?
Well, the users dont have root access. So they wont be able to use sudo mkfs.vfat…
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.)
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.
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
Tks ! This tuto hepl me.
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?
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……..
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…
Ok, i formated, but i can’t rename my 2gb pen drive ;’-(
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.
after creating ext3 filesystem on my USB pen ‘no permission to open lost&found file ??
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
I like to format my pendrive in ntfs file system through shell prompt.any one help me out.
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…………..!
Below is the link for manual reference…
http://linux.die.net/man/8/mkfs.vfat
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.
simple but great help…thankz
This how-to doc was soooo helpful. Thanks a lot!
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?.
Do NOT do this.
on some machines /dev/sda is the hardrive.
you will lose all your data.
@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.
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
can any body give me instructions or commands to format the memory card in the terminal of ubuntu…
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
ive got the same as you. my pendrive turns “read only”. formating helps, but problem every time comes back. anyone knows why?
Sometimes a system is configured in such a way that when errors are on the device the device is remounted read-only.
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.
What are the commands for unmounting the drives in ubuntu………..
please help me in this…
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).
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….
Thanks a lot for this tip,it works super ;)
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
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?
Thanx a lot….really helpful and easy :3