Back to blog
GuidesAugust 30, 2026·10 min read

Linux Format HDD: How to Partition and Format Disk Drives

Linux Format HDD: How to Partition and Format Disk Drives

If you're wondering how to format HDD in Linux, the job breaks into three actions: identify the drive using lsblk, partition it using fdisk or parted, then build a file system using mkfs. Linux format HDD may seem like something a single command could do, yet it isn't. Those extra actions are a safety net, since typing one wrong device name erases the contents of the wrong drive.

This article will help you to accomplish all the actions in order to format an HDD on Linux step by step: identify the device, partition, choose one of the Linux disk formats (ext4, XFS, NTFS, FAT32), mount and set up automatic mounting after boot. At the end, you will learn how to securely erase the contents of a drive in order to delete everything that is stored there.

WARNING! All the commands in this tutorial that touch a partition table or filesystem will destroy data on the chosen drive. Double check the device names before you hit Enter. In case you are not sure – stop and double check it again.

Things you need

  • Linux computer with a connected drive (whether SATA, USB or a virtual disk in VM).

  • Root access (or sudo) privileges

  • Backup of all the data on the target disk which is still needed. There is no Undo for mkfs command.

Step 1: Identify the disk

In order to format a disk on Linux, you will need to find out its device name. Making a guess in this stage is how people destroy their system drive.

List block devices with lsblk command

bash

lsblk

plain

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   256G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0  63.5G  0 part /
└─sda3   8:3    0     8G  0 part [SWAP]
sdb      8:16   0   1.8T  0 disk

In the tree, each disk is listed with its partitions beneath it. Partitions on sda have mount points, meaning the disk is being used. sdb is an unused 1.8 TB disk with nothing mounted, which marks it as the new drive. The SIZE column helps you confirm which disk is which.

Check detailed information with fdisk -l command

bash

sudo fdisk -l /dev/sdb

You will see the model, precise size of the disk in bytes and sectors and if the partition table is present on this disk. If fdisk recognizes the model and the capacity of the disk as expected – you have found the right device.

Find out what is mounted with df -h command

bash

df -h

df will list only the mounted filesystems, so you will not see anything on the new, not formatted yet disk. Its purpose here is to protect you: make sure that /dev/sdb is not listed in any of the mount points – if it is, it means that it is used somewhere and you should not format it.

Step 2: Create partition table with fdisk or parted

The partition table tells the OS where each partition sits on the disk. If the disk is larger than 2 TB, you have to use a GPT table rather than MBR. Our 1.8 TB example is just below that threshold, but most new drives are above it. Both tools can create GPT: parted copes better with very large drives and scripts, while fdisk is more comfortable interactively.

Interactive partitioning with fdisk

bash

sudo fdisk /dev/sdb

Notice that we use device name sdb (whole disk), not sdb1 (partition). Inside fdisk:

  1. Type g to create a new GPT table.

  2. Type n to create a new partition. Press enter to accept default partition number, first sector and last sector in order to use the entire disk.

  3. Type p to print the layout of new table and check it.

  4. Type w to apply the table and exit.

Nothing changes until the last step. You can exit without applying any changes with q command without any harm.

Partitioning script with parted

bash

sudo parted /dev/sdb mklabel gpt
sudo parted -a optimal /dev/sdb mkpart primary 0% 100%

The -a optimal flag allows to align the partition to sectors of the physical drive, which is important in case of modern 4K-sector drives. In contrast to fdisk, parted applies changes immediately so there is no step to review the table, so be sure before you run it.

In any case, repeat the lsblk command. Now you will see sdb1 partition under sdb disk.

Step 3: Format the partition with mkfs

Partitioning marks the start and the end of the partition; formatting creates a filesystem inside it. Linux disk formatting is a family of commands rather than one: mkfs allows you to create filesystem of every common disk format in Linux, the syntax is always mkfs.<type>

ext4: the default Linux disk format

bash

sudo mkfs.ext4 /dev/sdb1

ext4 is a perfect choice in case if the drive will be used only by Linux operating systems: it is journaled, fast, well tested and recognized by every possible installer or rescue system.

XFS: for large files and volumes

bash

sudo mkfs.xfs /dev/sdb1

XFS is much better in handling large volumes and high parallel I/O than ext4. That's why Red Hat chose it as the default file system. The price of this is that you cannot decrease the size of XFS partition, only increase.

FAT32 and NTFS: for sharing across multiple OSes

bash

sudo mkfs.vfat -F 32 /dev/sdb1    # FAT32
sudo mkfs.ntfs -Q /dev/sdb1       # NTFS (quick format)

If the drive needs to work with other systems, use FAT32 or NTFS. FAT32 is outdated but compatible with nearly everything, from older devices to EFI partitions, yet no file may be bigger than 4 GB. NTFS handles big files easily, but on Linux it needs a driver: ntfs-3g, or the ntfs3 driver built into kernel 5.15 and later.

