云服务器磁盘LVM扩容:新增硬盘场景实战指南

背景介绍

随着业务增长,云服务器磁盘空间不足是常见问题。LVM(Logical Volume Manager)通过灵活管理物理磁盘和逻辑卷,支持动态扩容,避免了传统分区的局限性。本文以 新增硬盘扩容LVM卷组 为例,分步骤详解操作流程

前提条件

  • 云平台新增硬盘
  • 需要扩容的原分区已经采用了LVM进行管理

场景设计

首先看挂载信息,本次需要扩容的是挂载到 /mnt的分区

然后看磁盘信息


vdd磁盘则是本次需要用来扩容的新磁盘

操作步骤

分区

root@Debian12:~# fdisk /dev/vdd

Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0x1a7332c5.

Command (m for help): g
Created a new GPT disklabel (GUID: 746D7920-B943-F742-95EC-D5C695D02157).

Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-20971486, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971486, default 20969471): 

Created a new partition 1 of type 'Linux filesystem' and of size 10 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@Debian12:~# 

首先根据常规分区流程,对vdd磁盘进行分区划分


从结果看,我们已经得到了一个 vdd1的分区

创建PV

pvcreate /dev/vdd1 #创建PV


PV创建完成之后,就可以将这个PV放到需要扩容的VG里面


加入VG

vgextend doc /dev/vdd1 # 扩容VG



执行完成之后,我们可以看到目前doc的VG池空闲容量变成了10G,总容量也达到了20GB,下面开始分区扩容

扩容LV(分区)


lvextend -l +100%FREE /dev/mapper/doc-data  # 将VG所有空间分配给 doc-data

如果只是想扩指定容量可以使用下面的命令

lvextend -L + 10G /dev/mapper/doc-data  # 将10GB分配给 doc-data

从图中可以看到,此时LV前后容量已经发生了变化,下面继续看挂载信息


虽然LV已经扩容,但是这个时候的挂载信息还是没有变化,需要对其进行刷新

刷新挂载分区大小


仅限EXT2\3\4文件系统使用,其他文件系统请参考这篇文章云服务器磁盘LVM扩容-单硬盘多分区场景

resize2fs /dev/mapper/doc-data  # 仅限EXT2\3\4文件系统使用


这时候可以看到,挂载信息已经显示扩容后的大小,扩容到这步就完成了

原文链接:,转发请注明来源!