在虚拟机中对磁盘进行扩容后,原系统分区的大小并不会改变,此时,需要对系统分区进行扩容操作。

1、查看所有磁盘及分区

blkid

此处以/dev/sda为例,根据系统环境不同,得到的结果也不相同。

2、创建新分区

fdisk /dev/sda  ## /dev/sda为通过fdisk -l 查看到的物理磁盘(第一行)
Welcome to fdisk
 
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Command (m for help): n  ## n为创建一个新的分区
Partition type:   ## 这里需要选择时创建主分区还是扩展分区,都可以,这里直接选了主分区
   p   primary (2 primary, 0 extended, 2 free)   
   e   extended
Select (default p): p  ## 选择创建一个主分区,主分区只能有4个,编号为1-4,下面的全部直接回车就好了,会自动将剩余所用空间都创建
Partition number (3,4, default 3):   
First sector (104857600-209715199, default 104857600): 
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-209715199, default 209715199): 
Using default value 209715199
Partition 3 of type Linux and of size 50 GiB is set
 
Command (m for help): t   ## t为修改分区类型
Partition number (1-3, default 3): 3  ## 刚才创建的分区编号为3
Hex code (type L to list all codes): 8e  ## 8e就是 lvm格式的分区
Changed type of partition 'Linux' to 'Linux LVM'
 
Command (m for help): w  ## w保存并写入磁盘。
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.

partprobe

3、扩容分区

pvcreate /dev/sda3  ## 创建物理卷
pvdisplay      ## 查看物理卷

vgdisplay      ## 查看卷组 VG Name 为 centos
vgextend centos /dev/sda3   ## 将物理卷加入到卷组
vgdisplay     ## 加入后,再次查看卷组

lvdisplay     ## 查看逻辑卷,逻辑卷名称:LV Path /dev/centos/root
lvextend -l +100%FREE /dev/centos/root  ## 将剩余百分百空间都添加到逻辑卷中

xfs_growfs /dev/centos/root    ## xfs 在线扩容分区
df -h  ## 查看扩容结果

以上操作完成即扩容完成


原文链接地址:http://blog.exsvc.cn/article/centos-mbr-lvm-extend.html
转载请注明:转载自 易科博客 ,谢谢!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注