CentOS 8磁盘管理:分区创建与fstab持久化挂载配置

在Linux服务器运维中,新增数据盘后的分区、格式化与持久化挂载是基础且关键的存储配置操作。本文以CentOS 8环境为例,通过fdisk交互式分区、ext4文件系统创建、/etc/fstab自动挂载配置三个核心步骤,演示从裸盘到可用存储空间的完整初始化流程。包含命令行操作示意图与注意事项解析,适用于服务器存储扩容、云主机数据盘挂载等场景。操作前需要做好数据备份,避免误操作导致数据丢失。

查看磁盘分区状态

1lsblk

230412131903.png

可以看到数据盘/dev/vdb大小为600GB,没有分区。

创建分区与格式化

对/dev/vdb磁盘进行分区,使用fdisk命令

1fdisk /dev/vdb

230412132044.png

230412132429.png

 1
 2Welcome to fdisk (util-linux 2.32.1).
 3Changes will remain in memory only, until you decide to write them.
 4Be careful before using the write command.
 5
 6Device does not contain a recognized partition table.
 7Created a new DOS disklabel with disk identifier 0x0a10f380.
 8
 9Command (m for help): n #输入n创建新分区
10Partition type
11   p   primary (0 primary, 0 extended, 4 free)
12   e   extended (container for logical partitions)
13Select (default p): p #输入p选择主分区
14Partition number (1-4, default 1): 1  #输入1选择分区编号
15First sector (2048-419430399, default 2048):  #回车使用默认值
16Last sector, +sectors or +size{K,M,G,T,P} (2048-419430399, default 419430399):  #回车使用默认值
17
18Created a new partition 1 of type 'Linux' and of size 600 GiB.
19
20Command (m for help): wq  #输入wq保存并退出
21The partition table has been altered.
22Calling ioctl() to re-read partition table.
23Syncing disks.

格式化文件系统并持久化挂载

格式化文件系统,使用mkfs命令

1mkfs.ext4 /dev/vdb1

230412132829.png

持久化挂载

/etc/fstab中添加持久化挂载配置,挂载在/data目录下

1vim /etc/fstab
2
3/dev/vdb1 /data ext4 defaults 0 0

230321110243.png