CentOS 7服务器调整root与home分区容量方案(不影响服务)
一、操作前提与风险控制
二、操作流程(无需重启服务)
备份/home数据(强制) 避免数据丢失,执行以下命令:
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"}
查看分区状态 确认逻辑卷分布与文件系统类型:
df -Th # 查看挂载点与容量
lvdisplay # 检查逻辑卷详细信息(如VG名称、空闲空间):ml-citation{ref="1,2" data="citationList"}
卸载/home分区 终止占用进程并卸载:
fuser -km /home # 强制终止/home下的进程:ml-citation{ref="3,5" data="citationList"}
umount /home # 卸载分区:ml-citation{ref="2,3" data="citationList"}
删除home逻辑卷 释放空间至卷组(VG):
lvremove /dev/centos/home # 确认操作后输入y:ml-citation{ref="1,2" data="citationList"}
vgdisplay # 验证VG空闲空间是否增加:ml-citation{ref="1,5" data="citationList"}
扩展根分区 分配空闲空间并生效扩容:
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"}
(可选)重建/home分区 若需保留/home,按需新建逻辑卷:
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"}
三、验证与恢复
检查分区状态
df -Th # 确认root分区扩容成功:ml-citation{ref="2,5" data="citationList"}
恢复/home数据(若重建)
tar -xzvf /tmp/home_backup.tar.gz -C / # 解压备份数据:ml-citation{ref="4,6" data="citationList"}
更新/etc/fstab(重要) 若重建/home分区,需添加挂载配置防止重启失效:
echo "/dev/mapper/centos-home /home xfs defaults 0 0" >> /etc/fstab:ml-citation{ref="3,5" data="citationList"}
四、注意事项
操作耗时参考:数据备份与恢复占主要时间,分区调整通常在10分钟内完成。
评论前必须登录!
注册