Format a FAT memory stick on Linux without dependencies

 Â· 2 min Â· torgeir

This is something I always forget, so here are the notes.

Terminal Linux Fdisk Memorystick Format Fat

Find the device

Run the lsblk command to determine the name of your memory stick

watch -n 1 lsblk

Now, plug it in and wait for it to appear.

Determine its name

In /dev/sdX part, X often being a, b, c or d, depending on how many disks you have, represents the disk.

In /dev/sdXY part, Y represents the partition.

Unmount the partition

Continue root for the rest of the process, not to have to type sudo all the time.

sudo su -

If it was already plugged in, make sure to unmount the partition before you continue.

umount /dev/sdXY

Caution!

Before you continue, make sure you triple check that what you are about to enter is not your main hard drive. Cause the following will mess it up, unconditionally, unrecoverably, if you were to pick the wrong disk.

Format the disk

Setup partition table and create new partition

fdisk /dev/sdX
o (creates a new empty partition table)
p (displays the current partition table on the disk)
n (starts the process of creating a new partition)
p (specify that it is a primary partition)
default (make the partition occupy the full disk)
default (set partition id to the default)
default (set partition type to the default, FAT)
t (start process of changing partition id)
c (change partition id to 0xC, used by FAT32 filesystem.)
w (write the partition table to the disk and exit)

Format the partition with the desired filesystem

mkfs.vfat /dev/sdXY

All good 👍

Edits

[2023-07-16 Sun 16:00] If you created the partition without specifying FAT, and just kept ’linux’ it will be ext3.

Do this instead to format it an with ext3 filesystem

mkfs.ext3 /dev/sdXY