mkfs

Overview

The mkfs command builds a Linux filesystem on a device, usually a hard disk partition. It’s a frontend for filesystem-specific commands like mkfs.ext4, mkfs.xfs, etc.

Syntax

mkfs [-t fstype] [options] device

Common Options

Option Description
-t type Filesystem type
-V Verbose output
-h Display help
-v Version info
-c Check for bad blocks
-i size Bytes per inode
-L label Set volume label
-n Dry run
-q Quiet execution
-F Force creation

Filesystem Types

Type Description
ext4 Extended filesystem 4
xfs XFS filesystem
btrfs B-tree filesystem
vfat FAT filesystem
ntfs NTFS filesystem
exfat Extended FAT
f2fs Flash-Friendly FS

Key Use Cases

  1. Partition formatting
  2. System setup
  3. Storage preparation
  4. Device initialization
  5. Recovery operations

Examples with Explanations

Example 1: Create ext4

mkfs -t ext4 /dev/sdb1

Format as ext4

Example 2: Create with Label

mkfs.ext4 -L "DATA" /dev/sdc1

Format and label

Example 3: Check Blocks

mkfs -t ext4 -c /dev/sdd1

Check blocks while formatting

Common Usage Patterns

  1. Basic format:

    mkfs.ext4 /dev/sdb1
  2. Force format:

    mkfs -t ext4 -F /dev/sdc1
  3. Custom options:

    mkfs.ext4 -i 4096 /dev/sdd1

Security Considerations

  1. Data loss risk
  2. Root access
  3. Device verification
  4. Backup importance
  5. System integrity

Additional Resources

Best Practices

  1. Verify device
  2. Backup data
  3. Check options
  4. Document changes
  5. Test mount

Filesystem Features

  1. Journaling
  2. Compression
  3. Snapshots
  4. Quotas
  5. ACLs

Troubleshooting

  1. Device errors
  2. Bad blocks
  3. Size issues
  4. Label conflicts
  5. Format failures