How to use the command 'mkfs' (with examples)

How to use the command 'mkfs' (with examples)

The ‘mkfs’ command is used to build a Linux filesystem on a hard disk partition. It is a deprecated command and it is recommended to use filesystem-specific ‘mkfs.’ utilities instead. The ‘mkfs’ command supports creating different types of filesystems such as ext2, ext3, ext4, NTFS, etc.

Use case 1: Build a Linux ext2 filesystem on a partition

Code:

mkfs path/to/partition

Motivation: The motivation to use this example is to create a Linux ext2 filesystem on a specific partition. This can be useful when setting up a new disk or preparing a partition for a specific purpose, such as data storage.

Explanation:

  • ‘mkfs’: The command to build a Linux filesystem.
  • ‘path/to/partition’: The path to the partition on which the filesystem should be built.

Example output:

mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 65536 4k blocks and 16384 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks: 
...
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

Use case 2: Build a filesystem of a specified type

Code:

mkfs -t ext4 path/to/partition

Motivation: The motivation to use this example is to create a specific type of filesystem, in this case, ext4, on a specified partition. This can be useful when the desired filesystem type needs to be explicitly stated.

Explanation:

  • ‘mkfs’: The command to build a Linux filesystem.
  • ‘-t ext4’: Specifies the type of filesystem to be created as ext4.
  • ‘path/to/partition’: The path to the partition on which the filesystem should be built.

Example output:

mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 65536 4k blocks and 16384 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks: 
...
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

Use case 3: Build a filesystem of a specified type and check for bad blocks

Code:

mkfs -c -t ntfs path/to/partition

Motivation: The motivation to use this example is to create a specific type of filesystem, in this case, ntfs, on a specified partition while also checking for bad blocks. This can be useful when ensuring the quality and reliability of the filesystem.

Explanation:

  • ‘mkfs’: The command to build a Linux filesystem.
  • ‘-c’: Checks for bad blocks on the partition during the filesystem creation process.
  • ‘-t ntfs’: Specifies the type of filesystem to be created as ntfs.
  • ‘path/to/partition’: The path to the partition on which the filesystem should be built.

Example output:

Creating NTFS volume structures.
Format completed.

Conclusion:

The ‘mkfs’ command provides a way to build Linux filesystems on hard disk partitions. It supports creating different types of filesystems and allows for additional options such as checking for bad blocks. While deprecated, it can still be used for certain use cases where the filesystem-specific ‘mkfs.’ utilities are not available or necessary.

Tags :

Related Posts

How to use the command 'nohup' (with examples)

How to use the command 'nohup' (with examples)

The ’nohup’ command allows you to run a process that will continue to run even if the terminal is closed or the session is ended.

Read More
Using the `az storage blob` command (with examples)

Using the `az storage blob` command (with examples)

Download a blob to a file path az storage blob download --account-name storage_account_name --account-key storage_account_key -c container_name -n path/to/blob -f path/to/local_file Motivation: This command allows you to download a blob from a storage container to a local file path.

Read More
How to use the command 'unimatrix' (with examples)

How to use the command 'unimatrix' (with examples)

The ‘unimatrix’ command allows you to simulate the Matrix look with Unicode characters.

Read More