Formatting USB disk on Linux
Sometimes we may want to format external USB drive. I recently encountered a situation, where I had bootable USB drive with operating system ready to install, but I wanted to remove all this stuff and use disk for storing data. I couldn’t format this disk with GUI tools for some reason and I kept getting errors or information that it’s not possible. In case you don’t know, on Linux everything is always possible, so I quit that GUI tool, opened terminal and start playing with good old and simple programs.
When we insert disk and type:
we can see the output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
When we type:
sudo fdisk -l
Now, we have basic information about our USB drive. It’s located in
/dev/sdb and has
7,5 GB of space.
Sometimes, we can have mulitple partitions on our drive. In such case, we may want to delete them and create new partition.
To do that, we can type:
next, we can use
d for deleting partition:
Welcome to fdisk (util-linux 2.34).
n for creating a new one:
Command (m for help): n
after that, we can confirm the process with
Command (m for help): w
next, we can umount drive:
sudo umount /dev/sdb
and create a file system - in our case, we’ll use FAT32 file system in order to make USB drive accessible across all operating systems
sudo mkfs.vfat /dev/sdb1
after that, we can create a label for our disk with name
disk3 (it can be anything):
sudo mlabel - /dev/sdb1 ::disk3
Please note, when we create file system of a different type, we need to use different commands for creating disk labels. For more information about that, read article about renaming USB devices on Linux.
That’s it! Maybe it’s not that easy as clicking on the GUI, but we can see whole process and format any disk even when something seems to be messed up.