Formatting the Drive in Linux
Last Updated :
01 May, 2025
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.
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.
- 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.
- TYPE:
disk
(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.
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,
Filesystem | Use Case |
---|
ext4 | Best 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. |
NTFS | Ideal 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. |
FAT32 | Great 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. |
Btrfs | Designed 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. |
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
Similar Reads
How to Format USB Drives On Linux
It may be essential to format the USB device on occasion (for example, when changing the file system or deleting data). Many Linux users, on the other hand, are hesitant to begin the formatting process, believing it to be either difficult or time-consuming. We'll learn how to format a USB drive in L
3 min read
How to Use Google Drive in Linux
Google Drive is one of the famous cloud storage services provided by Google. Google Drive allows users to store files online and access them from anywhere. Google Drive is available for all major platforms i.e. Windows, MacOS, Linux, and others. In this article, we will learn how to use Google Drive
8 min read
cfdisk command in Linux with examples
cfdisk command is used to create, delete, and modify partitions on a disk device. It displays or manipulates the disk partition table by providing a text-based "graphical" interface. cfdisk /dev/sda Example: After running you get a prompt like this: Choose gpt from the list. Now you will see a parti
3 min read
Device Drivers in Linux
Drivers are used to help the hardware devices interact with the operating system. In windows, all the devices and drivers are grouped together in a single console called device manager. In Linux, even the hardware devices are treated like ordinary files, which makes it easier for the software to int
3 min read
How to Create File in Linux
Today, we're going to learn about something really important â how to create files in Linux. It's like creating a fresh piece of digital paper to write or store things. We'll explore different ways to do this using simple commands. Whether you're just starting out or have been using Linux for a bit,
7 min read
How to Delete Files in Linux?
Linux comes with several tools that can assist us in removing Directories and files. We always need to delete many files and folders based on a set of requirements. To complete our mission quickly, knowing a few basic commands and their variations is beneficial. Use caution when using the commands b
6 min read
What is /Dev/Null in Linux?
If you have been learning shell programming, you may already have come across something like /dev/null. In this article, we will understand what it is and how it is used. Let's start off by understanding what /dev is. What is /dev?In the Linux file system, everything is a file or a directory. Even d
5 min read
How to Find Out File Types in Linux
In Linux, everything is considered as a file. In UNIX, seven standard file types are regular, directory, symbolic link, FIFO special, block special, character special, and socket. In Linux/UNIX, we have to deal with different file types to manage them efficiently.Categories of Files in Linux/UNIXIn
7 min read
How to Format a Hard Drive in Windows?
Formatting a hard drive in Windows is a crucial task that prepares the drive for data storage, resolves system errors, and clears unwanted data. Whether you're setting up a new hard drive, cleaning an old one, or solving file system issues, knowing how to format your drive correctly is essential. Th
4 min read
Display File System Type in Linux
Understanding the file system type on a Linux system is crucial for efficient management and troubleshooting. Different file systems serve various purposes, and identifying them provides insights into storage devices and their capabilities. This article explores various methods to display the file s
4 min read