4

使用growpart扩容分区

 1 year ago
source link: https://www.bboy.app/2022/06/29/%E4%BD%BF%E7%94%A8growpart%E6%89%A9%E5%AE%B9%E5%88%86%E5%8C%BA/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用growpart扩容分区

2022-06-29linux

20220629-1.webp

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

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

[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors

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

重启机器之后查看修改之后的磁盘大小

[root@localhost ~]# 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大小

[root@localhost ~]# 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

调整物理卷大小

[root@localhost ~]# pvresize /dev/sda3 
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

查看物理卷大小

[root@localhost ~]# 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了,扩容逻辑卷

查看逻辑卷大小

[root@localhost ~]# 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

最后查看容量

[root@localhost ~]# 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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK