其他分享
首页 > 其他分享> > 32.第九章 磁盘存储和文件系统管理(二)

32.第九章 磁盘存储和文件系统管理(二)

作者:互联网

2.1.3 管理分区

列出块设备

lsblk

创建分区命令

fdisk 管理MBR分区
gdisk 管理GPT分区
parted 高级分区操作,可以是交互或非交互方式

重新设置内存中的内核分区表版本,适合于除了CentOS 6 以外的其它版本 5,7,8

partprobe

2.1.3.1 parted

注意:parted的操作都是实时生效的,小心使用
格式:

parted [选项]... [设备 [命令 [参数]...]...]

f范例:

[root@rocky8 ~]# alias scandisk
alias scandisk='echo '\''- - -'\'' > /sys/class/scsi_host/host0/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host1/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host2/scan'

[root@rocky8 ~]# scandisk
[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

[root@rocky8 ~]# hexdump -C -n 512 -v /dev/sdb
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000200
#磁盘上没有分区信息

[root@rocky8 ~]# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help  #查看帮助                                                             
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular
        partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) mklabel msdos #设置成MBR分区                                                    
(parted) quit #退出                                                             
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# hexdump -C -n 512 -v /dev/sdb                            
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  41 3b 8f 95 00 00 00 00  |........A;......|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
#现在已经有分区信息了,41 3b 8f 95

