Formatting usb pen in Linux

by on August 8, 2006 · 12 comments· LAST UPDATED August 27, 2006

in

Q. How do I format USB pen in Linux?

A. You can use standard mke2fs command to format usb pen in Linux. mke2fs is used to create an ext2/ext3 filesystem (usually in a disk partition or other USB devices). device is the special file corresponding to the device (e.g /dev/hdXX). blocks-count is the number of blocks on the device. If omitted, mke2fs automagically figures the file system size. If called as mkfs.ext3 a journal is created as if the –j option was specified.

Step # 1: Verify or find out your usb partition name

Type the following command to find out USB pen partition name:

# fdisk -l

Step # 2: Format parition

Once identified the partition name type the following command to format the usb pen in Linux (caution you must select correct usb partition name, otherwise you will loss all the data on hard disk):

# mkfs.ext3 /dev/sda1

To format as VFAT/FAT32 file system type the command:

# mkfs.vfat /dev/sda1

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

{ 12 comments… read them below or add one }

1 Mark Luxton August 15, 2008 at 3:58 pm

I have been using Gparted to set up my USB pen.
I find it near impossible to make mistakes this way.
I had formatted it as FAT16 and it works going from Linux box to windows box and back. Eventually the pen would not allow me to add files even though there was over 3GB available. Could this be due to the deletion of files only removing the TOC and not the actual data?
I just reformatted as FAT32 to see if that works better. Files are copying now. Is there a preferred format? FAT 16 or 32 or Linux Ext2 or 3. I realize it must be FAT to go to a Windoze box(or NTFS if all you got is Windoze).
Note: At one point I could not get a large group of files to copy to the root of the pen drive but was able to do so into a folder on the drive???

Reply

2 Richard Steven Hack October 13, 2008 at 9:48 pm

As for not being able to copy large number of files to a FAT16 root directy, I vaguely recall there is a limit to the number of files FAT16 supports in a root level directory. I think you can only a maximum of 512 files in a root directory because under the FAT16 system the root directory has a fixed size whereas subfolders do not.

Reply

3 Frank February 8, 2009 at 11:35 pm

Hi guys,

I have been pondering similar thoughts. It is my understanding that FAT16 in LBA mode is limited to a partition size of 2GB. Although, it has been reported that up to a 4GB partition is supported but is known to cause issues.

Can anyone shine further light on the limitations of a FAT16 partition?

References:

Link #1 and Link 2

Reply

4 Jitu June 10, 2010 at 5:34 pm

Hi, ALL

Can anybody help in Linux, I want to my usb format when I went through this command #mkfs.vfat /dev/sda1 . This is not working and I got error like.mkfs.vfat: /dev/sda1 contains a mounted file system. what is this mean?

Thanks

Reply

5 Anonymous J Coward March 21, 2011 at 9:08 am

This seems to have a high ranking on Google search, so let’s answer Jitu’s question.

The error means that the USB disk is mounted. When mounted, it cannot be formatted. To format it, first un-mount it. E.g.

#umount /dev/sda1

(oh, and do double check sda is your USB drive – not your internal hard drive before formatting :), e.g. by running ‘df’ )

Reply

6 Mark Luxton June 11, 2010 at 1:22 am

I had forgotten about the post I made here till just now getting an email from the last poster. The original “problem” I was having was that I needed to empty the trash. Then I had the actual space to copy my files. I had deleted several GB’s of data from my 8GB USB pen, then I tried to copy several more GB’s to the pen. Although it seemed that I had the space, it wasn’t actually free till emptying the trash.
FAT 32 seems to work best all around.
Using Gparted to do the formatting is easy.

Jitu. Perhaps you need to unmount /dev/sda1 before formatting from the command line? Also you may need to do this with root access. Mounted means that the drive is currently part of the Linux file system/operating system, and is “in use”.

Make sure you have selected the correct drive. /dev/sda1 is most likely your hard drives first partition, which you can not format while you are running your operating system from it. That is a good thing!

Reply

7 Mark June 11, 2010 at 11:48 am

Jitu. You did not say what GNU/Linux you are using, but I will tell you exactly what I do to format MY USB pens.
I have two hard drives and a DVD burner. Hard drive 1 is sda. Hard drive 2 is sdb.
Gparted does not show me the DVD burner since it can not format it. With my USB pen plugged in, Gparted lists it as sdc or sdc1(First and only partition).
I use these instructions for Ubuntu 8.04 and 10.04.

1/ Be connected to the internet.
2/ From a command line terminal do: sudo apt-get install gparted
Give root password.
3/ Plug in your USB pen.
4/ Run Gparted, giving your root password when asked.
5/ Click the drop down box in the upper right hand corner of Gparted’s window. Identify which “drive” is your USB pen. Mine is hdc1.
6/ From command line terminal or console window do : sudo umount /dev/sdc1
7/ You may have noticed a set of keys symbol after /dev/sdc1, in the line describing your USB pen in Gparted, which means it was mounted.
8/ In Gparted’s menu click Refresh Devices. The keys symbol is now gone.
9/ Click on the line describing your USB pen, in Gparted, to highlight it.
10/ Right click on the line, choose “Format to” and “fat32″.
11/ Click the green arrow to apply your choices.
12/ Close Gparted.
13/ Unplug your USB pen. Plug it back in. It should be mounted automatically and be ready to use.
14/ Remember to empty the “Trash” now and then after deleting lots of files from the USB pen so as to actually free up the space.
Works for me!

Reply

8 Anons July 26, 2012 at 1:30 am

You did not say that the flash drive must be unmounted!!

Reply

9 Philippe Petrinko November 8, 2012 at 3:36 pm

Hi Vivek,

Reading this old post, it would be great to modify some points:

1) Replace /dev/sda1 with another example as a file device. This device is most likely PC main hard drive partition. This is really dangerous for newbies. Try “/dev/sdc1″ for instance.

2) As “anons” pointed out, unmounting USB drive should be shown, as it has probably been automagically mounted when connected, as configured for most of desktop Linux distributions. At least this should be checked.

KUTGW,
— Philippe

Reply

10 Mac January 3, 2013 at 2:15 pm

How do you set a label on the USB thumb drive for example after you format it in NTFS?

I am searching for it via the command line but not finding anything?

Does anyone know?

Would I do this:

fdisk -l

Disk /dev/sdc: 4026 MB, 4026531840 bytes
128 heads, 30 sectors/track, 2048 cylinders
Units = cylinders of 3840 * 512 = 1966080 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc3072e18

Device Boot Start End Blocks Id System
/dev/sdc1 1 2048 3932145 87 NTFS volume set

I changed it via fdisk /dev/sdc1 to type ’87’

then I formatted it using:

wex01 $ mkfs.ntfs /dev/sdc1
Cluster size has been automatically set to 4096 bytes
Initizializing device with all zero’s

is this correct – then how do I label the device ?

Reply

11 cherry January 12, 2014 at 5:13 am

be careful,
if /dev/sda1 is the default partition of Windows if you happen to dual boot with windows in your hard disk. I am NOT into computers and these guys posting here are making fun of you. Be careful with fdisk command as root, especially the examples here, you can format your hard disk, with linux, with windows or with any other OS or important data. Do a backup before running fdisk

Reply

12 Mohammad Etemaddar April 26, 2014 at 5:00 pm

Cyberciti, You are great!

Reply

Leave a Comment

Tagged as:

Previous Faq:

Next Faq: