How to Format a Drive in Linux Safely Using the Command Line
Formatting a drive in Linux is straightforward, but selecting the wrong device can permanently erase important data. Whether you are preparing a new SSD, reformatting a USB drive, or creating a fresh Linux partition, the safest approach is to identify the device first, unmount it, and then create the required file system.
Linux provides several built-in tools for this process, including lsblk, umount, mkfs, and parted.
Warning: Formatting a partition destroys the files stored on that partition. Verify the device name carefully before running any
mkfscommand.
1. Find the Drive You Want to Format
Start by listing the storage devices connected to the Linux system:
lsblk -f
You may see output similar to:
NAME FSTYPE FSVER LABEL UUID MOUNTPOINTS
sda
├─sda1 ext4 1.0 7d2f... /
sdb
└─sdb1 exfat 1.0 USB 87F2...
In this example:
/dev/sdais the main system disk./dev/sdbis the secondary drive./dev/sdb1is the partition that will be formatted.
Check both the disk size and existing filesystem before continuing. Accidentally formatting your operating-system partition can make the system unusable.
2. Unmount the Drive
A mounted filesystem should normally be unmounted before formatting.
For example:
sudo umount /dev/sdb1
You can run lsblk again to verify that the partition no longer has a mount point.
If Linux reports that the device is busy, check whether an application or terminal session is currently accessing files on the drive.
3. Format the Drive as ext4
For a drive that will primarily be used with Linux, ext4 is one of the most common choices.
Run:
sudo mkfs.ext4 /dev/sdb1
Red Hat documents mkfs.ext4 as the standard command for creating an ext4 filesystem on a block device and notes that its default options are appropriate for most common situations.
You can also assign the drive a label while formatting it:
sudo mkfs.ext4 -L DataDrive /dev/sdb1
After formatting, verify the new filesystem:
lsblk -f
or:
sudo blkid /dev/sdb1
Format a Linux Drive as XFS
XFS is another widely used Linux filesystem, particularly for systems handling large files or high-throughput storage workloads.
To create an XFS filesystem:
sudo mkfs.xfs /dev/sdb1
Red Hat describes XFS as suitable for high-performance and scalable storage environments and documents mkfs.xfs as the standard filesystem-creation command.
For a normal desktop Linux drive, ext4 is generally the simpler choice. XFS is especially useful for servers and storage-heavy workloads.
Format a Drive as exFAT
If the drive needs to move between Linux, Windows, and macOS, exFAT can be more convenient.
After installing the required exFAT utilities for your distribution, use:
sudo mkfs.exfat /dev/sdb1
This can be useful for external SSDs and USB drives that need cross-platform compatibility.
Reformat an Entire Hard Drive in Linux
Sometimes you do not want to format an existing partition. Instead, you may want to erase the existing partition layout and prepare the entire drive again.
First confirm the disk:
lsblk
Assuming the target is /dev/sdb, start GNU Parted:
sudo parted /dev/sdb
Create a new GPT partition table:
mklabel gpt
Then create a new partition:
mkpart primary ext4 0% 100%
Exit:
quit
GNU Parted documents mklabel for creating a new partition table and mkpart for creating partitions. Creating a new disk label can make existing partitions inaccessible, so the target disk must be checked carefully.
The new partition will normally appear as something similar to:
/dev/sdb1
You can then format it:
sudo mkfs.ext4 /dev/sdb1
Which Linux Filesystem Should You Choose?
For most users, the choice can be simplified to:
| Filesystem | Best Use |
|---|---|
| ext4 | General Linux desktops, servers and internal drives |
| XFS | Large files and high-throughput server storage |
| exFAT | Drives shared between Linux, Windows and macOS |
| FAT32 | Smaller removable devices requiring broad compatibility |
| NTFS | Drives primarily intended for Windows interoperability |
The Linux kernel supports a wide range of filesystem implementations, including ext4, exFAT, F2FS and several network and specialized filesystems.
For a standard Linux installation or secondary internal drive, ext4 is usually the safest default choice.
Quick Linux Drive Formatting Example
If /dev/sdb1 is the partition you want to erase and use as an ext4 Linux drive, the basic process is:
lsblk -f
sudo umount /dev/sdb1
sudo mkfs.ext4 -L DataDrive /dev/sdb1
lsblk -f
Do not copy these commands blindly. Replace /dev/sdb1 with the actual partition shown on your system.
Frequently Asked Questions
How do I format a disk in Linux?
Identify the disk using lsblk, unmount its partition with umount, and then create a filesystem using a command such as:
sudo mkfs.ext4 /dev/sdb1
What is the best format for a Linux hard drive?
For most Linux desktop and general-purpose server environments, ext4 is a strong default. XFS may be preferable for some high-throughput storage workloads.
Does formatting a drive delete everything?
Formatting creates a new filesystem structure and can make existing files inaccessible. Red Hat explicitly warns that formatting a partition permanently destroys the data currently stored on it.
Back up anything important before proceeding.
How can I check the filesystem type in Linux?
Run:
lsblk -f
You can also use:
blkid
These commands help identify filesystem types and UUIDs before or after formatting.
Final Check
Before formatting any Linux drive, remember the safest sequence:
Identify the device → verify the device name → back up important files → unmount the partition → create the filesystem → verify the result.
Most formatting mistakes happen because the wrong /dev/sdX device is selected, not because the formatting command itself is complicated.
Taking a few seconds to verify the disk with lsblk before running mkfs can prevent an irreversible data-loss mistake.
No Comment! Be the first one.