CentOS 7磁盤格式化


查看CentOS 7支持的文件系統格式

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

mount查看分區的文件系統格式

[root@centos-01 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=490008k,nr_inodes=122502,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
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=0,minproto=5,maxproto=5,direct,pipe_ino=12742)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
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=99972k,mode=700)

可以發現,“/”根目錄、“/boot”目錄都是xfs格式(CentOS 7默認文件系統格式是xfs)。在CentOS 6以及之前的版本,使用的是ext文件系統格式,CentOS 6是ext4格式、CentOS 5是ext3格式。


創建分區

[root@centos-01 ~]# fdisk -l

磁盤 /dev/sda:32.2 GB, 32212254720 字節,62914560 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000d9f36

   設備 Boot      Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris /dev/sda3 4605952 62914559 29154304 83 Linux 磁盤 /dev/sdb:10.7 GB, 10737418240 字節,20971520 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標簽類型:dos 磁盤標識符:0x59b95324 設備 Boot Start End Blocks Id System [root@centos-01 ~]# fdisk /dev/sdb 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 命令(輸入 m 獲取幫助):n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p 分區號 (1-4,默認 1): 起始 扇區 (2048-20971519,默認為 2048): 將使用默認值 2048 Last 扇區, +扇區 or +size{K,M,G} (2048-20971519,默認為 20971519):+3G 分區 1 已設置為 Linux 類型,大小設為 3 GiB 命令(輸入 m 獲取幫助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盤。 [root@centos-01 ~]# fdisk -l 磁盤 /dev/sda:32.2 GB, 32212254720 字節,62914560 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標簽類型:dos 磁盤標識符:0x000d9f36 設備 Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris /dev/sda3 4605952 62914559 29154304 83 Linux 磁盤 /dev/sdb:10.7 GB, 10737418240 字節,20971520 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標簽類型:dos 磁盤標識符:0x59b95324 設備 Boot Start End Blocks Id System /dev/sdb1 2048 6293503 3145728 83 Linux 

格式化

mkfs.ext4等價於mke2fs -t ext4

[root@centos-01 ~]# mke2fs -t ext4 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
第一個數據塊=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, 294912

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

這里換種方式再次格式化。分區即使格式化過一次,還可以再次格式化。

[root@centos-01 ~]# mkfs.ext4 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
第一個數據塊=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, 294912

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 
  • mke2fs無法格式化成xfs格式
[root@centos-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...
  • mkfs.xfs可以格式化成xfs格式,不過因為分區之前已經格式化過,需要用‘-f’選項再次格式化。
[root@centos-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.
[root@centos-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
  • 查看還沒有掛載分區的格式(/dev/sdb1還未掛載)
[root@centos-01 ~]# blkid /dev/sdb1 
/dev/sdb1: UUID="b6615809-31bf-4a30-8a9c-6550bd8f9d1f" TYPE="xfs"

mke2fs命令

  • ‘-t’:指定文件系統類型
  • ‘-b’:指定區塊大小,單位為字節
[root@centos-01 ~]# mke2fs -b 8192 /dev/sdb1 
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)
無論如何也要繼續? (y,n) n
[root@centos-01 ~]# mke2fs -b 2048 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=2048 (log=1)
分塊大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=538968064
96 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, 802816, 1327104

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Writing superblocks and filesystem accounting information: 完成 
  • ‘-m’:指定分區預留大小。預設為5%。
[root@centos-01 ~]# mke2fs -m 1 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
7864 blocks (1.00%) reserved for the super user
第一個數據塊=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, 294912

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Writing superblocks and filesystem accounting information: 完成 
[root@centos-01 ~]# mke2fs -m 0.1 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
786 blocks (0.10%) reserved for the super user
第一個數據塊=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, 294912

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Writing superblocks and filesystem accounting information: 完成 
  • 前面的命令沒有指定文件系統類型,用blkid命令查看前面命令執行后格式化的類型。
[root@centos-01 ~]# blkid /dev/sdb1 
/dev/sdb1: UUID="2b56d897-2b84-4628-aafa-319e1812210c" TYPE="ext2"

如果不指定文件系統類型,就是ext2格式。

[root@centos-01 ~]# mke2fs -t ext4 -m 0.1 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
786 blocks (0.10%) reserved for the super user
第一個數據塊=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, 294912

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

[root@centos-01 ~]# mkfs.ext4 -m 0.1 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
786 blocks (0.10%) reserved for the super user
第一個數據塊=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, 294912

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 
  • ‘-i<字節>’:指定”字節/inode”的比例。默認是4個塊(block)對應一個inode,也就是4*4K=16K=16384Byte / 1 inode。
[root@centos-01 ~]# mke2fs -i 8192 -t ext4 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
文件系統標簽=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
393216 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM