mkfs Command in Linux

Learn via video courses
Topics Covered

Overview

The mkfs command in Linux is a powerful tool used to create a filesystem on a device, typically a hard disk partition. Essentially, this command prepares a storage device for usage by writing a specific filesystem structure. This introduction to the mkfs command in Linux will guide you through its syntax, options, and some of its essential and advanced use cases.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of mkfs Command in Linux

The basic syntax of the mkfs command in Linux is as follows:

Where:

  • options: This part of the command allows for control over the behavior of mkfs. Examples include -V for verbose output and -t for specifying the filesystem type.
  • filesystem_type: This defines the type of filesystem to be created. Examples are ext4, vfat, ntfs, etc.
  • device: This represents the device on which the filesystem will be created. It could be a disk partition like /dev/sdb1 or a whole disk like /dev/sdb.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Options in mkfs Command in Linux

  1. -V: Produces verbose output, including all filesystem-specific commands that are executed.

    For example -

    Output:

    This command creates an ext4 filesystem on the /dev/sdb1 device, providing verbose output.

  2. -t: Specifies the type of filesystem to be created.

    For example -

    Output:

    This command creates an ext4 filesystem on /dev/sdb1.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Example Usages

  • Creating a filesystem without specifying type (default is ext2):

    Output:

    Explanation: Creates a new ext2 filesystem on the partition /dev/sdb1.

  • Creating a vfat filesystem:

    Output:

    Explanation: This command creates a vfat filesystem on the partition /dev/sdb1.

Tips

  • Always backup important data before using the mkfs command, as it formats the specified partition.

  • Use the -V option for debugging purposes or when you need a detailed output.

Advanced Use Cases of mkfs Command in Linux

  • Creating an ext4 filesystem with a custom block size:
    Output:
    Explanation: This command creates an ext4 filesystem with a block size of 4096 bytes on /dev/sdb1.

Conclusion

  • The mkfs command in Linux is a powerful tool for creating filesystems on devices.

  • It's important to know the device you're formatting to avoid loss of data.

  • There are many filesystem types that mkfs can create, including but not limited to ext4, vfat, and ntfs.