在/etc/filesystems的文件里面可以看到支持的文件系统 centos 7默认的是xfs的文件系统 在刚开始装系统格式化的时候就是xfs的格式 centos 6之前的默认的是ext的文件系统 命令: mke2fs -t ext4 /dev/sdb3 === mkfs.ext4 /dev/sdb3 这种格式不支持xfs的格式 mkfs.xfs /dev/sdb3 不分区直接格式化也是可以的

[root@kylin ~]# cat /etc/filesystems xfs ext4 ext3 ext2 nodev proc nodev devpts iso9660 vfat hfs hfsplus

用mount可以看到sda的文件系统 [root@kylin ~]# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel) . . . (rw,nosuid,nodev,noexec,relatime,memory) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) configfs on /sys/kernel/config type configfs (rw,relatime) /dev/sda3 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota) selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=26,pgrp=1,timeout=300,minproto=5,maxproto=5,direct) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel) debugfs on /sys/kernel/debug type debugfs (rw,relatime) mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel) /dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota) tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=99996k,mode=700)

虽然说默认的是xfs的格式,但是也是可以格式化成ext的文件格式 格式化的命令 mke2fs -t xfs -b 2048 -t:是指定文件格式 -b:是指定块的大小

块的默认大小是4K,如果一个文件不足4K 也是会占用一个块(4K)

这个命令是不支持xfs的文件系统的 [root@kylin ~]# mke2fs -t xfs -b 2048 /dev/sdb3 mke2fs 1.42.9 (28-Dec-2013)

Your mke2fs.conf file does not define the xfs filesystem type. Aborting...

mkfs.ext4 ===mke2fs -t ext4

这两条命令是一样的 [root@kylin ~]# mke2fs -t ext4 /dev/sdb3 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376

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

[root@kylin ~]# mkfs.ext4 /dev/sdb3 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376

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

格式化成xfs格式的时候报错,需要加一个-f选项 [root@kylin ~]# mkfs.xfs /dev/sdb3 mkfs.xfs: /dev/sdb3 appears to contain an existing filesystem (ext4). mkfs.xfs: Use the -f option to force overwrite. [root@kylin ~]# mkfs.xfs -f /dev/sdb3 meta-data=/dev/sdb3 isize=512 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 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 [root@kylin ~]#

刚格式化玩用mount是看不到文件系统的,需用挂载才能看到,如果不挂载也是可以看到的 blkid /dev/sdb3 这个命令也是可以看到刚才的文件系统的 [root@kylin ~]# blkid /dev/sdb3 /dev/sdb3: UUID="fca5f753-b2f1-4957-a51f-1c851be3a25f" TYPE="xfs"

可以改块的大小,这边提示有点大,如果是需要放视频音乐的这种大文件的,可以改成比较大的分区 [root@kylin ~]# mke2fs -b 8192 /dev/sdb3 Warning: blocksize 8192 not usable on most systems. mke2fs 1.42.9 (28-Dec-2013) mke2fs: 8192-byte blocks too big for system (max 4096) Proceed anyway? (y,n) n

一般都是一些小的文件,可以改成2048,一般保持默认就可以了 [root@kylin ~]# mke2fs -b 2048 /dev/sdb3 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 524288 blocks 26214 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 32 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

在上面有一个5%的空间是预留的,预留个root用户的比较浪费空间,改小一点,磁盘最大化使用 可以使用-m参数改成0.1 [root@kylin ~]# mke2fs -m 0.1 /dev/sdb3

默认的文件类型是ext2,太老了,可以指定一下 [root@kylin ~]# blkid /dev/sdb3 /dev/sdb3: UUID="e51a1468-12b6-40f1-a2dc-11fca44e4208" TYPE="ext2"

mkfs.xfs 是不支持这些参数的 [root@kylin ~]# mkfs.xfs -m 0.1 /dev/sdb3

[root@kylin ~]# mkfs.ext4 -m 0.1 /dev/sdb3 这两个命令的参数是一样的,都是可以用的 [root@kylin ~]# mke2fs -t ext4 -b 8192 /dev/sdb3

-i的参数是改变inode的大小 [root@kylin ~]# mke2fs -i 8192 -t ext4 /dev/sdb3 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376

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