服务器分区调整方案(不影响服务)

CentOS 7服务器调整root与home分区容量方案(不影响服务)

一、操作前提与风险控制
  1. ‌系统要求‌:确认系统为CentOS 7,且使用LVM逻辑卷管理分区‌12。
  2. ‌文件系统类型‌:若根分区和home分区均为XFS(默认类型),仅支持扩容不支持缩容‌45。
  3. ‌服务影响‌:操作需卸载/home分区,建议在业务低峰期执行,并优先备份关键数据‌45。

二、操作流程(无需重启服务)
  1. ‌备份/home数据(强制) ‌

    避免数据丢失,执行以下命令:

    bash 复制代码
    tar -czvf /tmp/home_backup.tar.gz /home  # 压缩备份至/tmp目录‌:ml-citation{ref="4,6" data="citationList"}
    scp /tmp/home_backup.tar.gz user@backup-server:/path  # 传输至外部存储‌:ml-citation{ref="4" data="citationList"}
  2. ‌查看分区状态 ‌

    确认逻辑卷分布与文件系统类型:

    bash 复制代码
    df -Th  # 查看挂载点与容量
    lvdisplay  # 检查逻辑卷详细信息(如VG名称、空闲空间)‌:ml-citation{ref="1,2" data="citationList"}
  3. ‌卸载/home分区 ‌

    终止占用进程并卸载:

    bash 复制代码
    fuser -km /home  # 强制终止/home下的进程‌:ml-citation{ref="3,5" data="citationList"}
    umount /home  # 卸载分区‌:ml-citation{ref="2,3" data="citationList"}
  4. ‌删除home逻辑卷 ‌

    释放空间至卷组(VG):

    bash 复制代码
    lvremove /dev/centos/home  # 确认操作后输入y‌:ml-citation{ref="1,2" data="citationList"}
    vgdisplay  # 验证VG空闲空间是否增加‌:ml-citation{ref="1,5" data="citationList"}
  5. ‌扩展根分区 ‌

    分配空闲空间并生效扩容:

    bash 复制代码
    lvextend -l +100%free /dev/centos/root  # 将全部空闲空间分配给root‌:ml-citation{ref="1,5" data="citationList"}
    xfs_growfs /dev/centos/root  # 仅适用于XFS文件系统‌:ml-citation{ref="1,4" data="citationList"}
  6. ‌**(可选)重建/home分区** ‌

    若需保留/home,按需新建逻辑卷:

    bash 复制代码
    lvcreate -L 200G -n home centos  # 分配指定容量(如200G)‌:ml-citation{ref="5" data="citationList"}
    mkfs.xfs /dev/centos/home  # 格式化
    mount /dev/centos/home /home  # 临时挂载‌:ml-citation{ref="5" data="citationList"}

三、验证与恢复
  1. ‌检查分区状态‌

    bash 复制代码
    df -Th # 确认root分区扩容成功‌:ml-citation{ref="2,5" data="citationList"}
  2. ‌**恢复/home数据(若重建)**‌

    bash 复制代码
    tar -xzvf /tmp/home_backup.tar.gz -C /  # 解压备份数据‌:ml-citation{ref="4,6" data="citationList"}
  3. ‌更新/etc/fstab(重要) ‌

    若重建/home分区,需添加挂载配置防止重启失效:

    bash 复制代码
    echo "/dev/mapper/centos-home /home xfs defaults 0 0" >> /etc/fstab‌:ml-citation{ref="3,5" data="citationList"}

四、注意事项
  1. ‌XFS限制 ‌:XFS文件系统扩容后需立即执行xfs_growfs,否则容量不生效‌14。
  2. ‌服务中断风险‌:卸载/home时可能影响依赖/home路径的服务,建议提前通知或暂存临时文件至其他目录‌34。
  3. ‌LVM灵活性 ‌:若需动态调整(如保留部分home空间),可使用lvresize结合xfs_growfs分阶段操作‌45。

‌操作耗时参考‌:数据备份与恢复占主要时间,分区调整通常在10分钟内完成。

相关推荐
yyuuuzz1 小时前
跨境电商云服务器,五个店铺挤一台机器
运维·服务器·人工智能·云服务器
鲁邦通物联网1 小时前
AMR到站未出梯的机器人梯控故障归属分析与分段诊断方法
运维·网络·机器人·机器人梯控·agv梯控·非侵入式采集·机器人乘梯
CoderYanger1 小时前
Java EE 进阶:15. Linux基本使用和程序部署(第二弹):部署 Web 项目到 Linux
linux·服务器·数据库·spring boot·spring·阿里云·java-ee
1024+2 小时前
Ubuntu 系统设置虚拟内存
linux·运维·ubuntu
加搜科技观察2 小时前
自动化仓库应该如何选择 WMS 系统?
运维·自动化
天远Date Lab2 小时前
零信任架构实战:基于天远运营商近3个月欠费次数构建自动化通信履约评估网关
运维·人工智能·架构·自动化
飞花漫卷,情随岁迁2 小时前
Linux 排障与性能监控
linux·运维·服务器·网络·数据库·mysql·oracle
ESDWAN2 小时前
AI Agent兴起:从智能问答到企业工作流自动化
运维·人工智能·自动化
fengkai45452 小时前
Python对接LangChain智能体开发(Tool工具调用与 Agent智能体)
运维·开发语言·python·langchain·llm·ai agent·tool
福大大架构师每日一题3 小时前
agno v3.2.1发布:会话压缩、公司文件 API、工具稳定性与模型兼容性全面升级
服务器·网络·数据库