Skip to content

KALI – How to format a USB pen in Linux


We can format a USB in ext3 (the linux format) or vfat (for both Windows and Linux) machines.

Step 1 – Find out the exact name of the USB


mount step 1mount will list out the /dev/sdxx listing for all drives.  We could also use:

ls /dev

To get a real-time view of the /var/log/messages file the command is

sudo tail -f /var/log/messages

You’ll see the device reported… press control + c to get the prompt back.

If it’s USB pen, it’s very likely the drive will be


It’s important to know that /dev/sdb is the entire device and /dev/sdb1 is the first partition on the device.


Step 2 – Unmount the USB

**notice the spelling.. it’s umount

 umount /dev/sdb1


Step 3 – Create a new Filesystem with FDISK

sudo umount /dev/sdb1

sudo fdisk /dev/sdb

The first thing to do is to exame the existing partition, we do this by entering P at the prompt.  Entering L will list out all possible file types, and T will change a partition’s system ID.  The Hex code for Linux is 83.

Up to this point, the device has not been touched, all the changes are stored in memory not the physical device.  To save, we write using W.  If you want to leave the device unaltered, enter q at the prompt to exit FDISK without writing the changes.  Ignore the “doom and gloom” warning messages.

Step 4 –  Create a new filesystem with MKFS – convert to a Linux ext3 filesystem.

mkfs means “make filesystem” on our flash drive.

sudo mkfs -t ext3 /dev/sdb1

convert to ext3 red arrows


This means “make a filesystem”, of “type ext 3” on “device” at “/sdb1”

Watch the Inodes and file system being created

writing ext3 to usb green tick on inodes


Step 5 – ReFormat the USB back to VFAT for Windows

To reformat the device to its original FAT32 filesystem, specify VFAT as the filesystem type.

sudo mkfs -t vfat /dev/sdb1

convert usb back to fat 32 - wordsVFAT allows both Linux and Windows to read/write to the USB.  However it has a 4 GB single file limit.. which might catch you out if you try to write say the CENTOS 6.5 DVD ISO to a USB…as the filesize is 4.3 GB.

Step 6 – Check the filesystem with FSCK

Fsck can repair corrupt filesystems.  Recovered portions of files are placed in the lost+found directory, in the root of each filesystem.

sudo fsck /dev/sdb1

check that fat32 exists - words 2


Admission – I was on the Backtrack Machine at the time… sorry – my bad!


Why is unmounting important?

In the output of the “free” command we see statistics including BUFFERS.  In order to make systems work as fast as possible, data is sent to buffers, the writing to the physical device is often deferred to a future time.  The data piles up in memory.  Occasionally the OS will write out this data to the physical device.  Unmounting a device allows all the remaining data to be written to the device so that it can be safely removed.  If the device is removed without being unmounted, some data maybe lost.  In some cases, this data may include vital directory updates, which will result in a filesystem corruption, which is one of the worst things that can happen.



University South Wales reading list.

SHOTTS, W.E., 2012.  The Linux Command Line.  San Francisco: No Starch Press.

  1. pfffff

    mkfs command not found … fucking ridiculous. Linux sucks. Everytime you check something on the internet you need to install a new package. Not talking about old answer like the ipconfig /ifconfig. For someone who needs to get things done quickly its a nightmare. Once I got stuck for 2 days trying to compile a proprietary driver following advice on the internet. versus 20sec installer on windows. LInux is trashh

    Liked by 1 person

  2. Hi dontsay that, here’s a couple of things to check out if mkfs appears to have gone AWOL.

    1. Are you trying to run as root? Normal users won’t be able to access /sbin, but root can.
    2. is mkfs in /bin or /sbin?
    ls /sbin/mkfs*

    3. Does the PATH include /bin and /sbin
    echo $PATH

    Found this link for you:

    Do you have /sbin in your path?

    Most likely you are trying to run mkfs.ext4 as a normal user.

    Unless you’ve added it yourself (e.g. in ~/.bashrc or /etc/profile etc), root has /sbin and /usr/sbin in $PATH, but normal users don’t by default.

    Try running it from a root shell (e.g. after sudo -i) or as:

    sudo mkfs.ext4 -L hdd_misha /dev/sdb1
    BTW, normal users usually don’t have the necessary permissions to use mkfsto format a partition (although they can format a disk-image file that they own – e.g. for use with FUSE or in a VM with, say, VirtualBox).

    Formatting a partition requires root privs unless someone has seriously messed up the block device permissions in /dev.

    Good luck!

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: