linux's docs

7.3.0: 磁盘管理-格式化


1、磁盘格式化

1.1 命令:mkfs
作用:创建linux文件系统(格式化分区)
语法:

  • mkfs [-t] 分区
    如无-t,默认为ext2

  • mkfs.xxx 分区
    xxx为格式名称,下图为不同格式的相应命令

用法举例:

# mkfs指定分区格式
mkfs -t ext4 /dev/sdb1
mke2fs 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
328656 inodes, 1313305 blocks
65665 blocks (5.00%) reserved for the super user
# 预留5%的容量给root在磁盘满了的情况下使用
First data block=0
Maximum filesystem blocks=1346371584
41 block groups
32768 blocks per group, 32768 fragments per group
8016 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

# 使用mkfs.xxx方式格式化磁盘
# 查看所有mkfs命令,在输入"mkfs."后连续按下两次tab键
mkfs.[tab][tab]                
mkfs.cramfs   mkfs.ext3     mkfs.ext4dev
mkfs.ext2     mkfs.ext4     mkfs.xfs

# 格式化sdb2为ext4格式
mkfs.ext4 /dev/sdb2
mke2fs 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
66384 inodes, 265072 blocks
13253 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

# 格式化sdb3为xfs格式
mkfs.xfs /dev/sdb3
meta-data=/dev/sdb3              isize=256    agcount=4, agsize=66268 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=265072, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

1.2 mke2fs
作用:创建ext2、ext3或ext4文件系统
语法:mke2fs [参数] 分区 参数:

  • -i 定义多少磁盘空间给予分配一个inode,数值越大,inode数目越少。此选项多用于应对小文件比较多的情况
  • -m 保留磁盘空间的百分比,给superuser用的,用于应对磁盘空间有可能满的情况
  • -t type 格式(只能跟ext2、ext3、ext4)
  • -L lable制定分区标签名,标签名可用于挂载分区用
  • -b "block-size"目前有效值为1024、2048或4096bytes

用法举例:

mke2fs -t ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
......
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

mke2fs -m 5 -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
......
13253 blocks (5.00%) reserved for the super user
......
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.PS:
# mke2fs有许多设定,必要时请man查询,来根据实际情况调用

Contents