kvm虚拟机centos8磁盘扩容

通过PVE搭建虚拟机,系统盘只有30G,发现使用的时候已经不足,需要进行扩容,

虚拟机关机状态,在PVE增加磁盘大小之后,虚机开机之后,还需要在虚拟机里面进行扩容操作

kvm虚拟机centos8磁盘扩容_第1张图片

 kvm虚拟机centos8磁盘扩容_第2张图片

 开机检查磁盘大小

lsblk

kvm虚拟机centos8磁盘扩容_第3张图片

[root@localhost ~]# fdisk -l
Disk /dev/vda: 132 GiB, 141733920768 bytes, 276824064 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
Disklabel type: dos
Disk identifier: 0x79cee493

Device     Boot   Start      End  Sectors Size Id Type
/dev/vda1  *       2048  2099199  2097152   1G 83 Linux
/dev/vda2       2099200 67108863 65009664  31G 8e Linux LVM


Disk /dev/mapper/cs-root: 29 GiB, 31079792640 bytes, 60702720 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 /dev/mapper/cs-swap: 2.1 GiB, 2202009600 bytes, 4300800 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

开始扩容

1.创建一个新的分区

依次输入以下指令

n    [添加分区]
p    [主分区]
3    [分区号,回车默认也是3]
默认    [直接回车]
默认    [直接回车]
w    [保存分区]
[root@localhost ~]# fdisk /dev/vda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 
First sector (67108864-276824063, default 67108864): 
Last sector, +sectors or +size{K,M,G,T,P} (67108864-276824063, default 276824063): 

Created a new partition 3 of type 'Linux' and of size 100 GiB.

Command (m for help): w
The partition table has been altered.
Syncing disks.

 可以看到新的分区已经出现了kvm虚拟机centos8磁盘扩容_第4张图片

 2.将vda3分区初始化为物理卷

partprobe
pvcreate /dev/vda3

 3.查看跟分区所在的卷组信息

vgdisplay
# vgs

 kvm虚拟机centos8磁盘扩容_第5张图片

 4.扩容cs卷组

vgextend cs /dev/vda3

kvm虚拟机centos8磁盘扩容_第6张图片

 5.扩容文件系统

lvextend -l +100%FREE /dev/mapper/cs-root

kvm虚拟机centos8磁盘扩容_第7张图片

[root@localhost ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               cs
  PV Size               <31.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              7935
  Free PE               0
  Allocated PE          7935
  PV UUID               Oaojfu-XAyd-ick0-U7nZ-2YFt-VBUk-FGgStv
   
  --- Physical volume ---
  PV Name               /dev/vda3
  VG Name               cs
  PV Size               100.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              25599
  Free PE               0
  Allocated PE          25599
  PV UUID               597ofc-wiTD-8lM3-h2JL-fXlR-alFZ-f12G2n

6.同步文件系统

xfs_growfs /

kvm虚拟机centos8磁盘扩容_第8张图片

 

你可能感兴趣的:(linux,技能,运维,磁盘扩容,虚拟卷扩容,Linux,centos8)