Linux系统使用 mkfs.ext4 格式化磁盘分区
1.安装格式化工具
- 大多数系统默认已经安装相关的软件工具。
2.修改分区表
- 可以使用
fdisk
或parted
来修改分区表。
3.格式化磁盘
-
格式化指定分区:
mkfs.ext4 /dev/vdb1
-
格式化完成后进行优化配置:
tune2fs -c -1 /dev/vdb1
4.挂载磁盘分区
-
临时挂载:
mkdir -p /data mount /dev/vdb1 /data df -h
-
永久挂载:
vim /etc/fstab # 添加以下内容 ------ /dev/vdb1 /data ext4 defaults 0 0 ------ # 检查并挂载磁盘 mount -a df -h
5.实例演示
-
格式化指定分区:
[root@zuiyoujie ~]# mkfs.ext4 /dev/vdb1 e2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 32768000 inodes, 131071870 blocks 6553593 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 4000 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
-
优化配置:
[root@zuiyoujie ~]# tune2fs -c -1 /dev/vdb1 tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to -1
-
挂载分区到指定目录:
[root@zuiyoujie ~]# mkdir -p /data [root@zuiyoujie ~]# mount /dev/vdb1 /data [root@zuiyoujie ~]# vim /etc/fstab # 添加以下内容 /dev/vdb1 /data ext4 defaults 0 0