KVM虚拟机根目录扩容
# 1. 虚拟机查看磁盘
[root@k8s-node02 ~] lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda2 8:2 0 199G 0 part
│ ├─centos-opt 253:1 0 130G 0 lvm /opt
│ └─centos-root 253:0 0 69G 0 lvm /
└─sda1 8:1 0 1G 0 part /boot
1
2
3
4
5
6
7
2
3
4
5
6
7
# 2. 宿主机执行命令
# 2.1 创建磁盘
qemu-img create -f qcow2 /vm/expand-disk/k8s-node02-data.img 100G
1
# 2.2 将磁盘添加到虚拟机
virsh attach-disk k8s-node02-33.222 --source /vm/expand-disk/k8s-node02-data.img --target sdc --subdriver qcow2 --persistent
1
# 3. 虚拟机执行命令
# 3.1 查看磁盘
[root@k8s-node02 ~] lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 100G 0 disk
sda 8:0 0 200G 0 disk
├─sda2 8:2 0 199G 0 part
│ ├─centos-opt 253:1 0 130G 0 lvm /opt
│ └─centos-root 253:0 0 69G 0 lvm /
└─sda1 8:1 0 1G 0 part /boot
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 3.2 磁盘进行分区
fdisk /dev/sdb
1
# 3.3 分区查看
[root@k8s-node02 ~] lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 100G 0 part
sda 8:0 0 200G 0 disk
├─sda2 8:2 0 199G 0 part
│ ├─centos-opt 253:1 0 130G 0 lvm /opt
│ └─centos-root 253:0 0 69G 0 lvm /
└─sda1 8:1 0 1G 0 part /boot
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 3.4 查看物理卷信息
[root@k8s-node02 ~] pvdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50943 / <199.00 GiB
Free PE / Size 0 / 0
VG UUID wqewxG-dg2m-fV5N-efXg-VlH5-hcoQ-M6yplI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 3.5 扩展卷组
vgextend centos /dev/sdb1
1
# 3.6 再次查看卷组信息
[root@k8s-node02 ~] vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 298.99 GiB
PE Size 4.00 MiB
Total PE 76542
Alloc PE / Size 50943 / <199.00 GiB
Free PE / Size 25599 / <100.00 GiB
VG UUID wqewxG-dg2m-fV5N-efXg-VlH5-hcoQ-M6yplI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 3.7 查看逻辑卷属性
[root@k8s-node02 ~] lvdisplay
--- Logical volume ---
LV Path /dev/centos/opt
LV Name opt
VG Name centos
LV UUID sVxfDn-pquv-A3Zq-9N6E-HnFa-7upm-0s0s2T
LV Write Access read/write
LV Creation host, time localhost, 2021-03-12 13:10:11 +0800
LV Status available
open 1
LV Size 130.00 GiB
Current LE 33280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID rm4gNM-1W5R-jXnc-QxMk-WB2t-fqMI-svFwlK
LV Write Access read/write
LV Creation host, time localhost, 2021-03-12 13:10:13 +0800
LV Status available
open 1
LV Size <69.00 GiB
Current LE 17663
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 3.8 将目前磁盘未分配的空间全部扩展到 /dev/centos/root 分区下
lvextend -l +100%FREE /dev/centos/root
1
# 3.9 查看逻辑卷属性
[root@k8s-node02 ~] lvdisplay
--- Logical volume ---
LV Path /dev/centos/opt
LV Name opt
VG Name centos
LV UUID sVxfDn-pquv-A3Zq-9N6E-HnFa-7upm-0s0s2T
LV Write Access read/write
LV Creation host, time localhost, 2021-03-12 13:10:11 +0800
LV Status available
open 1
LV Size 130.00 GiB
Current LE 33280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID rm4gNM-1W5R-jXnc-QxMk-WB2t-fqMI-svFwlK
LV Write Access read/write
LV Creation host, time localhost, 2021-03-12 13:10:13 +0800
LV Status available
open 1
LV Size 168.99 GiB
Current LE 43262
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 3.10 重新识别分区大小
xfs_growfs /dev/centos/root
1
上次更新: 2025/04/25, 03:40:17