CentOS扩容LVM系统盘
目的
在系统运维中,遇到磁盘空间不足的情况时,往往需要对磁盘进行扩容。一种方式是新增磁盘,一种方式磁盘扩容。前者较为简单,已有相关内容。本次就说一下系统盘单盘扩容的方法。
过程
以下使用CentOS8.5环境下的GPT格式磁盘
扩容对象为/dev/nvme0n1,容量有20G扩容为50G
扩盘前状态
[root@elastic ~]# pvscan PV /dev/nvme0n1p3 VG cl lvm2 [18.41 GiB / 0 free] Total: 1 [18.41 GiB] / in use: 1 [18.41 GiB] / in no VG: 0 [0 ] # 注意使用parted来查看硬盘状态,而不应当使用fdisk,因为下述使用GPT分区。 [root@elastic ~]# parted -l Model: NVMe Device (nvme) Disk /dev/nvme0n1: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 630MB 629MB fat32 EFI System Partition boot, esp 2 630MB 1704MB 1074MB xfs 3 1704MB 21.5GB 19.8GB
扩展分区
# 安装分区扩容工具 yum install -y cloud-utils-growpart.noarch # growpart 扩容对象 分区编号 (参见上述parted -l的结果) growpart /dev/nvme0n1 3 # 查看结果 [root@elastic ~]# parted -l Model: NVMe Device (nvme) Disk /dev/nvme0n1: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 630MB 629MB fat32 EFI System Partition boot, esp 2 630MB 1704MB 1074MB xfs 3 1704MB 53.7GB 52.0GB
扩展LVM
[root@elastic ~]# pvresize /dev/nvme0n1p3 Physical volume "/dev/nvme0n1p3" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized [root@elastic ~]# pvs PV VG Fmt Attr PSize PFree /dev/nvme0n1p3 cl lvm2 a-- 48.41g 30.00g [root@elastic ~]# lvextend -l +100%free /dev/cl/root Size of logical volume cl/root changed from 30.00 GiB (7680 extents) to 46.41 GiB (11881 extents). Logical volume cl/root successfully resized. [root@elastic ~]# pvs PV VG Fmt Attr PSize PFree /dev/nvme0n1p3 cl lvm2 a-- 48.41g 0 [root@elastic ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- 46.41g swap cl -wi-ao---- 2.00g
收尾
[root@elastic ~]# xfs_growfs /dev/cl/root
总结
- GPT分区工具使用parted,而MBR分区使用fdisk
- LVM管理的PV是分区,如果没有growpart,则需要新建分区再加入对应VG
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.