Linux 磁盘目录扩容记录一则

前言

今天 RMAN 备份恢复的时候发现磁盘空间不足了:

bash 复制代码
ORA-19502: write error on file "/oradata/rpt/tbs_ods04.dbf", block number 2921152 (block size=8192)
ORA-27072: File I/O error
Linux-x86_64 Error: 28: No space left on device
Additional information: 4
Additional information: 2921152
Additional information: -1

看一下磁盘空间:

bash 复制代码
[oracle@lucifer:/home/oracle]$ df -h 
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                  16G     0   16G   0% /dev
tmpfs                     32G     0   32G   0% /dev/shm
tmpfs                     16G   25M   16G   1% /run
tmpfs                     16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root 1008G  982G   26G  98% /
/dev/sda2               1014M  142M  873M  14% /boot
/dev/sda1                200M   12M  189M   6% /boot/efi
tmpfs                    3.2G     0  3.2G   0% /run/user/0

根目录空间不够用了,需要扩容,这是一台虚拟机,找系统工程师加了 1T 空间,手动在系统上进行扩容,记录一下操作过程。

根目录扩容

虚拟化加完空间后,需要重启主机生效:

bash 复制代码
## reboot 之前
[oracle@lucifer:/home/oracle]$ lsblk
NAME            MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
sda               8:0    0      1T  0 disk
├─sda1            8:1    0    200M  0 part /boot/efi
├─sda2            8:2    0      1G  0 part /boot
└─sda3            8:3    0 1022.8G  0 part
  ├─centos-root 253:0    0 1007.1G  0 lvm  /
  └─centos-swap 253:1    0   15.8G  0 lvm  [SWAP]
sr0              11:0    1    1.2M  0 rom

## reboot 之后
[root@lucifer:/root]# lsblk
NAME            MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
sda               8:0    0      2T  0 disk
├─sda1            8:1    0    200M  0 part /boot/efi
├─sda2            8:2    0      1G  0 part /boot
└─sda3            8:3    0 1022.8G  0 part
  ├─centos-root 253:0    0 1007.1G  0 lvm  /
  └─centos-swap 253:1    0   15.8G  0 lvm  [SWAP]
sr0              11:0    1    1.2M  0 rom

可以看到磁盘空间已经加到 /dev/sda 上,现在是 2T,但是需要扩容到根目录上,还需要操作下,本文使用 parted 命令进行扩容。

扩展GPT分区:

bash 复制代码
## 修复 GPT 备份表位置,扩展分区 3 到磁盘末尾
[root@lucifer:/root]# parted /dev/sda resizepart 3 100%
Error: The backup GPT table is not at the end of the disk, as it should be.  This might mean that another operating system believes the disk is smaller.  Fix, by moving the backup to the end (and
removing the old backup)?
parted: invalid token: 3
Fix/Ignore/Cancel? Fix
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 2147483648 blocks) or continue with the current setting?
Fix/Ignore? Fix
Partition number? 3
End?  [1100GB]? 100%
Information: You may need to update /etc/fstab.

刷新分区表:

bash 复制代码
## 通知内核分区表已变更
[root@lucifer:/root]# partprobe /dev/sda

[root@lucifer:/root]# lsblk
NAME            MAJ:MIN RM    SIZE RO TYPE MOUNTPOINT
sda               8:0    0      2T  0 disk
├─sda1            8:1    0    200M  0 part /boot/efi
├─sda2            8:2    0      1G  0 part /boot
└─sda3            8:3    0      2T  0 part
  ├─centos-root 253:0    0 1007.1G  0 lvm  /
  └─centos-swap 253:1    0   15.8G  0 lvm  [SWAP]
sr0              11:0    1    1.2M  0 rom

扩展物理卷:

bash 复制代码
## 让 LVM 识别新的分区大小
[root@lucifer:/root]# pvresize /dev/sda3
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

扩展逻辑卷:

bash 复制代码
## 使用所有可用空间扩展根分区逻辑卷
[root@lucifer:/root]#  lvextend -l +100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from 1007.05 GiB (257805 extents) to 1.98 TiB (519949 extents).
  Logical volume centos/root successfully resized.

扩展文件系统:

bash 复制代码
## 在线扩展XFS文件系统
[root@lucifer:/root]# xfs_growfs /
meta-data=/dev/mapper/centos-root isize=512    agcount=81, agsize=3276800 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=263992320, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 263992320 to 532427776

验证结果:

bash 复制代码
[root@lucifer:/root]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                  16G     0   16G   0% /dev
tmpfs                     32G     0   32G   0% /dev/shm
tmpfs                     16G  8.4M   16G   1% /run
tmpfs                     16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-root  2.0T  711G  1.3T  35% /
/dev/sda2               1014M  142M  873M  14% /boot
/dev/sda1                200M   12M  189M   6% /boot/efi
tmpfs                    3.2G     0  3.2G   0% /run/user/0

[root@lucifer:/root]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0    2T  0 disk
├─sda1            8:1    0  200M  0 part /boot/efi
├─sda2            8:2    0    1G  0 part /boot
└─sda3            8:3    0    2T  0 part
  ├─centos-root 253:0    0    2T  0 lvm  /
  └─centos-swap 253:1    0 15.8G  0 lvm  [SWAP]
sr0              11:0    1  1.2M  0 rom

可以看到:根目录从 1008G 成功扩展到 2.0 T。

写在最后

本文比较基础简单,仅做记录参考。


📚 推荐阅读:DBA 学习之路

如果这篇文章对你有帮助,推荐访问我的 Oracle DBA 系统学习站点,涵盖 100 天完整学习路线:

  • 🔧 Oracle 安装部署 · RMAN 备份恢复 · Data Pump 数据迁移
  • 🏗️ RAC 高可用 · DataGuard 容灾 · 多租户架构
  • 🔍 故障排查 · 升级迁移 · GoldenGate 数据同步

👉 立即访问 ora100.com →

相关推荐
candyTong1 小时前
Claude Code Agent Teams:多 Agent 协作的生命周期与实现机制
后端·架构
IT_陈寒6 小时前
为什么你应该学习JavaScript?
前端·人工智能·后端
淇奥76 小时前
【MyBatis-Plus】MyBatis-Plus 学习笔记
后端
_code_bear_6 小时前
OpenSpec CLI 与 OPSX 工作流说明
前端·后端·架构
用户8356290780517 小时前
使用 Python 在 PowerPoint 中添加并控制音频播放
后端·python
用户8356290780517 小时前
使用 Python 在 PowerPoint 中生成并自定义饼图与环形图
后端·python
念何架构之路7 小时前
Go语言常见并发模式
开发语言·后端·golang
Cosolar7 小时前
大模型应用开发面试 • 第4期|A2A、复杂挑战与具身智能
人工智能·后端·面试
迷渡8 小时前
聊一聊 Bun 用 Rust 重写这件事
开发语言·后端·rust
王中阳Go8 小时前
秒杀、分库分表、全链路追踪:一个电商微服务的架构全拆解
后端·go