How to use the command 'mkfs' (with examples)
- Linux
- December 25, 2023
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.
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.