最近更新时间 2020-01-22 13:20:16


1. 查看磁盘分区情况。

df -lh
Filesystem  Size  Used Avail Use% Mounted on
devtmpfs    388M     0  388M   0% /dev
tmpfs       405M     0  405M   0% /dev/shm
tmpfs       405M  5.8M  399M   2% /run
tmpfs       405M     0  405M   0% /sys/fs/cgroup
/dev/...    8.0G  1.9G  6.2G  24% /
/dev/sda1   976M  139M  771M  16% /boot

2. 查看硬盘状态,包括未格式化硬盘。

fdisk -l
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

显示有一块 20G 的新硬盘未格式化。

3. 添加新分区。

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.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x51d6e253.

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): 

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

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


  • n  回车。
  • p  回车。
  • 1  回车。
  • 连续两次回车。
  • w  回车。


fdisk -l
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x86aa11ed

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1  2048 41943039 41940992  20G 83 Linux

4. 格式化分区。

mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512    agcount=4, agsize=1310656 blks
         =  sectsz=512   attr=2, projid32bit=1
         =  crc=1        finobt=1, sparse=1, rmapbt=0
         =  ....
realtime =none extsz=4096   blocks=0, rtextents=0

CentOS 8已经把 xfs 作为默认文件系统。

5. 挂载硬盘。

mkdir /data
mount /dev/sdb1 /data

设置开机自动挂载,编辑 /etc/fstab 文件。

echo "/dev/sdb1 /data xfs defaults 0 0">>/etc/fstab