闲者博客 - 系统盘
https://bk1314.com/tag/%E7%B3%BB%E7%BB%9F%E7%9B%98/
-
nokvm开的虚拟机系统盘扩容
https://bk1314.com/30.html
2022-02-23T23:07:00+08:00
一.宿主机扩容虚拟机系统盘**环境 文件系统CentOS 7 XFS1.1查看虚拟机(以下操作在宿主机上)**[root@office-prd-kvm-01 ~]# virsh list
4 office-com-ldap-01 running1.2查看虚拟机系统盘[root@office-prd-kvm-01 ~]# virsh domblklist office-com-ldap-01
目标 源
------------------------------------------------
vda /home/office-com-ldap-01/office-com-ldap-01.system.qcow2
hda 1.3原始系统盘大小[root@office-prd-kvm-01 ~]# qemu-img info /home/office-com-ldap-01/office-com-ldap-01.system.qcow2
virtual size: 15G (16106127360 bytes)
#很重要要先关闭虚拟机
[root@office-prd-kvm-01 ~]# virsh shutdown office-com-ldap-01
1.4扩容磁盘[root@office-prd-kvm-01 ~]# qemu-img resize /home/office-com-ldap-01/office-com-ldap-01.system.qcow2 +5G
[root@office-prd-kvm-01 ~]# qemu-img info /home/office-com-ldap-01/office-com-ldap-01.system.qcow2
virtual size: 20G (21474836480 bytes)
[root@office-prd-kvm-01 ~]# virsh start office-com-ldap-01二.虚拟机内查看(以下操作在kvm虚拟机中)2.1查看是否增加[root@office-prd-kvm-01 ~]# lsblk2.2给未分配的空间分区[root@office-prd-kvm-01 ~]# fdisk /dev/vda命令(输入 m 获取帮助):n
Select (default p):p
命令(输入 m 获取帮助):t
Hex 代码(输入 L列出所有代码):l
Hex代码 (输入 L 列出所有代码):8e
命令(输入 m 获取帮助):p
命令(输入 m 获取帮助):w2.3刷新分区表[root@office-com-ldap-01 ~]# partprobe 2.4添加到卷组(dev/centos/root)[root@office-com-ldap-01 ~]# pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created.
[root@office-com-ldap-01 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 centos lvm2 a-- <9.00g 0
/dev/vda3 lvm2 --- 5.00g 5.00g
[root@office-com-ldap-01 ~]# vgextend centos /dev/vda3
Volume group "centos" successfully extended
[root@office-com-ldap-01 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 13.99g <5.00g
[root@office-com-ldap-01 ~]# lvextend -l +100%FREE /dev/mapper/centos-root
New size given (1279 extents) not larger than existing size (2047 extents)
[root@office-com-ldap-01 ~]# xfs_growfs /dev/mapper/centos-root
[root@office-com-ldap-01 ~]# df -Th
[post cid="32" /]