Open In App

Formatting the Drive in Linux

Last Updated : 01 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Formatting drives is easy(if you know what you are doing) in Linux but with a tiny mistake, you can lose data or due to wrong formatting you may also corrupt some important files. So in this article, we will tell you about some basic formatting commands in Linux. Even though you can use number graphical tools available in Linux to manage your drives but there will be some cases where you may get errors and fail to format a drive due to some issues but with a simple command, you can do all that in the terminal which is much easier and fail-safe.

Why Proper Drive Formatting Matters in Linux

Formatting drives in Linux is powerful but risky — one wrong command can erase critical data instantly. It’s not just about wiping a USB drive; you’re preparing storage for use by the system, whether it’s a hard disk, SSD, or removable device.

Although graphical programs such as GParted or KDE Partition Manager work fine for starters or minimal tasks, they lack the accuracy and scripting features necessary for advanced or automated environments. That is where the Linux terminal comes in handy. By using commands such as lsblk, fdisk, parted, and mkfs, you have total command over disk partitioning and formatting — perfect for experienced users, system administrators, or anyone handling Linux servers.

Reasons for Proper Formatting

  • Data Integrity: Proper formatting guarantees the filesystem (e.g., ext4, NTFS) keeps data structured without errors, saving server operations from file corruption, according to 2025 Red Hat manuals.
  • Performance Optimization: Selecting an appropriate filesystem (e.g., Btrfs for snapshots) improves read/write I/O speed, essential for cloud storage or database servers, with SSDs improving 20% in performance, according to Phoronix benchmarks.
  • Compatibility: Changing to FAT32 or NTFS makes drives compatible with Linux, Windows, and macOS, ideal for USB sharing or dual-booting.
  • Security: Accurate partitioning and filesystem configuration keep hackers from taking advantage of misconfigured drives, 25% of server hacks being storage-related, according to IBM Security 2025.
  • Automation: Terminal commands such as parted and mkfs get translated in AnsCNFst or Terraform so mass-formatting would be possible in Kubernetes clusters according to CNCF trends.

The lsblk Command

lsblk command: This command tells you about the all the devices connected to your machine.

  • NAME: It is the column which shows name of the device.
  • MAJ:MIN: It shows major and minor device number.
  • TYPEdisk (physical drive) or part (partition)
  • MOUNTPOINT: Where the drive is mounted (never format mounted drives!)
  • sda1 and sda2 denotes the partitions on devices, sdb is USB, sda is SSD, if you have an internal hard drive it will show as sdc.

Steps for Formatting the Drive

Here, we are using a virtual machine for the tutorial but the commands and process will be the same for all kinds of drive and machines. So we will be formatting the 3.7 GB sdb(USB Drive) for this. You can perform it for any storage device whether internal or external. There are a number of tools in Linux for partitioning drives but we will use 'parted' because it is easy to use. We will use MBR partitioning ('parted' also supports GPT partitioning').

Step 1:

Below command will open the parted utility and then you will work inside that.

sudo parted /dev/sdb

Step 2:

It creates the partition table and MBR will be used by msdos. You may see warnings regarding partition, just make sure you are partitioning the right drive and enter ignore/y to bypass the warnings.

mklabel msdos

Step 3:

The basic syntax for partition command

mkpart 'partition type' 'file system' start end

If you want to use all space and create one partition use:

mkpart primary ext4 1MiB 100%

if you want to create more than one partition use:

mkpart primary ext4 1MiB 2GB

To create another partition, use:

mkpart primary ext4 2GB 3GB

Here 2 GB is the starting point for this partition because it was an endpoint in the last one and 3GB is the endpoint of this partition. The endpoint can be changed according to what size partition you want, here it will create the second partition of size 1 GB.

Step 4

To see the result of partition use print command, it will display all partitions you have created.

(parted) print

Step 5

If you are satisfied with your partitions, use exit command Now running 'isblk ' will show all the new partitions. You can use any desired file type such as NTFS, vfat, btrfs, etc.

(parted) quit
lsblk

Common Filesystems

Understanding filesystems is important when setting up or managing drives on Linux. A filesystem determines how data is stored, accessed, and organized on a disk. Below are some of the most commonly used filesystems in Linux,

FilesystemUse Case
ext4Best choice for Linux-only systems. It is stable, reliable, and supports large files and partitions. ext4 is the default filesystem in most Linux distributions like Ubuntu and Debian.
NTFSIdeal when you want to share drives between Linux and Windows. NTFS supports file permissions and is widely used on external hard drives and dual-boot setups.
FAT32Great for small USB drives (less than 32GB). It works across almost all operating systems including Linux, Windows, and macOS, but has a 4GB per file size limit.
BtrfsDesigned for advanced use cases like creating snapshots, RAID, or file compression. Suitable for users who need more control over data integrity and versioning in Linux environments.

Data Safety When Formatting the Drive

When dealing with external drives or partitions in Linux, it is important to maintain proper safety measures to prevent data corruption or unintentional loss.

Unmount First

Always unmount the drive first before doing things like formatting, resizing, or safely ejecting it.

sudo umount /dev/sdb*  # * = all partitions on the drive

Backup Data

Before altering the disk, backup your valuable files using the rsync command.

rsync -av /mnt/usb/ /backup/  # Copy files safely from USB to backup directory

Verify with lsblk

Double-check with lsblk that the device is correctly unmounted and see its partitions, mount points, and filesystem types.

lsblk -f             # Displays detailed info about block devices and mount status

Conclusion

Formatting a drive in Linux is not merely deleting information — it's about preparing the storage for long-term, dependable use. With easy but effective tools such as parted and mkfs, Linux provides you with complete control over how your disk is divided and what filesystem it has. By doing things the right way — from listing devices with lsblk, to unmounting and backing up data — you can have a smooth and secure formatting process.

Whether you’re preparing a USB drive for dual-boot, organizing partitions for better performance, or reformatting external storage, doing it properly avoids system errors and lost files


Next Article
Article Tags :

Similar Reads