Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash mkfs Usage: Create and manage file systems
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[Linux] Bash mkfs Usage: Create and manage file systems

Overview

The mkfs command in Bash is used to create a file system on a specified device or partition. This command is essential for preparing storage devices for use, allowing the operating system to manage files and directories on that device.

Usage

The basic syntax of the mkfs command is as follows:

mkfs [options] [arguments]

Common Options

  • -t, --type: Specify the type of file system to create (e.g., ext4, vfat).
  • -L, --label: Assign a label to the file system.
  • -n, --no-mount: Do not mount the file system after creation.
  • -V, --verbose: Provide detailed output during the execution of the command.

Common Examples

Here are some practical examples of using the mkfs command:

  1. Creating an ext4 file system on a partition:
    mkfs -t ext4 /dev/sdb1
    
  2. Creating a FAT32 file system with a label:
    mkfs -t vfat -L MY_USB /dev/sdc1
    
  3. Creating an ext3 file system without mounting:
    mkfs -t ext3 -n /dev/sda1
    
  4. Verbose output while creating an ext4 file system:
    mkfs -t ext4 -V /dev/sdd1
    

Tips

  • Always ensure that you have backed up any important data before using mkfs, as it will erase existing data on the specified device.
  • Use the -L option to give your file system a recognizable label, making it easier to identify later.
  • Check the device you are formatting with lsblk or fdisk -l to avoid formatting the wrong partition.