Open In App

mkfs Command in Linux with Examples

The mkfs command stands for “make file system” is utilized to make a file system (which is, a system for organizing a hierarchy of directories, subdirectories, and files) on a formatted storage device usually, a partition on a hard disk drive (HDD) or it can also be a USB drive, etc. A partition is logically an autonomous part of an HDD. An organized segment is one to which a low-level arrangement or format, additionally called a physical format(organization), has been applied. It comprises separating the disk’s tracks into a predetermined number of divisions and filling the information zone of every segment with dummy bytes. 

These outcomes in the demolition of any current information on the disk. Formatting(organizing) of new HDD and floppy plates is done at the manufacturing plant. It is seldom important to do a low-level format on an HDD. The creation of a file system is also known as high-level formatting or logical formatting. It includes making a table of contents for the partition or disk, but in this case, the data already present on the disk or segment is not destroyed. Basically, “mkfs” is just a front-end for the various specific file system creation programs that are available in Linux, such as mke2fs, mkfs.ext3 and mkfs.vfat, etc. When the “mkfs” command is compiled, then a precise list of standard directories is created, and therefore the specified program is searched for from the same list.



Syntax for mkfs command:

mkfs [ -V ] [ -t fstype ] [ fs-options ] filesys [ blocks ]

Journaling

It is a significant idea in file systems. The file system records the awaiting file keeps in touch with a diary. As each file is composed of, the diary is refreshed, and the unresolved setup accounts are refreshed. This permits the file system to fix broken, halfway composed files that have happened because of a disastrous occasion, for example, a power cut. A portion of the more seasoned file systems doesn’t uphold journaling. Those that don’t, keep in touch with the disk, less regularly in light of the fact that they don’t have to refresh the diary. They might give a faster performance, yet they are more inclined to harm because of interrupted file writes.



 

To make a File System on a USB:

1. Finding the required device on the OS through the terminal. Type in the following command, and it will show all the disk nodes that are currently mounted. Be always sure in choosing the right disk or otherwise, you can remove the storage device and then again plug it in if the above command is not showing it in the list, thereafter again run the above command to list all the nodes. Here, our required disk is “/dev/sdb” which is of 3.7 GiB.

sudo fdisk -l

2. Un-mounting the USB drive’s partition

Un-mounting the storage drive is necessary before performing the format. Run the following command, but remember to replace “sdb1″ with your USB drive’s partition label, and then press Enter. 

sudo umount /dev/sdb1

3. Erasing all the data on the drive (discretionary)

You can erase everything on the drive by entering the following command. But, remember to supplant “sdb” with your USB drive’s name.

sudo dd if=/dev/zero of=/dev/sdb bs=4k status=progress && sync

4. Creating a new partition table

Type in the following command, by replacing “sdb” with your USB drive’s label, and then press Enter.

sudo fdisk /dev/sdb

Enter “o” for creating an empty partition table.

Enter the option “n” for creating a new partition.

Enter “w” to write the table and exit.

5. Execute the following command for viewing the partition.

lsblk

6. Formatting the new volume created

Enter the following command and press Enter for formatting the drive as ext4. Remember to, replace “sdb1” with your partition’s label: 

sudo mkfs.vfat /dev/sdb1

7. Verifying the newly created filesystem

Run the following command in the terminal:

sudo file -sL /dev/sdb1

8. Lastly, execute the following command for ejecting the drive when finished.

sudo eject /dev/sdb

Now, We have successfully formatted the USB storage device and have also created a file system with a partition.

Article Tags :