当机器原来只有100G,现在多加了一块200G的磁盘,(或者原来虚拟机的100G磁盘不够了,在设置中多添加了200G),这个时候fdisk -l可以看到全量是300G,但是活跃的只有100G,df -h看到的也只有100G,这个时候怎么办呢?
第一步,创建新的分区
fdisk -l可以看到原来只有sda1和sda2这2个分区,这时我们创建第三个分区,使用命令fdisk /dev/sda
进入该设备。此时出现:
Command (m for help):
查看帮助信息:输入m,看到如下信息
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition 注:这是删除一个分区的动作;
l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition's system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;
具体每个参数的含义,请仔细阅读。常用的就是:d l m p q t w
2、列出当前操作硬盘的分区情况,用p
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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
Disk label type: dos
Disk identifier: 0x000ea964
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
Command (m for help): n 注:添加分区
Partition type:
p primary (1 primary, 0 extended, 3 free) 注:1个主分区,3个空闲分区总共四个主分区
e extended
Select (default p): p 注:添加主分区,默认主分区;
w保存
这个时候会新增新的主分区sda3,需要重启reboot一下,才能在/dev目录下显示
第二步:创建物理卷
pvcreate /dev/sda3
第三步:将物理卷添加到逻辑卷
vgscan
vgextend centos(自己的名字) /dev/sda3
lvscan
lvextend -L +100G /dev/centos/root
lvextend -L +99G /dev/centos/home
resize2fs /dev/centos/root (有的系统这步不需要)
resize2fs /dev/centos/home(有的系统这步不需要)
到这里基本磁盘扩容已经基本完成。
但是df -h还是看不到的
这个时候需要做文件系统的扩容了
第四步:文件系统扩容
mount
xfs_growfs -d /home/
xfs_growfs -d /
然后查看df -h就有了
这个时候扩容完成
本文详细介绍了如何在CentOS系统中进行磁盘扩容和文件系统扩容的步骤,包括创建新分区、创建物理卷、将物理卷添加到逻辑卷以及扩展文件系统,以解决磁盘空间不足的问题。
4074





