本文主要是介绍4.5-磁盘格式化(上),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
磁盘虽然分好区了,但是还不能用,我们还需要在这每个分区上格式化。所谓格式化,其实就是安装文件系统,Windows下的文件系统有 Fat32、NTFS,CentOS使用的文件系统为 ext。之前CentOS版本使用ext3作为默认的文件系统,而CentOS6使用ext4作为默认的文件系统
CentOS7 支持的文件系统格式
[root@evan-01 ~]# cat /etc/filesystems
xfs
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*
[root@evan-01 ~]#
xfs 是CentOS7 默认的文件系统
查看分区的文件系统
/ 和 /boot 都是xfs
[root@evan-01 ~]# mount
格式化分区前的准备
查看分区
[root@evan-01 ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c973aDevice Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVMDisk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes[root@evan-01 ~]#
创建分区
n创建新分区,p选择主分区,回车(默认分区号1),回车(默认磁盘扇区从2048开始),+3G(设置分区大小为3G),p(查看分区)发现已经有了1个主分区了,w保存退出
[root@evan-01 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6e55b372.Command (m for help): n
Partition type:p primary (0 primary, 0 extended, 4 free)e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +3G
Partition 1 of type Linux and of size 3 GiB is setCommand (m for help): pDisk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6e55b372Device Boot Start End Blocks Id System
/dev/sdb1 2048 6293503 3145728 83 LinuxCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
[root@evan-01 ~]#
格式化分区
命令:mke2fs、mkfs.ext2、mkfs.ext3 和 mkfs.ext4
-t 指定格式化成什么类型的文件系统,可以是 ext2、ext3也可以是ext4 、xfs
-b 分区时设定每个数据区块占用空间大小,目前支持 1024 、2048 以及 4096 Bytes
mkfs.ext4 === mke2fs -t ext4
[root@evan-01 ~]# mke2fs -t ext4 /dev/sdb1
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
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done [root@evan-01 ~]#
[root@evan-01 ~]# mkfs.ext4 /dev/sdb1
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
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done [root@evan-01 ~]#
mke2fs 不支持 xfs,换种写法 mkfs.xfs /dev/sdb1
[root@evan-01 ~]# mke2fs -t xfs /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)Your mke2fs.conf file does not define the xfs filesystem type.
Aborting...
[root@evan-01 ~]# mkfs.xfs /dev/sdb1
mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.
因为 sdb1分区已经有文件系统了,所以需要使用 -f 强制覆盖下
[root@evan-01 ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=196608 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=786432, 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@evan-01 ~]#
查看没有挂载的格式化后的分区
[root@evan-01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="c6329596-b26c-45dd-88ea-c7b5ba77cf95" TYPE="xfs"
[root@evan-01 ~]#
这篇关于4.5-磁盘格式化(上)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!