本文基于centos7进行磁盘扩容
1.查看原有磁盘大小
查看新的磁盘空间是否已经分配
fdisk -l //可以查看空间大小是否已经分配,分配后进行下一步
如果是虚拟机可以使用下图方式进行扩容
对新空间进行分区
fdisk /dev/sda
输入m ,可以查看帮助信息
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
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
增加新的分区
command (m for help):n
选择基本信息分区,输入:p
Command (m for help): n
Command action
e extended
p primary partition (1-4)
回车
First cylinder (1-15908,default 1):Enter
(这是回车是指分的默认大小)
写入并退出
command (m for help):w
完成后,如果提示:
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)
就重启一下系统识别该磁盘空间
为新分配的空间创建一个新的物理卷
键入命令:pvcreate /dev/sda3
如果提示sda3找不到,键入:partprobe或者重启虚拟机
查询创建的物理卷
可以查到本机物理卷名称为“centos”
使用新增物理卷扩展本地物理卷
扩展 LVM 的逻辑卷 centos-root
键入命令:lvextend -L +1G 加上要扩展的分区名
lvextend -L +1G /dev/centos/root
调整逻辑卷的大小
此时系统还不认识刚刚添加进来的磁盘的文件系统,所以还需要对文件系统进行扩容。
键入:xfs_growfs 加上要扩展的分区名
或者
resize2fs – f 加 上要扩展的分区名
结束