Master the Linux ‘mkfs.ext4’ Command: A Comprehensive Guide
This article offers a comprehensive overview of the Linux ‘mkfs.ext4’ command, including its history, usage, parameters, and real-world use cases. It also covers less common but powerful usage techniques and important points to be aware of.
Instructions
This guide presents a detailed walkthrough of the Linux ‘mkfs.ext4’ command aimed at beginners. It explores the history, usage, commonly used parameters, and real-world use cases of the command. Additionally, it delves into less common but powerful usage techniques and important points to be aware of.
History
The ‘mkfs.ext4’ command, as part of the larger ‘mkfs’ family of commands, has been a part of Unix and Unix-like operating systems since the early 2000s. It is specifically designed to create the fourth extended filesystem (ext4), which is a journaling file system for Linux, developed as the successor to ext3.
When and why to use it
The ‘mkfs.ext4’ command comes into play when you need to create an ext4 file system, which is commonly used in Linux distributions. It’s useful when setting up new drives, repurposing old drives, or preparing a partition for data storage.
How to use it
To use ‘mkfs.ext4’, you would typically provide the device identifier. For instance, to create a new ext4 filesystem on the first partition of the first disk:
$ mkfs.ext4 /dev/sda1
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 26104 4k blocks and 65408 inodes
Filesystem UUID: 2fc39a9c-faee-45c6-9651-8e25963739da
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
The commonly used parameters
-L
Assigns a volume label to the file system.
$ mkfs.ext4 -L my_volume /dev/sda1
-n
Performs a dry run without actually creating a file system.
$ mkfs.ext4 -n /dev/sda1
This is a dry run and no file system will be created.
Other supported parameters
-b
Specifies the block size for the filesystem.-m
Sets the percentage of blocks reserved for the super-user.-E
Offers extended options to the command.-F
Forces the creation of a file system.
Most common use cases
One of the most common use cases for ‘mkfs.ext4’ is formatting a new partition to prepare it for data storage.
$ mkfs.ext4 /dev/sdb1
Creating filesystem with 26104 4k blocks and 65408 inodes
The tricky skills
You can use the ‘-E’ flag to pass an extended option to ‘mkfs.ext4’. For instance, to continue creating a filesystem even when an existing filesystem is detected, use the ‘nodiscard’ option.
$ mkfs.ext4 -E nodiscard /dev/sdb1
What needs to be noted
- ‘mkfs.ext4’ requires superuser privileges to execute.
- Using ‘mkfs.ext4’ on a device with existing data will destroy that data.
Conclusion
‘mkfs.ext4’ is an essential tool for managing ext4 file systems on Linux. This guide provides a comprehensive overview of its usage, parameters, and real-world applications, helping beginners understand and utilize ‘mkfs.ext4’ effectively.