Linux mkfs 命令教程:创建文件系统 📁
1. 简介
mkfs
是 "make filesystem" 的缩写,意为“创建文件系统”。它是 Linux 系统中用于在分区上创建文件系统的工具。🔧 mkfs
可以将未格式化的磁盘分区转化为可用的文件系统,支持多种文件系统类型,如 ext4、vfat、ntfs 等。无论你是需要格式化新分区,还是重新格式化现有分区,mkfs
都能帮你实现。
2. 常见操作概览
操作 | 命令格式 | 说明 |
---|---|---|
创建 ext4 文件系统 | sudo mkfs -t ext4 <设备名> | 在指定分区上创建 ext4 文件系统。 |
创建 vfat 文件系统 | sudo mkfs -t vfat <设备名> | 在指定分区上创建 vfat 文件系统。 |
创建 ntfs 文件系统 | sudo mkfs -t ntfs <设备名> | 在指定分区上创建 ntfs 文件系统。 |
显示支持的文件系统 | mkfs -T | 列出 mkfs 支持的所有文件系统类型。 |
显示帮助信息 | mkfs -h | 显示 mkfs 命令的帮助信息。 |
3. 命令示例
3.1 创建 ext4 文件系统
要在 /dev/sda2
上创建 ext4 文件系统:
$ sudo mkfs -t ext4 /dev/sda2
终端输出:
mke2fs 1.45.5 (07-Jan-2023)
Creating filesystem with 244195040 4k blocks and 61054976 inodes
Filesystem UUID: 1f3a7e9d-3c18-492a-983b-9e8b6e1a1b4f
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
这会创建一个新的 ext4 文件系统。📈
3.2 创建 vfat 文件系统
要在 /dev/sda3
上创建 vfat 文件系统:
$ sudo mkfs -t vfat /dev/sda3