Linux-标准分区_数据盘扩容

【以下操作仅适用于云服务器且未做磁盘阵列】

操作系统为CentOS 7.3 64位,未扩容前的数据盘仅有一个主分区(/dev/vdb1,ext4文件系统),文件系统的挂载点为 /data,文件系统扩容完成后,数据盘仍然只有一个主分区。
1.远程连接实例。
2.运行 umount 命令卸载主分区。
umount /dev/vdb1
#说明 使用 df -h 查看是否卸载成功,如果看不到 /dev/vdb1 的信息表示卸载成功

df -h

使用 fdisk 命令删除原来的分区并创建新分区:
fdisk -l 罗列分区信息并记录扩容前数据盘的最终容量、起始扇区(First sector)位置。
运行命令 fdisk [数据盘设备名] 进入 fdisk 界面。本示例中,命令为 fdisk /dev/vdb。
输入 d 并按回车键,删除原来的分区。
###说明 删除分区不会造成数据盘内数据的丢失。
输入 n 并按回车键,开始创建新的分区。
输入 p 并按回车键,选择创建主分区。因为创建的是一个单分区数据盘,所以只需要创建主分区。
输入第一个可用的扇区编号:为了保证数据的一致性,按回车键采用默认值。
注:如果发现First sector显示的位置和之前记录的不一致,说明之前可能使用 parted 来分区,那么就停止当前的 fdisk 操作,使用 parted 重新操作。
输入最后一个扇区编号:因为这里仅创建一个分区,所以按回车键采用默认值。
输入 wq 并按回车键,开始分区。
[root@VM_0_3_centos ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-62914559, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Using default value 62914559
Partition 1 of type Linux and of size 30 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
注:部分操作系统里,修改分区后可能会重新自动挂载文件系统。建议先执行 df -h 重新查看文件系统空间和使用情况。如果文件系统重新被挂载,执行 umount [文件系统名称] 再次卸载文件系统。
检查文件系统,并变更文件系统大小。
[root@VM_0_3_centos ~]##e2fsck -f /dev/vdb1 # 检查文件系统
[root@VM_0_3_centos ~]##resize2fs /dev/vdb1 # 变更文件系统大小
说明
使用 e2fsck 时,由于系统需要检查并订正文件系统元数据,所以速度较慢、耗时较长,请耐心等待。
正确使用 e2fsck 和 resize2fs 指令,不会造成原有数据丢失。
以下为示例输出结果。
[root@VM_0_3_centos ~]## e2fsck -f /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 11/1835008 files (0.0% non-contiguous), 159218/7339776 blocks
[root@VM_0_3_centos ~]## resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 7864064 (4k) blocks.
The filesystem on /dev/vdb1 is now 7864064 blocks long.
将扩容完成的文件系统挂载到原来的挂载点

#mount /dev/vdb1 /data
查看文件系统空间和使用情况:运行命令 df -h。如果出现扩容后的文件系统信息,说明挂载成功,可以使用扩容后的文件系统了。

注:挂载操作完成后,不需要在控制台上重启实例即可开始使用扩容后的文件系统。

发布了24 篇原创文章 · 获赞 46 · 访问量 670

猜你喜欢

转载自blog.csdn.net/qq_36913644/article/details/104632982