How to Format a Drive with an ext4 Filesystem Using the mkfs Command in Linux

When you install a brand-new hard drive or SSD into a Linux server, the operating system will recognize the physical block device (e.g., /dev/sdb), but you cannot actually save any files to it yet. Before a storage drive can hold data, it must be mathematically structured with a filesystem, which acts as a massive index tracking where every file begins and ends on the physical disk platters. To create this critical filesystem structure, you must format the partition using the mkfs (make filesystem) command.

Understanding the mkfs Architecture

The mkfs command is technically not a single program; it is a unified frontend wrapper. Depending on which filesystem type you specify, mkfs silently calls a specialized builder program in the background (such as mkfs.ext4, mkfs.xfs, or mkfs.vfat) to do the actual formatting work.

In the modern Linux ecosystem, the ext4 (Fourth Extended Filesystem) format is the absolute gold standard for reliability, speed, and journaling capabilities, making it the default choice for almost all internal server drives.

How to Format a Drive to ext4

Warning: Formatting a partition instantly and permanently destroys absolutely all data currently stored on it. Double-check your drive letters using lsblk before proceeding.

Assuming you have already used a partitioning tool like fdisk to create a new, empty primary partition designated as /dev/sdb1, you must run the format command with root privileges.

  1. Open your terminal.
  2. Execute the format command by typing: sudo mkfs -t ext4 /dev/sdb1
  3. Press Enter.

The -t flag explicitly tells the wrapper to use the ext4 architecture. You can also bypass the wrapper entirely and call the specific builder directly by typing sudo mkfs.ext4 /dev/sdb1. Both commands achieve the exact same mathematical result.

Understanding the Formatting Process

Once you press Enter, the terminal will output a series of highly technical status updates as the format progresses.

  • Discarding device blocks: If you are formatting a Solid State Drive (SSD), the system will issue TRIM commands to wipe the flash memory cells clean, ensuring maximum write speeds for your future files.
  • Creating journal: The builder establishes a reserved “journal” section. If your server suddenly loses power during a file transfer, this journal prevents the filesystem from becoming fatally corrupted, allowing for instant recovery upon reboot.
  • Writing superblocks and filesystem accounting information: This final step writes the master index tables across the drive.

When the terminal returns you to a standard bash prompt, the formatting is complete. The partition is now structured with a robust ext4 filesystem and is ready to be mounted to a directory so you can begin saving data.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.