【CentOS】给OA的应用服务器扩容(先分区扩容,再扩展逻辑卷,最后扩展文件系统大小步骤)

先分区扩容,再扩展逻辑卷,最后扩展文件系统大小步骤

背景:

同事反馈,OA应用服务器的磁盘空间不足,使用率已经达到99%,经检查发现磁盘空间足够(vda总大小 ​​600G​​,vda2分区已用 ​​402G​​),剩余约 ​​198G​​ 未分配(600G - 402G),故对vda2分区进行扩容。

步骤 1:检查当前分区信息

sudo fdisk -l /dev/vda

记录 vda2起始扇区(Start)(如 2099200)。

[root@localhost ~]# sudo fdisk -l /dev/vda

Disk /dev/vda: 644.2 GB, 644245094400 bytes, 1258291200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000acbb5

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 845162495 421531648 8e Linux LVM

步骤 2:删除并重建 vda2分区

sudo fdisk /dev/vda
  1. 输入 d2删除 vda2不会影响数据,LVM 元数据独立于分区表)。
  2. 输入 np2重建分区:起始扇区必须与原分区一致(如 2099200)。结束扇区按回车(默认占满剩余空间)。
  3. 输入 t28e设置类型为 Linux LVM
  4. 输入 w保存并退出。

[root@localhost ~]# sudo fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/vda: 644.2 GB, 644245094400 bytes, 1258291200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000acbb5

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 845162495 421531648 8e Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-1258291199, default 2099200): 2099200
Last sector, +sectors or +size{K,M,G} (2099200-1258291199, default 1258291199):
Using default value 1258291199
Partition 2 of type Linux and of size 599 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

步骤 3:刷新分区表

sudo partprobe /dev/vda

步骤 4:扩展 LVM 物理卷(PV)

sudo pvresize /dev/vda2

验证剩余空间:

sudo pvdisplay | grep "Free PE"

步骤 5:扩展逻辑卷(LV)和文件系统

# 扩展逻辑卷
sudo lvextend -l +100%FREE /dev/centos/root

# 确保逻辑卷已扩展
sudo lvdisplay /dev/centos/root  # 检查 LV Size

# 确认文件系统类型
lsblk -f /dev/mapper/centos-root

# 扩展文件系统(根据类型选择,类型为XFS)
sudo xfs_growfs /         # XFS 文件系统

步骤 6:验证结果

df -h /

lsblk

确认 / 容量已增加,且服务正常运行。

posted @ 2025-09-18 11:43  K89  阅读(13)  评论(0)    收藏  举报