Regardless of the choice, mkfs will print the UUID of the created file system. Write it somewhere: you will need it in the following step, and it can be retrieved with sudo blkid /dev/sdb1.

How the result should look like

Successful formatting will not give any output except for the block groups or allocation units, no errors, and UUID at the end. Check it with lsblk -f command, which will give you the additional info:

plain

NAME   FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sdb
└─sdb1 ext4   1.0         5f3c8a2e-9b1d-4e7a-a6c2-1d0e8f4b2c91

The output above should look similar to yours: in the FSTYPE column you will see the file system that you have created. Your partition should be located under its parent disk. If the FSTYPE field is empty, formatting was unsuccessful or you have formatted the wrong disk. If the partition itself is missing – go back to the previous step. In case of existing partitions, the output will differ, but every old filesystem signature should be gone from the partition you reformatted.

Step 4: Mount the filesystem and automount it with /etc/fstab

Formatting a hard drive on Linux does not allow seeing the new drive in file tree: you should mount it manually.

Mount the drive manually

bash

sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data

Make sure that it works by using df -h /mnt/data command; this mount survives until you unmount it or reboot.

Persistent mount with /etc/fstab

In order to mount the disk automatically at boot, you will need to add a new row to the /etc/fstab file. Use UUID instead of /dev/sdb1, because device letters may vary when you connect or disconnect other disks; but the UUID of the drive will not change.

plain

UUID=5f3c8a2e-9b1d-4e7a-a6c2-1d0e8f4b2c91  /mnt/data  ext4  defaults  0  2

You should replace ext4 with xfs, vfat or ntfs depending on the format which you have chosen. In order to avoid problems, follow two simple rules here. First of all, test it before reboot:

bash

sudo mount -a

This will notify you about any error in fstab file before you will see an emergency shell at boot. Second of all, before editing /etc/fstab, make a copy of it: sudo cp /etc/fstab /etc/fstab.bak.

Step 5: Securely wipe a disk

Deletion of files or even reformatting allows recovering the data with special software. In case you plan to sell, recycle or repurpose the disk – wipe it completely.

Wipe with shred

bash

sudo shred -v -n 3 /dev/sdb

This command will overwrite the disk 3 times with random data and show you the progress. Use -z parameter in order to finish with zeros and hide the shred procedure from other tools.

Zero fill with dd

bash

sudo dd if=/dev/zero of=/dev/sdb bs=64K status=progress conv=fdatasync

One-time zero pass is enough in order to destroy the possibility of recovery in standard software, and it allows you to find broken sectors of the drive, because dd stops on them. However, be careful with this command: dd got the nickname of "disk destroyer" because of its dangerousness. Read twice: transpose if and of parameters, or substitute sda instead of sdb and you will overwrite whatever you pointed out without asking.

It is important that both of these commands are not suitable for SSDs. Due to the mechanism of wear leveling, neither of them will guarantee the erasure of the drive. In case of SSDs use blkdiscard or manufacturer's secure erase utility.

Where you can find help

Each of these tools has a man page, and it is far more thorough than any blog post: man fdisk, man parted, man mkfs.ext4 and man fstab cover the options this tutorial left out. For a quick reference, fdisk --help and parted --help list the most common flags, and the tldr command (from the tldr package) shows worked examples for each tool. If a command gives you an unexpected error, post the error and the output of lsblk -f on your distribution's forum or on Unix & Linux Stack Exchange.

FAQ

What is the best disk format for Linux?

ext4 is better for general use; XFS is more suitable for very large volumes or heavy parallel workload. In case of cross-platform drive, use FAT32 (universal but limits each file to 4 GB) or NTFS (allows large files and works on both Linux and Windows).

Is it possible to format a disk in Linux without loss of data?

No, you will lose it. Formatting implies destruction of existing file system in the partition, so if you need this data – transfer it beforehand, or use resizing/converting tools for particular file systems instead of mkfs.

How can I find the format of the Linux disk?

Use either lsblk -f or sudo blkid command. These commands will print the filesystem type and UUID for every partition.

Do I need to partition my disk before formatting it?

Yes, and it is recommended practice, even for the drive with one partition only, because tools expect the partition table to be present. You can technically put a file system on a raw device with mkfs.ext4 /dev/sdb, but some tools will reject it.

Summary

Whether you searched "linux format HDD", "format disk Linux", "linux format drive", "linux format disk" or "format hard drive Linux" – all the actions will be the same: use lsblk and confirm the drive with fdisk -l, partition it with fdisk or parted, format it with proper mkfs command, mount and bind it in /etc/fstab via UUID.

Get started with Orbit Servers

Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.

Get started
Julius

Written by

Julius

Product Manager

Julius is a product-minded builder who cares about making technology simpler and more useful for the people who rely on it. He’s always looking for ways to improve things, one small step at a time, and enjoys turning good ideas into products that work.

Related posts