使用growpart扩容分区

简介

经常碰到就是虚拟机磁盘满然后需要扩容的情况,记录下过程

操作

首先查看当前系统盘的大小

1
2
[[email protected] ~]# fdisk -l /dev/sda
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors

然后在esxi中修改你的磁盘大小比如到200GiB

重新扫描磁盘

命令类似于下面

echo "---" > /sys/class/scsi_device/0\:0\:1\:0/device/rescan

当然你也可以选择去重启机器

1
2
3
4
[[email protected] ~]# fdisk -l
GPT PMBR size mismatch (209715199 != 419430399) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors

安装growpart

yum install cloud-utils-growpart

扩容分区

growpart /dev/sda 3

因为我使用的是rocky linux,在默认安装的时候使用的是lvm,所以首先扩容pv,如果你没有配置lvm,那么直接跳到扩容文件系统

查看目前pv大小

1
2
3
4
5
6
7
8
9
10
11
[[email protected] ~]# pvdisplay 
--- Physical volume ---
PV Name /dev/sda3
VG Name rl
PV Size 98.41 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25193
Free PE 1
Allocated PE 25192
PV UUID TGVCwX-lv6Z-ZPhn-5ffp-KO7j-poBh-CKa92M

调整物理卷大小

1
2
3
[[email protected] ~]# pvresize /dev/sda3 
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

查看物理卷大小

1
2
3
4
5
6
7
8
9
10
11
[[email protected] ~]# pvdisplay 
--- Physical volume ---
PV Name /dev/sda3
VG Name rl
PV Size 198.41 GiB / not usable 1.98 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 50793
Free PE 25601
Allocated PE 25192
PV UUID TGVCwX-lv6Z-ZPhn-5ffp-KO7j-poBh-CKa92M

已经200g了,扩容逻辑卷

查看逻辑卷大小

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
[[email protected] ~]# lvdisplay 
--- Logical volume ---
LV Path /dev/rl/swap
LV Name swap
VG Name rl
LV UUID PO9f7n-7DJH-xv8z-vZNp-4Nm3-4S16-OCOrlk
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-03-08 21:11:54 +0800
LV Status available
# open 2
LV Size <7.88 GiB
Current LE 2016
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/rl/root
LV Name root
VG Name rl
LV UUID YhzOQ2-uNmL-QHKx-NU3o-iSbo-GgTI-dMeDCs
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-03-08 21:11:54 +0800
LV Status available
# open 1
LV Size 90.53 GiB
Current LE 23176
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

扩容逻辑卷

lvextend -l +100%FREE /dev/rl/root

最后扩容文件系统

xfs_growfs /dev/mapper/rl-root

最后查看容量

1
2
3
4
5
6
7
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs 7.7G 11M 7.7G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/rl-root 191G 28G 163G 15% /

欢迎关注我的博客www.bboy.app

Have Fun

欢迎关注我的其它发布渠道