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
- Partition formatting
- System setup
- Storage preparation
- Device initialization
- 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
Basic format:
mkfs.ext4 /dev/sdb1
Force format:
mkfs -t ext4 -F /dev/sdc1
Custom options:
mkfs.ext4 -i 4096 /dev/sdd1
Security Considerations
- Data loss risk
- Root access
- Device verification
- Backup importance
- System integrity
Additional Resources
Best Practices
- Verify device
- Backup data
- Check options
- Document changes
- Test mount
Filesystem Features
- Journaling
- Compression
- Snapshots
- Quotas
- ACLs
Troubleshooting
- Device errors
- Bad blocks
- Size issues
- Label conflicts
- Format failures