[root@rocky8 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags
#print  打印分区

[root@rocky8 ~]# parted /dev/sdb mkpart primary 1 200
Information: You may need to update /etc/fstab.
#分区

[root@rocky8 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  200MB  199MB  primary

[root@rocky8 ~]# hexdump -C -n 512 -v /dev/sdb
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  41 3b 8f 95 00 00 00 04  |........A;......|
000001c0  01 04 83 fd 82 fe 00 08  00 00 00 f0 05 00 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
#00 04 000001c0  01 04 83 fd 82 fe 00 08  00 00 00 f0 05 00 这就是分区表信息

[root@rocky8 ~]# parted /dev/sdb mkpart primary 201 500
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# parted /dev/sdb print                   
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  200MB  199MB  primary
 2      201MB   500MB  299MB  primary

[root@rocky8 ~]# hexdump -C -n 512 -v /dev/sdb
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  41 3b 8f 95 00 00 00 04  |........A;......|
000001c0  01 04 83 fd 82 fe 00 08  00 00 00 f0 05 00 00 03  |................|
000001d0  c1 03 83 fe c2 ff 00 00  06 00 00 e8 08 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
#00 03 000001d0  c1 03 83 fe c2 ff 00 00  06 00 00 e8 08 00 这是第二个分区信息

[root@rocky8 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  200MB  199MB  primary
 2      201MB   500MB  299MB  primary

[root@rocky8 ~]# parted /dev/sdb rm 1
Information: You may need to update /etc/fstab.
#删除分区

[root@rocky8 ~]# parted /dev/sdb print                                    
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 2      201MB  500MB  299MB  primary
#现在已经没有第一个分区了

[root@rocky8 ~]# hexdump -C -n 512 -v /dev/sdb
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000190  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  41 3b 8f 95 00 00 00 00  |........A;......|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 03  |................|
000001d0  c1 03 83 fe c2 ff 00 00  06 00 00 e8 08 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
#第一个分区表就空了

[root@rocky8 ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  1075MB  1074MB  primary   xfs             boot
 2      1075MB  108GB   107GB   primary   xfs
 3      108GB   162GB   53.7GB  primary   xfs
 4      162GB   215GB   52.6GB  extended
 5      162GB   164GB   2147MB  logical   linux-swap(v1)


Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 2      201MB  500MB  299MB  primary


Error: /dev/nvme0n1: unrecognised disk label
Model: NVMe Device (nvme)                                                 
Disk /dev/nvme0n1: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0
has been opened read-only.
Model: NECVMWar VMware IDE CDR10 (scsi)                                   
Disk /dev/sr0: 9908MB
Sector size (logical/physical): 2048B/2048B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 2      48.1MB  88.2MB  40.1MB  primary               esp
 
[root@rocky8 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 2      201MB  500MB  299MB  primary

[root@rocky8 ~]# parted /dev/sdb rm 2
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# parted /dev/sdb print                                    
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags

范例:

[root@centos8 ~]#parted /dev/sdb print
Error: /dev/sdb: unrecognised disk label
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

[root@rocky8 ~]# parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# parted /dev/sdb print                              
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  Flags

[root@rocky8 ~]# parted /dev/sdb mkpart primary 1 1001
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1001MB  1000MB               primary

[root@rocky8 ~]# parted /dev/sdb mkpart primary 1002 1102
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1001MB  1000MB               primary
 2      1002MB  1102MB  99.6MB               primary

[root@rocky8 ~]# parted /dev/sdb rm 2
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# parted /dev/sdb print                                    
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1001MB  1000MB               primary

[root@rocky8 ~]# parted /dev/sdb mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
Information: You may need to update /etc/fstab.

[root@rocky8 ~]# parted /dev/sdb print                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags

[root@rocky8 ~]# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                                             
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular
        partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) 

2.1.3.2 fdisk和gdisk

fdisk -l [-u] [device...] 查看分区
fdisk [device...] 管理MBR分区
gdisk [device...] 类fdisk 的GPT分区工具

子命令:

p 分区列表
t 更改分区类型
n 创建新分区
d 删除分区
v 校验分区
u 转换单位
w 保存并退出
q 不保存并退出

查看内核是否已经识别新的分区

cat /proc/partations

Centos6 通知内核重新读取硬盘分区表

新增分区用

partx -a /dev/DEVICE
kpartx -a /dev/DEVICE -f: force

#示例:
[root@centos6 ~]#partx -a /dev/sda

删除分区用

partx -d --nr M-N /dev/DEVICE

#示例:
[root@centos6 ~]#partx -d --nr 6-8 /dev/sda

范例:非交互式创建分区

echo -e 'n\np\n\n\n+2G\nw\n' | fdisk /dev/sdc

范例:

[root@rocky8 ~]# dnf -y install gdisk

[root@rocky8 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

[root@rocky8 ~]# fdisk  /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m #帮助

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): p #查看分区情况
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Command (m for help): n #新建分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): e #扩展分区
Partition number (1-4, default 1): 2 #第二个分区
First sector (2048-41943039, default 2048): 1 #不能从1开始,2048前都预留了
Value out of range.
First sector (2048-41943039, default 2048):   #默认从2048开始
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +10G

Created a new partition 2 of type 'Extended' and of size 10 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb2        2048 20973567 20971520  10G  5 Extended

Command (m for help): n
Partition type
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): p #主分区
Partition number (1,3,4, default 1): 1
First sector (20973568-41943039, default 20973568): 
Last sector, +sectors or +size{K,M,G,T,P} (20973568-41943039, default 41943039): +1G

Created a new partition 1 of type 'Linux' and of size 1 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended

Partition table entries are not in disk order.

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l #逻辑分区

Adding logical partition 5
First sector (4096-20973567, default 4096): 
Last sector, +sectors or +size{K,M,G,T,P} (4096-20973567, default 20973567): +2G

Created a new partition 5 of type 'Linux' and of size 2 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5           4096  4198399  4194304   2G 83 Linux

Partition table entries are not in disk order.

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 6
First sector (4200448-20973567, default 4200448): 
Last sector, +sectors or +size{K,M,G,T,P} (4200448-20973567, default 20973567): +1G

Created a new partition 6 of type 'Linux' and of size 1 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5           4096  4198399  4194304   2G 83 Linux
/dev/sdb6        4200448  6297599  2097152   1G 83 Linux

Partition table entries are not in disk order.

Command (m for help): w #保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    1K  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    1G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

[root@rocky8 ~]# fdisk  /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5           4096  4198399  4194304   2G 83 Linux
/dev/sdb6        4200448  6297599  2097152   1G 83 Linux

Partition table entries are not in disk order.

Command (m for help): d
Partition number (1,2,5,6, default 6): 5

Partition 5 has been deleted.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5        4200448  6297599  2097152   1G 83 Linux

Partition table entries are not in disk order.

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 6
First sector (4096-20973567, default 4096): 
Last sector, +sectors or +size{K,M,G,T,P} (4096-4200447, default 4200447): +5G
Value out of range. #提示超出范围,因为前面分的2G,从4096开始,连续空间不足5G,不能分。
Last sector, +sectors or +size{K,M,G,T,P} (4096-4200447, default 4200447): 

Created a new partition 6 of type 'Linux' and of size 2 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5        4200448  6297599  2097152   1G 83 Linux
/dev/sdb6           4096  4200447  4196352   2G 83 Linux

Partition table entries are not in disk order.

Command (m for help): d
Partition number (1,2,5,6, default 6): 6

Partition 6 has been deleted.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5        4200448  6297599  2097152   1G 83 Linux

Partition table entries are not in disk order.

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 6
First sector (4096-20973567, default 4096): 6297600

Sector 6297600 is already allocated. #从6297600开始,提示已经被使用,系统默认让从6299648开始分。
First sector (6299648-20973567, default 6299648): 
Last sector, +sectors or +size{K,M,G,T,P} (6299648-20973567, default 20973567): +5G

Created a new partition 6 of type 'Linux' and of size 5 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5        4200448  6297599  2097152   1G 83 Linux
/dev/sdb6        6299648 16785407 10485760   5G 83 Linux

Partition table entries are not in disk order.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    1K  0 part 
├─sdb5    8:21   0    1G  0 part 
└─sdb6    8:22   0    5G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk
#上面是为了做实验,理解分区,生产中这样分是不合理的

[root@rocky8 ~]# fdisk  /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1       20973568 23070719  2097152   1G 83 Linux
/dev/sdb2           2048 20973567 20971520  10G  5 Extended
/dev/sdb5        4200448  6297599  2097152   1G 83 Linux
/dev/sdb6        6299648 16785407 10485760   5G 83 Linux

Partition table entries are not in disk order.

Command (m for help): d
Partition number (1,2,5,6, default 6): 1

Partition 1 has been deleted.

Command (m for help): d
Partition number (2,5,6, default 6): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +1G

Created a new partition 1 of type 'Linux' and of size 1 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 2099199 2097152   1G 83 Linux

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 
First sector (2099200-41943039, default 2099200): 
Last sector, +sectors or +size{K,M,G,T,P} (2099200-41943039, default 41943039): +2G

Created a new partition 2 of type 'Linux' and of size 2 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot   Start     End Sectors Size Id Type
/dev/sdb1          2048 2099199 2097152   1G 83 Linux
/dev/sdb2       2099200 6293503 4194304   2G 83 Linux

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (3,4, default 3): 
First sector (6293504-41943039, default 6293504): 
Last sector, +sectors or +size{K,M,G,T,P} (6293504-41943039, default 41943039): 

Created a new partition 3 of type 'Extended' and of size 17 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot   Start      End  Sectors Size Id Type
/dev/sdb1          2048  2099199  2097152   1G 83 Linux
/dev/sdb2       2099200  6293503  4194304   2G 83 Linux
/dev/sdb3       6293504 41943039 35649536  17G  5 Extended

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (6295552-41943039, default 6295552): 
Last sector, +sectors or +size{K,M,G,T,P} (6295552-41943039, default 41943039): +2G

Created a new partition 5 of type 'Linux' and of size 2 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot   Start      End  Sectors Size Id Type
/dev/sdb1          2048  2099199  2097152   1G 83 Linux
/dev/sdb2       2099200  6293503  4194304   2G 83 Linux
/dev/sdb3       6293504 41943039 35649536  17G  5 Extended
/dev/sdb5       6295552 10489855  4194304   2G 83 Linux

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 6
First sector (10491904-41943039, default 10491904): 
Last sector, +sectors or +size{K,M,G,T,P} (10491904-41943039, default 41943039): +3G

Created a new partition 6 of type 'Linux' and of size 3 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048  2099199  2097152   1G 83 Linux
/dev/sdb2        2099200  6293503  4194304   2G 83 Linux
/dev/sdb3        6293504 41943039 35649536  17G  5 Extended
/dev/sdb5        6295552 10489855  4194304   2G 83 Linux
/dev/sdb6       10491904 16783359  6291456   3G 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    2G  0 part 
├─sdb3    8:19   0    1K  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    3G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

范例:

[root@rocky8 ~]# scandisk
[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    2G  0 part 
├─sdb3    8:19   0    1K  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    3G  0 part 
sdc       8:32   0   10G  0 disk 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

[root@rocky8 ~]# gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): ? #帮助
b	back up GPT data to a file
c	change a partition's name
d	delete a partition
i	show detailed information on a partition
l	list known partition types
n	add a new partition
o	create a new empty GUID partition table (GPT)
p	print the partition table
q	quit without saving changes
r	recovery and transformation options (experts only)
s	sort partitions
t	change a partition's type code
v	verify disk
w	write table to disk and exit
x	extra functionality (experts only)
?	print this menu

Command (? for help): p #查看分区情况
Disk /dev/sdc: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EF723019-30A5-4A81-A156-D60F9E3DCC84
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 20971453 sectors (10.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): n #创建新分区
Partition number (1-128, default 1): #分区编号
First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: 	#开始从2048分
Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +1G #分1G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):  #分区类型
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdc: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EF723019-30A5-4A81-A156-D60F9E3DCC84
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 18874301 sectors (9.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem

Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-20971486, default = 2099200) or {+-}size{KMGTP}: 
Last sector (2099200-20971486, default = 20971486) or {+-}size{KMGTP}: +2G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdc: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EF723019-30A5-4A81-A156-D60F9E3DCC84
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 14679997 sectors (7.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         6293503   2.0 GiB     8300  Linux filesystem

Command (? for help): n
Partition number (3-128, default 3): 
First sector (34-20971486, default = 6293504) or {+-}size{KMGTP}: 
Last sector (6293504-20971486, default = 20971486) or {+-}size{KMGTP}: +1G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdc: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EF723019-30A5-4A81-A156-D60F9E3DCC84
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 12582845 sectors (6.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         6293503   2.0 GiB     8300  Linux filesystem
   3         6293504         8390655   1024.0 MiB  8300  Linux filesystem

Command (? for help): d #删除分区
Partition number (1-3): 3

Command (? for help): p
Disk /dev/sdc: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EF723019-30A5-4A81-A156-D60F9E3DCC84
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 14679997 sectors (7.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         6293503   2.0 GiB     8300  Linux filesystem

Command (? for help): w #保存退出

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y  #是否确定
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    2G  0 part 
├─sdb3    8:19   0    1K  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    3G  0 part 
sdc       8:32   0   10G  0 disk 
├─sdc1    8:33   0    1G  0 part 
└─sdc2    8:34   0    2G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

范例:

[root@rocky8 ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048  2099199  2097152   1G 83 Linux
/dev/sdb2        2099200  6293503  4194304   2G 83 Linux
/dev/sdb3        6293504 41943039 35649536  17G  5 Extended
/dev/sdb5        6295552 10489855  4194304   2G 83 Linux
/dev/sdb6       10491904 16783359  6291456   3G 83 Linux

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): t #更改分区类型
Partition number (1-3,5,6, default 6): 6
Hex code (type L to list all codes): L #查看分区类型ID

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT            
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor      
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary  
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS    
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE 
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep        
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT            
Hex code (type L to list all codes): 8e #更改成8e ,LVM逻辑卷

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048  2099199  2097152   1G 83 Linux
/dev/sdb2        2099200  6293503  4194304   2G 83 Linux
/dev/sdb3        6293504 41943039 35649536  17G  5 Extended
/dev/sdb5        6295552 10489855  4194304   2G 83 Linux
/dev/sdb6       10491904 16783359  6291456   3G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

范例:

[root@rocky8 ~]# gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdc: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EF723019-30A5-4A81-A156-D60F9E3DCC84
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 14679997 sectors (7.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         6293503   2.0 GiB     8300  Linux filesystem

Command (? for help): ?
b	back up GPT data to a file
c	change a partition's name
d	delete a partition
i	show detailed information on a partition
l	list known partition types
n	add a new partition
o	create a new empty GUID partition table (GPT)
p	print the partition table
q	quit without saving changes
r	recovery and transformation options (experts only)
s	sort partitions
t	change a partition's type code
v	verify disk
w	write table to disk and exit
x	extra functionality (experts only)
?	print this menu

Command (? for help): t #更改磁盘类型id
Partition number (1-2): 2
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
3000 ONIE boot             3001 ONIE config           3900 Plan 9              
4100 PowerPC PReP boot     4200 Windows LDM data      4201 Windows LDM metadata
4202 Windows Storage Spac  7501 IBM GPFS              7f00 ChromeOS kernel     
7f01 ChromeOS root         7f02 ChromeOS reserved     8200 Linux swap          
8300 Linux filesystem      8301 Linux reserved        8302 Linux /home         
8303 Linux x86 root (/)    8304 Linux x86-64 root (/  8305 Linux ARM64 root (/)
8306 Linux /srv            8307 Linux ARM32 root (/)  8400 Intel Rapid Start   
8e00 Linux LVM             a000 Android bootloader    a001 Android bootloader 2
a002 Android boot          a003 Android recovery      a004 Android misc        
a005 Android metadata      a006 Android system        a007 Android cache       
a008 Android data          a009 Android persistent    a00a Android factory     
a00b Android fastboot/ter  a00c Android OEM           a500 FreeBSD disklabel   
a501 FreeBSD boot          a502 FreeBSD swap          a503 FreeBSD UFS         
a504 FreeBSD ZFS           a505 FreeBSD Vinum/RAID    a580 Midnight BSD data   
a581 Midnight BSD boot     a582 Midnight BSD swap     a583 Midnight BSD UFS    
a584 Midnight BSD ZFS      a585 Midnight BSD Vinum    a600 OpenBSD disklabel   
a800 Apple UFS             a901 NetBSD swap           a902 NetBSD FFS          
a903 NetBSD LFS            a904 NetBSD concatenated   a905 NetBSD encrypted    
a906 NetBSD RAID           ab00 Recovery HD           af00 Apple HFS/HFS+      
af01 Apple RAID            af02 Apple RAID offline    af03 Apple label         
Press the <Enter> key to see more codes: 8e00
af04 AppleTV recovery      af05 Apple Core Storage    af06 Apple SoftRAID Statu
af07 Apple SoftRAID Scrat  af08 Apple SoftRAID Volum  af09 Apple SoftRAID Cache
b300 QNX6 Power-Safe       bc00 Acronis Secure Zone   be00 Solaris boot        
bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap        
bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home       
bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2  
bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5  
c001 HP-UX data            c002 HP-UX service         e100 ONIE boot           
e101 ONIE config           ea00 Freedesktop $BOOT     eb00 Haiku BFS           
ed00 Sony system partitio  ed01 Lenovo system partit  ef00 EFI System          
ef01 MBR partition scheme  ef02 BIOS boot partition   f800 Ceph OSD            
f801 Ceph dm-crypt OSD     f802 Ceph journal          f803 Ceph dm-crypt journa
f804 Ceph disk in creatio  f805 Ceph dm-crypt disk i  fb00 VMWare VMFS         
fb01 VMWare reserved       fc00 VMWare kcore crash p  fd00 Linux RAID          
Hex code or GUID (L to show codes, Enter = 8300): 8e00 #8e00 是LVM
Changed type of partition to 'Linux LVM'

Command (? for help): p
Disk /dev/sdc: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): EF723019-30A5-4A81-A156-D60F9E3DCC84
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 14679997 sectors (7.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         6293503   2.0 GiB     8E00  Linux LVM

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    2G  0 part 
├─sdb3    8:19   0    1K  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    3G  0 part 
sdc       8:32   0   10G  0 disk 
├─sdc1    8:33   0    1G  0 part 
└─sdc2    8:34   0    2G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 
#如果分完区,没有看到,就是内存分区表没有同步

[root@rocky8 ~]# partprobe
#用这个命令同步一下

Centos 6 同步
添加分区用  partx -a /dev/sdb
删除分区  partx -d --nr 5-6 /dev/sdb

2.2 文件系统

2.2.1 文件系统概念

文件系统是操作系统用于明确存储设备或分区上的文件的方法和数据结构;即在存储设备上组织文件的方法。操作系统中负责管理和存储文件信息的软件结构称为文件管理系统,简称文件系统从系统角度来看,文件系统是对文件存储设备的空间进行组织和分配,负责文件存储并对存入的文件进行保护和检索的系统。具体地说,它负责为用户建立文件,存入、读出、修改、转储文件,控制文件的存取,安全控制,日志,压缩,加密等

支持的文件系统:

/lib/modules/`uname -r`/kernel/fs

各种文件系统:https://en.wikipedia.org/wiki/Comparison_of_file_systems

帮助:man 5 fs

2.2.2 文件系统类型

Linux 常用文件系统

Windows 常用文件系统

Unix:

网络文件系统:

集群文件系统:

分布式文件系统:

RAW:

常用的文件系统特性:

FAT32

NTFS

EXT3

EXT4:

XFS

查前支持的文件系统:

cat /proc/filesystems

范例:

[root@rocky8 ~]# lsblk -f
NAME    FSTYPE  LABEL                UUID                                 MOUNTPOINT
sda                                                                       
├─sda1  xfs                          c72110fc-5dae-470c-9940-97ba978c7dc7 /boot
├─sda2  xfs                          57f3a077-bb67-42c3-9e6c-bc8a0fed3776 /
├─sda3  xfs                          02ae6744-8c28-4c86-b85b-e113c06a834f /data
├─sda4                                                                    
└─sda5  swap                         4f387202-0a81-4202-9e12-90d04af4d308 [SWAP]
sdb                                                                       
├─sdb1                                                                    
├─sdb2                                                                    
├─sdb3                                                                    
├─sdb5                                                                    
└─sdb6                                                                    
sdc                                                                       
├─sdc1                                                                    
└─sdc2                                                                    
sr0     iso9660 Rocky-8-4-x86_64-dvd 2021-06-20-16-16-21-00               
nvme0n1

[root@centos7 ~]# lsblk -f
NAME   FSTYPE  LABEL           UUID                                 MOUNTPOINT
sda                                                                 
├─sda1 xfs                     1741d17f-e256-4497-82f6-587ea4dad1e5 /boot
├─sda2 xfs                     1d6c2389-c44b-4068-b19f-827414c1675a /
├─sda3 xfs                     e4b4af84-60f3-485d-8803-96257dbbcfe3 /data
├─sda4                                                              
└─sda5 swap                    485c9b48-b54b-43be-b39a-30b2ffbab7df [SWAP]
sr0    iso9660 CentOS 7 x86_64 2020-11-02-15-15-23-00 

root@ubuntu1804:~# lsblk -f
NAME   FSTYPE  LABEL                           UUID                                 MOUNTPOINT
sda                                                                                 
├─sda1 ext4                                    0d314a5d-1e35-446b-bfcd-bb458dba215d /boot
├─sda2 ext4                                    c6645190-9f94-4ae7-b5ef-b16dcb96ed4c /
├─sda3 ext4                                    9e20c986-0757-45c4-a05d-3703dfa087c6 /data
└─sda4 swap                                    12848bd0-7412-4266-917c-28644c8e8550 [SWAP]
sr0    iso9660 Ubuntu-Server 18.04.6 LTS amd64 2021-09-16-00-01-03-00 

root@ubuntu1804:~# cat /proc/filesystems
nodev	sysfs
nodev	rootfs
nodev	ramfs
nodev	bdev
nodev	proc
nodev	cpuset
nodev	cgroup
nodev	cgroup2
nodev	tmpfs
nodev	devtmpfs
nodev	configfs
nodev	debugfs
nodev	tracefs
nodev	securityfs
nodev	sockfs
nodev	dax
nodev	bpf
nodev	pipefs
nodev	hugetlbfs
nodev	devpts
	ext3
	ext2
	ext4
	squashfs
	vfat
nodev	ecryptfs
	fuseblk
nodev	fuse
nodev	fusectl
nodev	pstore
nodev	mqueue
	btrfs
nodev	autofs
#查看系统支持的文件系统类型

root@ubuntu1804:~# modinfo xfs
filename:       /lib/modules/4.15.0-156-generic/kernel/fs/xfs/xfs.ko #xfs文件系统驱动文件就在这个路径
license:        GPL
description:    SGI XFS with ACLs, security attributes, realtime, no debug enabled
author:         Silicon Graphics, Inc.
alias:          fs-xfs
srcversion:     8B4FB1AD83FD5AFDCAE8AA2
depends:        libcrc32c
retpoline:      Y
intree:         Y
name:           xfs
vermagic:       4.15.0-156-generic SMP mod_unload modversions 
signat:         PKCS#7
signer:         
sig_key:        
sig_hashalgo:   md4
#modinfo  查看内核模块信息

root@ubuntu1804:~# ls /lib/modules/4.15.0-156-generic/kernel/fs/xfs/xfs.ko
/lib/modules/4.15.0-156-generic/kernel/fs/xfs/xfs.ko
root@ubuntu1804:~# ls /lib/modules/4.15.0-156-generic/kernel/fs/ #这个目录下存放系统支持的文件系统类型文件
9p    aufs     binfmt_misc.ko  cifs    efs    freevxfs  hfs      jffs2  ncpfs       nilfs2  omfs       qnx4      romfs  ufs
adfs  autofs4  btrfs           coda    exofs  fscache   hfsplus  jfs    nfs         nls     orangefs   qnx6      sysv   xfs
affs  befs     cachefiles      cramfs  f2fs   fuse      hpfs     lockd  nfs_common  ntfs    overlayfs  quota     ubifs
afs   bfs      ceph            dlm     fat    gfs2      isofs    minix  nfsd        ocfs2   pstore     reiserfs  udf

2.2.3 文件系统的组成部分

在这里插入图片描述

2.2.4 文件系统选择管理

2.2.4.1 创建文件系统

创建文件管理工具

常用选项

-t {ext2|ext3|ext4|xfs} 指定文件系统类型
-b {1024|2048|4096} 指定块 block 大小
-L ‘LABEL’ 设置卷标
-j 相当于 -t ext3, mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3
-i # 为数据空间中每多少个字节创建一个inode;不应该小于block大小
-N # 指定分区中创建多少个inode
-I 一个inode记录占用的磁盘空间大小,128---4096
-m # 默认5%,为管理人员预留空间占总空间的百分比
-O FEATURE[,...] 启用指定特性
-O ^FEATURE 关闭指定特性

范例:

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    2G  0 part 
├─sdb3    8:19   0  512B  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    3G  0 part 
sdc       8:32   0   10G  0 disk 
├─sdc1    8:33   0    1G  0 part 
└─sdc2    8:34   0    2G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 
[root@rocky8 ~]# mkfs.ext4 /dev/sdb1 #mkfs.ext4  创建ext4文件系统
mke2fs 1.45.6 (20-Mar-2020)
Found a dos partition table in /dev/sdb1
Proceed anyway? (y,N) y #问你它上边有一个mbr的分区表,是否继续,y
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: adec073e-aea5-4467-94aa-efd3981ba803
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@rocky8 ~]# lsblk -f
NAME    FSTYPE  LABEL                UUID                                 MOUNTPOINT
sda                                                                       
├─sda1  xfs                          c72110fc-5dae-470c-9940-97ba978c7dc7 /boot
├─sda2  xfs                          57f3a077-bb67-42c3-9e6c-bc8a0fed3776 /
├─sda3  xfs                          02ae6744-8c28-4c86-b85b-e113c06a834f /data
├─sda4                                                                    
└─sda5  swap                         4f387202-0a81-4202-9e12-90d04af4d308 [SWAP]
sdb                                                                       
├─sdb1  ext4                         adec073e-aea5-4467-94aa-efd3981ba803  # 这里就出现了ext4的文件系统,同时分配了一个UUID
├─sdb2                                                                    
├─sdb3                                                                    
├─sdb5                                                                    
└─sdb6                                                                    
sdc                                                                       
├─sdc1                                                                    
└─sdc2                                                                    
sr0     iso9660 Rocky-8-4-x86_64-dvd 2021-06-20-16-16-21-00               
nvme0n1 

[root@rocky8 ~]# blkid
/dev/sda1: UUID="c72110fc-5dae-470c-9940-97ba978c7dc7" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-01"
/dev/sda2: UUID="57f3a077-bb67-42c3-9e6c-bc8a0fed3776" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-02"
/dev/sda3: UUID="02ae6744-8c28-4c86-b85b-e113c06a834f" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-03"
/dev/sda5: UUID="4f387202-0a81-4202-9e12-90d04af4d308" TYPE="swap" PARTUUID="43d7507d-05"
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-06-20-16-16-21-00" LABEL="Rocky-8-4-x86_64-dvd" TYPE="iso9660" PTUUID="4a14a4ee" PTTYPE="dos"
/dev/sdb1: UUID="adec073e-aea5-4467-94aa-efd3981ba803" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a62c9118-01" #这里显示了UUID,文件系统类型
/dev/sdb2: PARTUUID="a62c9118-02"
/dev/sdb5: PARTUUID="a62c9118-05"
/dev/sdb6: PARTUUID="a62c9118-06"
/dev/sdc1: PARTLABEL="Linux filesystem" PARTUUID="7a7090a5-623a-45a0-b7e7-2c613355b7ea"
/dev/sdc2: PARTLABEL="Linux LVM" PARTUUID="cb838081-f185-4983-ad7e-6eea78c54565"

[root@rocky8 ~]# mkfs.xfs /dev/sdb2 #mkfs.xfs  创建xfs文件系统
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=524288, 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@rocky8 ~]# lsblk -f
NAME    FSTYPE  LABEL                UUID                                 MOUNTPOINT
sda                                                                       
├─sda1  xfs                          c72110fc-5dae-470c-9940-97ba978c7dc7 /boot
├─sda2  xfs                          57f3a077-bb67-42c3-9e6c-bc8a0fed3776 /
├─sda3  xfs                          02ae6744-8c28-4c86-b85b-e113c06a834f /data
├─sda4                                                                    
└─sda5  swap                         4f387202-0a81-4202-9e12-90d04af4d308 [SWAP]
sdb                                                                       
├─sdb1  ext4                         adec073e-aea5-4467-94aa-efd3981ba803 
├─sdb2  xfs                          8a2c8fdf-9294-4030-b10c-edc8a7b3e78f 
├─sdb3                                                                    
├─sdb5                                                                    
└─sdb6                                                                    
sdc                                                                       
├─sdc1                                                                    
└─sdc2                                                                    
sr0     iso9660 Rocky-8-4-x86_64-dvd 2021-06-20-16-16-21-00               
nvme0n1                                                                   
[root@rocky8 ~]# blkid
/dev/sda1: UUID="c72110fc-5dae-470c-9940-97ba978c7dc7" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-01"
/dev/sda2: UUID="57f3a077-bb67-42c3-9e6c-bc8a0fed3776" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-02"
/dev/sda3: UUID="02ae6744-8c28-4c86-b85b-e113c06a834f" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-03"
/dev/sda5: UUID="4f387202-0a81-4202-9e12-90d04af4d308" TYPE="swap" PARTUUID="43d7507d-05"
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-06-20-16-16-21-00" LABEL="Rocky-8-4-x86_64-dvd" TYPE="iso9660" PTUUID="4a14a4ee" PTTYPE="dos"
/dev/sdb1: UUID="adec073e-aea5-4467-94aa-efd3981ba803" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a62c9118-01"
/dev/sdb2: UUID="8a2c8fdf-9294-4030-b10c-edc8a7b3e78f" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="a62c9118-02"
/dev/sdb5: PARTUUID="a62c9118-05"
/dev/sdb6: PARTUUID="a62c9118-06"
/dev/sdc1: PARTLABEL="Linux filesystem" PARTUUID="7a7090a5-623a-45a0-b7e7-2c613355b7ea"
/dev/sdc2: PARTLABEL="Linux LVM" PARTUUID="cb838081-f185-4983-ad7e-6eea78c54565"

[root@rocky8 ~]# tune2fs -l /dev/sdb1 #tune2fs -l  查看ext4文件系统特性
tune2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          adec073e-aea5-4467-94aa-efd3981ba803
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              65536
Block count:              262144
Reserved block count:     13107
Free blocks:              249189
Free inodes:              65525
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      127
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Fri Oct 15 21:16:34 2021
Last mount time:          n/a
Last write time:          Fri Oct 15 21:16:34 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Oct 15 21:16:34 2021
Check interval:           0 (<none>)
Lifetime writes:          533 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      67cae779-ee52-4cd2-82ff-b72216fa51ff
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0xe9647312

[root@rocky8 ~]# dumpe2fs /dev/sdb1 # dumpe2fs 查看更加详细的ext4文件系统特性
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          adec073e-aea5-4467-94aa-efd3981ba803
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl #默认挂载选项
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              65536
Block count:              262144
Reserved block count:     13107
Free blocks:              249189
Free inodes:              65525
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      127
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Fri Oct 15 21:16:34 2021
Last mount time:          n/a
Last write time:          Fri Oct 15 21:16:34 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Oct 15 21:16:34 2021
Check interval:           0 (<none>)
Lifetime writes:          533 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      67cae779-ee52-4cd2-82ff-b72216fa51ff
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0xe9647312
Journal features:         (none)
Journal size:             32M
Journal length:           8192
Journal sequence:         0x00000001
Journal start:            0


Group 0: (Blocks 0-32767) csum 0xecdc
  Primary superblock at 0, Group descriptors at 1-1
  Reserved GDT blocks at 2-128
  Block bitmap at 129 (+129), csum 0x34f4a600
  Inode bitmap at 137 (+137), csum 0x63342b4a
  Inode table at 145-656 (+145)
  28521 free blocks, 8181 free inodes, 2 directories, 8181 unused inodes
  Free blocks: 4247-32767
  Free inodes: 12-8192
Group 1: (Blocks 32768-65535) csum 0xc480 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 32768, Group descriptors at 32769-32769
  Reserved GDT blocks at 32770-32896
  Block bitmap at 130 (bg #0 + 130), csum 0x00000000
  Inode bitmap at 138 (bg #0 + 138), csum 0x00000000
  Inode table at 657-1168 (bg #0 + 657)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 32897-65535
  Free inodes: 8193-16384
Group 2: (Blocks 65536-98303) csum 0x1a5c [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 131 (bg #0 + 131), csum 0x00000000
  Inode bitmap at 139 (bg #0 + 139), csum 0x00000000
  Inode table at 1169-1680 (bg #0 + 1169)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 65536-98303
  Free inodes: 16385-24576
Group 3: (Blocks 98304-131071) csum 0xa343 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 98304, Group descriptors at 98305-98305
  Reserved GDT blocks at 98306-98432
  Block bitmap at 132 (bg #0 + 132), csum 0x00000000
  Inode bitmap at 140 (bg #0 + 140), csum 0x00000000
  Inode table at 1681-2192 (bg #0 + 1681)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 98433-131071
  Free inodes: 24577-32768
Group 4: (Blocks 131072-163839) csum 0xd0fb [INODE_UNINIT]
  Block bitmap at 133 (bg #0 + 133), csum 0x5587cc45
  Inode bitmap at 141 (bg #0 + 141), csum 0x00000000
  Inode table at 2193-2704 (bg #0 + 2193)
  24576 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 139264-163839
  Free inodes: 32769-40960
Group 5: (Blocks 163840-196607) csum 0x51ce [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 163840, Group descriptors at 163841-163841
  Reserved GDT blocks at 163842-163968
  Block bitmap at 134 (bg #0 + 134), csum 0x00000000
  Inode bitmap at 142 (bg #0 + 142), csum 0x00000000
  Inode table at 2705-3216 (bg #0 + 2705)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 163969-196607
  Free inodes: 40961-49152
Group 6: (Blocks 196608-229375) csum 0x8f12 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 135 (bg #0 + 135), csum 0x00000000
  Inode bitmap at 143 (bg #0 + 143), csum 0x00000000
  Inode table at 3217-3728 (bg #0 + 3217)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 196608-229375
  Free inodes: 49153-57344
Group 7: (Blocks 229376-262143) csum 0xb7ab [INODE_UNINIT]
  Backup superblock at 229376, Group descriptors at 229377-229377
  Reserved GDT blocks at 229378-229504
  Block bitmap at 136 (bg #0 + 136), csum 0x4e9c6bf1
  Inode bitmap at 144 (bg #0 + 144), csum 0x00000000
  Inode table at 3729-4240 (bg #0 + 3729)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 229505-262143
  Free inodes: 57345-65536

#centos 6 上添加acl功能,centos 7/8 默认有这个功能
tune2fs -o acl /dev/sdb

[root@rocky8 ~]# tune2fs -o ^acl /dev/sdb1 # tune2fs -o ^acl ,在acl前加上^就去掉了acl
tune2fs 1.45.6 (20-Mar-2020)
[root@rocky8 ~]# dumpe2fs /dev/sdb1
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          adec073e-aea5-4467-94aa-efd3981ba803
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr #去了这里就没有acl功能了
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              65536
Block count:              262144
Reserved block count:     13107
Free blocks:              249189
Free inodes:              65525
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      127
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Fri Oct 15 21:16:34 2021
Last mount time:          n/a
Last write time:          Fri Oct 15 21:22:22 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Oct 15 21:16:34 2021
Check interval:           0 (<none>)
Lifetime writes:          533 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      67cae779-ee52-4cd2-82ff-b72216fa51ff
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0xfba2ffa4
Journal features:         (none)
Journal size:             32M
Journal length:           8192
Journal sequence:         0x00000001
Journal start:            0


Group 0: (Blocks 0-32767) csum 0xecdc
  Primary superblock at 0, Group descriptors at 1-1
  Reserved GDT blocks at 2-128
  Block bitmap at 129 (+129), csum 0x34f4a600
  Inode bitmap at 137 (+137), csum 0x63342b4a
  Inode table at 145-656 (+145)
  28521 free blocks, 8181 free inodes, 2 directories, 8181 unused inodes
  Free blocks: 4247-32767
  Free inodes: 12-8192
Group 1: (Blocks 32768-65535) csum 0xc480 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 32768, Group descriptors at 32769-32769
  Reserved GDT blocks at 32770-32896
  Block bitmap at 130 (bg #0 + 130), csum 0x00000000
  Inode bitmap at 138 (bg #0 + 138), csum 0x00000000
  Inode table at 657-1168 (bg #0 + 657)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 32897-65535
  Free inodes: 8193-16384
Group 2: (Blocks 65536-98303) csum 0x1a5c [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 131 (bg #0 + 131), csum 0x00000000
  Inode bitmap at 139 (bg #0 + 139), csum 0x00000000
  Inode table at 1169-1680 (bg #0 + 1169)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 65536-98303
  Free inodes: 16385-24576
Group 3: (Blocks 98304-131071) csum 0xa343 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 98304, Group descriptors at 98305-98305
  Reserved GDT blocks at 98306-98432
  Block bitmap at 132 (bg #0 + 132), csum 0x00000000
  Inode bitmap at 140 (bg #0 + 140), csum 0x00000000
  Inode table at 1681-2192 (bg #0 + 1681)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 98433-131071
  Free inodes: 24577-32768
Group 4: (Blocks 131072-163839) csum 0xd0fb [INODE_UNINIT]
  Block bitmap at 133 (bg #0 + 133), csum 0x5587cc45
  Inode bitmap at 141 (bg #0 + 141), csum 0x00000000
  Inode table at 2193-2704 (bg #0 + 2193)
  24576 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 139264-163839
  Free inodes: 32769-40960
Group 5: (Blocks 163840-196607) csum 0x51ce [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 163840, Group descriptors at 163841-163841
  Reserved GDT blocks at 163842-163968
  Block bitmap at 134 (bg #0 + 134), csum 0x00000000
  Inode bitmap at 142 (bg #0 + 142), csum 0x00000000
  Inode table at 2705-3216 (bg #0 + 2705)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 163969-196607
  Free inodes: 40961-49152
Group 6: (Blocks 196608-229375) csum 0x8f12 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 135 (bg #0 + 135), csum 0x00000000
  Inode bitmap at 143 (bg #0 + 143), csum 0x00000000
  Inode table at 3217-3728 (bg #0 + 3217)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 196608-229375
  Free inodes: 49153-57344
Group 7: (Blocks 229376-262143) csum 0xb7ab [INODE_UNINIT]
  Backup superblock at 229376, Group descriptors at 229377-229377
  Reserved GDT blocks at 229378-229504
  Block bitmap at 136 (bg #0 + 136), csum 0x4e9c6bf1
  Inode bitmap at 144 (bg #0 + 144), csum 0x00000000
  Inode table at 3729-4240 (bg #0 + 3729)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 229505-262143
  Free inodes: 57345-65536

[root@rocky8 ~]# tune2fs -o acl /dev/sdb1 #tune2fs -o acl 添加acl功能
tune2fs 1.45.6 (20-Mar-2020)
[root@rocky8 ~]# dumpe2fs /dev/sdb1
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          adec073e-aea5-4467-94aa-efd3981ba803
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl #加上后这里就显示有了acl功能
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              65536
Block count:              262144
Reserved block count:     13107
Free blocks:              249189
Free inodes:              65525
First block:              0
Block size:               4096 #块大小4k,它在文件系统上管理空间的时候,最小的文件存储单位是4k。最小存储单位就是一个文件在磁盘上存储的最小占用空间大小为4k。
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      127
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Fri Oct 15 21:16:34 2021
Last mount time:          n/a
Last write time:          Fri Oct 15 21:23:50 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Oct 15 21:16:34 2021
Check interval:           0 (<none>)
Lifetime writes:          533 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      67cae779-ee52-4cd2-82ff-b72216fa51ff
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0xb7b5eb7e
Journal features:         (none)
Journal size:             32M
Journal length:           8192
Journal sequence:         0x00000001
Journal start:            0


Group 0: (Blocks 0-32767) csum 0xecdc
  Primary superblock at 0, Group descriptors at 1-1
  Reserved GDT blocks at 2-128
  Block bitmap at 129 (+129), csum 0x34f4a600
  Inode bitmap at 137 (+137), csum 0x63342b4a
  Inode table at 145-656 (+145)
  28521 free blocks, 8181 free inodes, 2 directories, 8181 unused inodes
  Free blocks: 4247-32767
  Free inodes: 12-8192
Group 1: (Blocks 32768-65535) csum 0xc480 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 32768, Group descriptors at 32769-32769
  Reserved GDT blocks at 32770-32896
  Block bitmap at 130 (bg #0 + 130), csum 0x00000000
  Inode bitmap at 138 (bg #0 + 138), csum 0x00000000
  Inode table at 657-1168 (bg #0 + 657)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 32897-65535
  Free inodes: 8193-16384
Group 2: (Blocks 65536-98303) csum 0x1a5c [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 131 (bg #0 + 131), csum 0x00000000
  Inode bitmap at 139 (bg #0 + 139), csum 0x00000000
  Inode table at 1169-1680 (bg #0 + 1169)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 65536-98303
  Free inodes: 16385-24576
Group 3: (Blocks 98304-131071) csum 0xa343 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 98304, Group descriptors at 98305-98305
  Reserved GDT blocks at 98306-98432
  Block bitmap at 132 (bg #0 + 132), csum 0x00000000
  Inode bitmap at 140 (bg #0 + 140), csum 0x00000000
  Inode table at 1681-2192 (bg #0 + 1681)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 98433-131071
  Free inodes: 24577-32768
Group 4: (Blocks 131072-163839) csum 0xd0fb [INODE_UNINIT]
  Block bitmap at 133 (bg #0 + 133), csum 0x5587cc45
  Inode bitmap at 141 (bg #0 + 141), csum 0x00000000
  Inode table at 2193-2704 (bg #0 + 2193)
  24576 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 139264-163839
  Free inodes: 32769-40960
Group 5: (Blocks 163840-196607) csum 0x51ce [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 163840, Group descriptors at 163841-163841
  Reserved GDT blocks at 163842-163968
  Block bitmap at 134 (bg #0 + 134), csum 0x00000000
  Inode bitmap at 142 (bg #0 + 142), csum 0x00000000
  Inode table at 2705-3216 (bg #0 + 2705)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 163969-196607
  Free inodes: 40961-49152
Group 6: (Blocks 196608-229375) csum 0x8f12 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 135 (bg #0 + 135), csum 0x00000000
  Inode bitmap at 143 (bg #0 + 143), csum 0x00000000
  Inode table at 3217-3728 (bg #0 + 3217)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 196608-229375
  Free inodes: 49153-57344
Group 7: (Blocks 229376-262143) csum 0xb7ab [INODE_UNINIT]
  Backup superblock at 229376, Group descriptors at 229377-229377
  Reserved GDT blocks at 229378-229504
  Block bitmap at 136 (bg #0 + 136), csum 0x4e9c6bf1
  Inode bitmap at 144 (bg #0 + 144), csum 0x00000000
  Inode table at 3729-4240 (bg #0 + 3729)
  32639 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 229505-262143
  Free inodes: 57345-65536

[root@rocky8 ~]# mkfs.ext4 -b 500 /dev/sdb1
mkfs.ext4: invalid block size - 500
#-b  指定文件最小占用大小,500不行。

[root@rocky8 ~]# mkfs.ext4 -b 1024 /dev/sdb1 #最小也要指定1024,1k大小
mke2fs 1.45.6 (20-Mar-2020)
/dev/sdb1 contains a ext4 file system
	created on Fri Oct 15 21:16:34 2021
Proceed anyway? (y,N) y
Creating filesystem with 1048576 1k blocks and 65536 inodes
Filesystem UUID: f7d5345f-5f29-417d-a044-37508852e80f
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553, 
	1024001

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

[root@rocky8 ~]# dumpe2fs /dev/sdb1
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          f7d5345f-5f29-417d-a044-37508852e80f
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              65536 #节点数量
Block count:              1048576 #存放数据的容量
Reserved block count:     52428
Free blocks:              1012622
Free inodes:              65525
First block:              1
Block size:               1024 #现在就改成1024
Fragment size:            1024
Group descriptor size:    64
Reserved GDT blocks:      256
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         512
Inode blocks per group:   128
Flex block group size:    16
Filesystem created:       Fri Oct 15 21:25:45 2021
Last mount time:          n/a
Last write time:          Fri Oct 15 21:25:45 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Oct 15 21:25:45 2021
Check interval:           0 (<none>)
Lifetime writes:          295 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      e7cd8a67-ff5e-4ab2-ba16-1eae1ce1119b
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x33082019
Journal features:         (none)
Journal size:             16M
Journal length:           16384
Journal sequence:         0x00000001
Journal start:            0


Group 0: (Blocks 1-8192) csum 0x1a3d
  Primary superblock at 1, Group descriptors at 2-9
  Reserved GDT blocks at 10-265
  Block bitmap at 266 (+265), csum 0x0e545962
  Inode bitmap at 282 (+281), csum 0x538d8ff6
  Inode table at 298-425 (+297)
  5833 free blocks, 501 free inodes, 2 directories, 501 unused inodes
  Free blocks: 2360-8192
  Free inodes: 12-512
Group 1: (Blocks 8193-16384) csum 0xa235 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 8193, Group descriptors at 8194-8201
  Reserved GDT blocks at 8202-8457
  Block bitmap at 267 (bg #0 + 266), csum 0x00000000
  Inode bitmap at 283 (bg #0 + 282), csum 0x00000000
  Inode table at 426-553 (bg #0 + 425)
  7927 free blocks, 512 free inodes, 0 directories, 512 unused inodes
  Free blocks: 8458-16384
  Free inodes: 513-1024
Group 2: (Blocks 16385-24576) csum 0x5ebc [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 268 (bg #0 + 267), csum 0x00000000
  Inode bitmap at 284 (bg #0 + 283), csum 0x00000000
  Inode table at 554-681 (bg #0 + 553)
  8192 free blocks, 512 free inodes, 0 directories, 512 unused inodes
  Free blocks: 16385-24576
  Free inodes: 1025-1536
Group 3: (Blocks 24577-32768) csum 0xa300 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 24577, Group descriptors at 24578-24585
  Reserved GDT blocks at 24586-24841
  Block bitmap at 269 (bg #0 + 268), csum 0x00000000
  Inode bitmap at 285 (bg #0 + 284), csum 0x00000000
  Inode table at 682-809 (bg #0 + 681)
  7927 free blocks, 512 free inodes, 0 directories, 512 unused inodes
  Free blocks: 24842-32768
  Free inodes: 1537-2048
Group 4: (Blocks 32769-40960) csum 0x9348 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 270 (bg #0 + 269), csum 0x00000000
  Inode bitmap at 286 (bg #0 + 285), csum 0x00000000
  Inode table at 810-937 (bg #0 + 809)
  8192 free blocks, 512 free inodes, 0 directories, 512 unused inodes
  Free blocks: 32769-40960
  Free inodes: 2049-2560
Group 5: (Blocks 40961-49152) csum 0x6ef4 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 40961, Group descriptors at 40962-40969
  Reserved GDT blocks at 40970-41225
  Block bitmap at 271 (bg #0 + 270), csum 0x00000000
  Inode bitmap at 287 (bg #0 + 286), csum 0x00000000
  Inode table at 938-1065 (bg #0 + 937)
  7927 free blocks, 512 free inodes, 0 directories, 512 unused inodes
  Free blocks: 41226-49152
  Free inodes: 2561-3072
...

#可以分1024、2048、4096,这个可以创建文件系统时候改,一旦有数据,就不能再改了,除非把数据移出来,再改

[root@rocky8 ~]#  mkfs.ext4 --help
mkfs.ext4: invalid option -- '-'
Usage: mkfs.ext4 [-c|-l filename] [-b block-size] [-C cluster-size]
	[-i bytes-per-inode] [-I inode-size] [-J journal-options]
	[-G flex-group-size] [-N number-of-inodes] [-d root-directory]
	[-m reserved-blocks-percentage] [-o creator-os]
	[-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
	[-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
	[-t fs-type] [-T usage-type ] [-U UUID] [-e errors_behavior][-z undo_file]
	[-jnqvDFSV] device [blocks-count]

[root@rocky8 ~]# mkfs.ext4 -N 655360 /dev/sdb1 #-N  指定节点编号数量
mke2fs 1.45.6 (20-Mar-2020)
/dev/sdb1 contains a ext4 file system
	created on Fri Oct 15 21:25:45 2021
Proceed anyway? (y,N) y
Creating filesystem with 262144 4k blocks and 655360 inodes
Filesystem UUID: ba7fe12e-93ef-43eb-a684-d12611a1f737
Superblock backups stored on blocks: 
	13680, 41040, 68400, 95760, 123120

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

[root@rocky8 ~]# dumpe2fs /dev/sdb1 | less
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          ba7fe12e-93ef-43eb-a684-d12611a1f737
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              655360 #这里的数量也变成了655360
Block count:              262144
Reserved block count:     13003
Free blocks:              211098
Free inodes:              655349
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64

#改变节点编号数量,必然会增加元数据占用空间,元数据占用空间大了,数据占用的空间就小了

[root@rocky8 ~]# dumpe2fs /dev/sdb1 | less
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          ba7fe12e-93ef-43eb-a684-d12611a1f737
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              655360
Block count:              262144
Reserved block count:     13003 #预留空间
Free blocks:              211098
Free inodes:              655349
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      306
Blocks per group:         13680
Fragments per group:      13680
Inodes per group:         32768
Inode blocks per group:   2048
Flex block group size:    16
Filesystem created:       Fri Oct 15 21:29:26 2021
Last mount time:          n/a
Last write time:          Fri Oct 15 21:29:26 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Oct 15 21:29:26 2021
Check interval:           0 (<none>)
Lifetime writes:          1261 kB
Reserved blocks uid:      0 (user root) #预留给root
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      5cbfc6c8-01fc-45d3-a560-6f11161db4f0
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x1cb8d362
Journal features:         (none)
Journal size:             32M
Journal length:           8192
Journal sequence:         0x00000001
Journal start:            0


Group 0: (Blocks 0-13679) csum 0xa0c7
  Primary superblock at 0, Group descriptors at 1-1 #superblock 就是存放元数据的块
  Reserved GDT blocks at 2-307
  Block bitmap at 308 (+308), csum 0x4c93c822
  Inode bitmap at 324 (+324), csum 0x271636c9
  Inode table at 340-2387 (+340)
  1046 free blocks, 32757 free inodes, 2 directories, 32757 unused inodes
  Free blocks: 12634-13679
  Free inodes: 12-32768
Group 1: (Blocks 13680-27359) csum 0xc71d [INODE_UNINIT]
  Backup superblock at 13680, Group descriptors at 13681-13681 #Backup superblock 备份超级块
  Reserved GDT blocks at 13682-13987
  Block bitmap at 309 (bg #0 + 309), csum 0x3c1ac2f3
  Inode bitmap at 325 (bg #0 + 325), csum 0x00000000
  Inode table at 2388-4435 (bg #0 + 2388)
  0 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 
  Free inodes: 32769-65536

#它会把一个个块分成组来存储,分组是提高效率,如果不分组他就会遍历磁盘上个一个个块去找,
#mkfs.ext4 -m  指定预留空间大小

2.2.4.2 查看和管理分区信息

blkid 可以查看块设备属性信息

格式:

blkid [OPTION]... [DEVICE]

常用选项:

-U UUID 根据指定的UUID来查找对应的设备

-L LABEL 根据指定的LABEL来查找对应的设备

e2label:管理ext系列文件系统的LABEL

e2label DEVICE [LABEL]

findfs :查找分区

findfs [options] LABEL=<label>
findfs [options] UUID=<uuid>

范例:

[root@centos8 ~]#findfs UUID=f7f53add-b184-4ddc-8d2c-5263b84d1e15
/dev/sda2

tune2fs:重新设定ext系列文件系统可调整参数的值

-l 查看指定文件系统超级块信息;super block
-L 'LABEL’ 修改卷标
-m # 修预留给管理员的空间百分比
-j 将ext2升级为ext3
-O 文件系统属性启用或禁用, -O ^has_journal
-o 调整文件系统的默认挂载选项,-o ^acl
-U UUID 修改UUID号

dumpe2fs:显示ext文件系统信息,将磁盘块分组管理

-h:查看超级块信息,不显示分组信息

范例:查看ext文件系统的元数据和块组信息

[root@rocky8 ~]# dumpe2fs /dev/sdb1
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          ba7fe12e-93ef-43eb-a684-d12611a1f737
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              655360
Block count:              262144
Reserved block count:     13003
Free blocks:              211098
Free inodes:              655349
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      306
Blocks per group:         13680
Fragments per group:      13680
Inodes per group:         32768
Inode blocks per group:   2048
Flex block group size:    16
Filesystem created:       Fri Oct 15 21:29:26 2021
Last mount time:          n/a
Last write time:          Fri Oct 15 21:29:26 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Fri Oct 15 21:29:26 2021
Check interval:           0 (<none>)
Lifetime writes:          1261 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      5cbfc6c8-01fc-45d3-a560-6f11161db4f0
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x1cb8d362
Journal features:         (none)
Journal size:             32M
Journal length:           8192
Journal sequence:         0x00000001
Journal start:            0


Group 0: (Blocks 0-13679) csum 0xa0c7
  Primary superblock at 0, Group descriptors at 1-1
  Reserved GDT blocks at 2-307
  Block bitmap at 308 (+308), csum 0x4c93c822
  Inode bitmap at 324 (+324), csum 0x271636c9
  Inode table at 340-2387 (+340)
  1046 free blocks, 32757 free inodes, 2 directories, 32757 unused inodes
  Free blocks: 12634-13679
  Free inodes: 12-32768
Group 1: (Blocks 13680-27359) csum 0xc71d [INODE_UNINIT]
  Backup superblock at 13680, Group descriptors at 13681-13681
  Reserved GDT blocks at 13682-13987
  Block bitmap at 309 (bg #0 + 309), csum 0x3c1ac2f3
  Inode bitmap at 325 (bg #0 + 325), csum 0x00000000
  Inode table at 2388-4435 (bg #0 + 2388)
  0 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 
  Free inodes: 32769-65536
Group 2: (Blocks 27360-41039) csum 0x69b3 [INODE_UNINIT]
  Block bitmap at 310 (bg #0 + 310), csum 0x486c1061
  Inode bitmap at 326 (bg #0 + 326), csum 0x00000000
  Inode table at 4436-6483 (bg #0 + 4436)
  6572 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 34468-41039
  Free inodes: 65537-98304
Group 3: (Blocks 41040-54719) csum 0xe2da [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 41040, Group descriptors at 41041-41041
  Reserved GDT blocks at 41042-41347
  Block bitmap at 311 (bg #0 + 311), csum 0x00000000
  Inode bitmap at 327 (bg #0 + 327), csum 0x00000000
  Inode table at 6484-8531 (bg #0 + 6484)
  13372 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 41348-54719
  Free inodes: 98305-131072
Group 4: (Blocks 54720-68399) csum 0xbbfc [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 312 (bg #0 + 312), csum 0x00000000
  Inode bitmap at 328 (bg #0 + 328), csum 0x00000000
  Inode table at 8532-10579 (bg #0 + 8532)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 54720-68399
  Free inodes: 131073-163840
Group 5: (Blocks 68400-82079) csum 0xc428 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 68400, Group descriptors at 68401-68401
  Reserved GDT blocks at 68402-68707
  Block bitmap at 313 (bg #0 + 313), csum 0x00000000
  Inode bitmap at 329 (bg #0 + 329), csum 0x00000000
  Inode table at 10580-12627 (bg #0 + 10580)
  13372 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 68708-82079
  Free inodes: 163841-196608
Group 6: (Blocks 82080-95759) csum 0x5050 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 314 (bg #0 + 314), csum 0x00000000
  Inode bitmap at 330 (bg #0 + 330), csum 0x00000000
  Inode table at 13988-16035 (bg #1 + 308)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 82080-95759
  Free inodes: 196609-229376
Group 7: (Blocks 95760-109439) csum 0x2f84 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 95760, Group descriptors at 95761-95761
  Reserved GDT blocks at 95762-96067
  Block bitmap at 315 (bg #0 + 315), csum 0x00000000
  Inode bitmap at 331 (bg #0 + 331), csum 0x00000000
  Inode table at 16036-18083 (bg #1 + 2356)
  13372 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 96068-109439
  Free inodes: 229377-262144
Group 8: (Blocks 109440-123119) csum 0x74de [INODE_UNINIT]
  Block bitmap at 316 (bg #0 + 316), csum 0x26c23c12
  Inode bitmap at 332 (bg #0 + 332), csum 0x00000000
  Inode table at 18084-20131 (bg #1 + 4404)
  5488 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 117632-123119
  Free inodes: 262145-294912
Group 9: (Blocks 123120-136799) csum 0x0270 [INODE_UNINIT, BLOCK_UNINIT]
  Backup superblock at 123120, Group descriptors at 123121-123121
  Reserved GDT blocks at 123122-123427
  Block bitmap at 317 (bg #0 + 317), csum 0x00000000
  Inode bitmap at 333 (bg #0 + 333), csum 0x00000000
  Inode table at 20132-22179 (bg #1 + 6452)
  13372 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 123428-136799
  Free inodes: 294913-327680
Group 10: (Blocks 136800-150479) csum 0x841d [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 318 (bg #0 + 318), csum 0x00000000
  Inode bitmap at 334 (bg #0 + 334), csum 0x00000000
  Inode table at 22180-24227 (bg #1 + 8500)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 136800-150479
  Free inodes: 327681-360448
Group 11: (Blocks 150480-164159) csum 0xc3b9 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 319 (bg #0 + 319), csum 0x00000000
  Inode bitmap at 335 (bg #0 + 335), csum 0x00000000
  Inode table at 24228-26275 (bg #1 + 10548)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 150480-164159
  Free inodes: 360449-393216
Group 12: (Blocks 164160-177839) csum 0xc3bc [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 320 (bg #0 + 320), csum 0x00000000
  Inode bitmap at 336 (bg #0 + 336), csum 0x00000000
  Inode table at 26276-28323 (bg #1 + 12596)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 164160-177839
  Free inodes: 393217-425984
Group 13: (Blocks 177840-191519) csum 0x8418 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 321 (bg #0 + 321), csum 0x00000000
  Inode bitmap at 337 (bg #0 + 337), csum 0x00000000
  Inode table at 28324-30371 (bg #2 + 964)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 177840-191519
  Free inodes: 425985-458752
Group 14: (Blocks 191520-205199) csum 0x3a05 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 322 (bg #0 + 322), csum 0x00000000
  Inode bitmap at 338 (bg #0 + 338), csum 0x00000000
  Inode table at 30372-32419 (bg #2 + 3012)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 191520-205199
  Free inodes: 458753-491520
Group 15: (Blocks 205200-218879) csum 0x7da1 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 323 (bg #0 + 323), csum 0x00000000
  Inode bitmap at 339 (bg #0 + 339), csum 0x00000000
  Inode table at 32420-34467 (bg #2 + 5060)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 205200-218879
  Free inodes: 491521-524288
Group 16: (Blocks 218880-232559) csum 0x41ad [INODE_UNINIT]
  Block bitmap at 218880 (+0), csum 0x9e981676
  Inode bitmap at 218884 (+4), csum 0x00000000
  Inode table at 218888-220935 (+8)
  5480 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 227080-232559
  Free inodes: 524289-557056
Group 17: (Blocks 232560-246239) csum 0xb8f8 [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 218881 (bg #16 + 1), csum 0x00000000
  Inode bitmap at 218885 (bg #16 + 5), csum 0x00000000
  Inode table at 220936-222983 (bg #16 + 2056)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 232560-246239
  Free inodes: 557057-589824
Group 18: (Blocks 246240-259919) csum 0x3eee [INODE_UNINIT, BLOCK_UNINIT]
  Block bitmap at 218882 (bg #16 + 2), csum 0x00000000
  Inode bitmap at 218886 (bg #16 + 6), csum 0x00000000
  Inode table at 222984-225031 (bg #16 + 4104)
  13680 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 246240-259919
  Free inodes: 589825-622592
Group 19: (Blocks 259920-262143) csum 0xa0e7 [INODE_UNINIT]
  Block bitmap at 218883 (bg #16 + 3), csum 0xc6b533bc
  Inode bitmap at 218887 (bg #16 + 7), csum 0x00000000
  Inode table at 225032-227079 (bg #16 + 6152)
  2224 free blocks, 32768 free inodes, 0 directories, 32768 unused inodes
  Free blocks: 259920-262143
  Free inodes: 622593-655360

xfs_info:显示示挂载或已挂载的 xfs 文件系统信息

xfs_info mountpoint|devname

范例:

[root@rocky8 ~]# xfs_info /dev/sda1
meta-data=/dev/sda1              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
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
#dumpe2fs 只能看ext4,xfs用xfs_info查看

超级块和INODE TABLE
在这里插入图片描述
块组描述符表(GDT)
ext文件系统每一个块组信息使用32字节描述,这32个字节称为块组描述符,所有块组的块组描述符组成块组描述符表GDT(group descriptor table)。虽然每个块组都需要块组描述符来记录块组的信息和属性元数据,但是不是每个块组中都存放了块组描述符。将所有块组的块组信息组成一个GDT保存,并将该GDT存放于某些块组中,类似存放superblock和备份superblock的块

2.2.4.3 文件系统检测和修复

文件系统夹故障常发生于死机或者非正常关机之后,挂载为文件系统标记为“no clean”

注意:一定不要在挂载状态下执行下面命令修复

fsck: File System Check

fsck.FS_TYPE
fsck -t FS_TYPE

注意:FS_TYPE 一定要与分区上已经文件类型相同

常用选项:

-a 自动修复
-r 交互式修复错误

e2fsck:ext系列文件专用的检测修复工具

-y 自动回答为yes
-f 强制修复
-p 自动进行安全的修复文件系统问题

xfs_repair:xfs文件系统专用检测修复工具

常用选项:

-f 修复文件,而设备
-n 只检查
-d 允许修复只读的挂载设备,在单用户下修复 / 时使用,然后立即reboot

范例:

[root@rocky8 ~]# fsck.ext4 /dev/sdb1
e2fsck 1.45.6 (20-Mar-2020)
/dev/sdb1: clean, 11/655360 files, 51046/262144 blocks

[root@rocky8 ~]# hexdump -C /dev/sdb1 |less
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400  00 00 0a 00 00 00 04 00  cb 32 00 00 9a 38 03 00  |.........2...8..|
00000410  f5 ff 09 00 00 00 00 00  02 00 00 00 02 00 00 00  |................|
00000420  70 35 00 00 70 35 00 00  00 80 00 00 00 00 00 00  |p5..p5..........|
00000430  f4 84 69 61 00 00 ff ff  53 ef 01 00 01 00 00 00  |..ia....S.......|
00000440  36 82 69 61 00 00 00 00  00 00 00 00 01 00 00 00  |6.ia............|
00000450  00 00 00 00 0b 00 00 00  00 01 00 00 3c 00 00 00  |............<...|
00000460  c2 02 00 00 6b 04 00 00  ba 7f e1 2e 93 ef 43 eb  |....k.........C.|
00000470  a6 84 d1 26 11 a1 f7 37  00 00 00 00 00 00 00 00  |...&...7........|
00000480  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000004c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 32 01  |..............2.|
000004d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000004e0  08 00 00 00 00 00 00 00  00 00 00 00 5c bf c6 c8  |............\...|
000004f0  01 fc 45 d3 a5 60 6f 11  16 1d b4 f0 01 01 40 00  |..E..`o.......@.|
00000500  0c 00 00 00 00 00 00 00  36 82 69 61 0a f3 01 00  |........6.ia....|
00000510  04 00 00 00 00 00 00 00  00 00 00 00 00 20 00 00  |............. ..|
00000520  80 ab 01 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000530  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000540  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 02  |................|
00000550  00 00 00 00 00 00 00 00  00 00 00 00 20 00 20 00  |............ . .|
00000560  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000570  00 00 00 00 04 01 00 00  f1 04 00 00 00 00 00 00  |................|
00000580  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*

[root@rocky8 ~]# dd if=/dev/zero of=/dev/sdb1 bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0036868 s, 284 MB/s

[root@rocky8 ~]#  fsck.ext4 /dev/sdb1  #fsck.ext4 修复文件系统
e2fsck 1.45.6 (20-Mar-2020)
ext2fs_open2: Bad magic number in super-block
fsck.ext4: Superblock invalid, trying backup blocks...
Superblock has an invalid journal (inode 8).
Clear<y>? yes
*** journal has been deleted ***

Resize inode not valid.  Recreate<y>? yes
Pass 1: Checking inodes, blocks, and sizes
Root inode is not a directory.  Clear<y>? yes
Deleted inode 2905 has zero dtime.  Fix<y>? yes
Deleted inode 2921 has zero dtime.  Fix<y>? yes
Deleted inode 2937 has zero dtime.  Fix<y>? yes
Deleted inode 2953 has zero dtime.  Fix<y>? 
Recreate journal<y>? cancelled!
/dev/sdb1: e2fsck canceled.

/dev/sdb1: ***** FILE SYSTEM WAS MODIFIED *****
#但是这里要每个都要你确定

[root@rocky8 ~]# fsck.ext4 /dev/sdb1 -y
e2fsck 1.45.6 (20-Mar-2020)
/dev/sdb1 was not cleanly unmounted, check forced.
Resize inode not valid.  Recreate? yes

Pass 1: Checking inodes, blocks, and sizes
Root inode is not a directory.  Clear? yes

Deleted inode 2953 has zero dtime.  Fix? yes

Deleted inode 2969 has zero dtime.  Fix? yes

Deleted inode 2985 has zero dtime.  Fix? yes

Deleted inode 3001 has zero dtime.  Fix? yes

Deleted inode 3017 has zero dtime.  Fix? yes

Deleted inode 3033 has zero dtime.  Fix? yes
...

[root@rocky8 ~]# fsck.ext4 /dev/sdb1
e2fsck 1.45.6 (20-Mar-2020)
/dev/sdb1: clean, 11/65536 files, 19559/1048576 blocks
#再次检查就正常了

#修复文件系统,一定要取消挂载
#xfs 文件系统用xfs_repair工具修复,fsck.xfs 这个工具也可以修复 xfs

[root@rocky8 ~]# fsck.xfs /dev/sdb2
If you wish to check the consistency of an XFS filesystem or
repair a damaged filesystem, see xfs_repair(8).
#推荐使用 xfs_repair工具修复

[root@rocky8 ~]# xfs_repair /dev/sdb2
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan and clear agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
Phase 5 - rebuild AG headers and trees...
        - reset superblock...
Phase 6 - check inode connectivity...
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done

[root@rocky8 ~]# fsck.ext4 --help
fsck.ext4: invalid option -- '-'
Usage: fsck.ext4 [-panyrcdfktvDFV] [-b superblock] [-B blocksize]
		[-l|-L bad_blocks_file] [-C fd] [-j external_journal]
		[-E extended-options] [-z undo_file] device

Emergency help:
 -p                   Automatic repair (no questions)
 -n                   Make no changes to the filesystem
 -y                   Assume "yes" to all questions
 -c                   Check for bad blocks and add them to the badblock list
 -f                   Force checking even if filesystem is marked clean
 -v                   Be verbose
 -b superblock        Use alternative superblock
 -B blocksize         Force blocksize when looking for superblock
 -j external_journal  Set location of the external journal
 -l bad_blocks_file   Add to badblocks list
 -L bad_blocks_file   Set badblocks list
 -z undo_file         Create an undo file

#fsck.ext4 和fsck -t ext4  命令是一样的

范例:修改破坏的ext文件系统

[root@rocky8 ~]# mount /dev/sdb2 /mnt
[root@rocky8 ~]# cp /etc/fstab /mnt/f1
[root@rocky8 ~]# cp /etc/fstab /mnt/f2
[root@rocky8 ~]# ls /mnt
f1  f2
[root@rocky8 ~]# dd if=/dev/zero of=/dev/sdb2 bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00148955 s, 704 MB/s
[root@rocky8 ~]# ls /mnt
f1  f2
[root@rocky8 ~]# tune2fs -l /dev/sdb2
tune2fs 1.45.6 (20-Mar-2020)
tune2fs: Bad magic number in super-block while trying to open /dev/sdb2
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633892 102172508   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47612   2039300   3% /mnt

#必须取消挂载后再做文件系统的修复
[root@centos8 ~]#umount /mnt

[root@rocky8 ~]# xfs_repair -L /dev/sdb2
Phase 1 - find and verify superblock...
sb realtime bitmap inode 18446744073709551615 (NULLFSINO) inconsistent with calculated value 129
resetting superblock realtime bitmap ino pointer to 129
sb realtime summary inode 18446744073709551615 (NULLFSINO) inconsistent with calculated value 130
resetting superblock realtime summary ino pointer to 130
Phase 2 - using internal log
        - zero log...
ALERT: The filesystem has valuable metadata changes in a log which is being
destroyed because the -L option was used.
        - scan filesystem freespace and inode maps...
Metadata CRC error detected at 0x561a9d8661d2, xfs_agf block 0x1/0x200
Metadata CRC error detected at 0x561a9d892f02, xfs_agi block 0x2/0x200
bad magic # 0x0 for agf 0
bad version # 0 for agf 0
bad length 0 for agf 0, should be 131072
bad uuid 00000000-0000-0000-0000-000000000000 for agf 0
...
Phase 5 - rebuild AG headers and trees...
        - reset superblock...
Phase 6 - check inode connectivity...
reinitializing root directory
reinitializing realtime bitmap inode
reinitializing realtime summary inode
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done

[root@rocky8 ~]# xfs_info /dev/sdb2
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=524288, 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@rocky8 ~]# mount /dev/sdb2 /mnt
[root@rocky8 ~]# ls /mnt
#文件丢失

标签:00,blocks,32,文件系统,dev,csum,磁盘,512,inodes
来源: https://blog.csdn.net/qq_25599925/article/details/120834665