- 先检查linux系统版本,这里以CentOS 7 为例,不同的系统版本可能略有不同
cat /etc/redhat-release
- 查看当前 挂载的文件系统
df -hT
查看到当前文件系统是xfs,此时root分区容量初始只有50G,我们将从home分区中减少一部分容量给root使用
Filesystem Type Size Used Avail Use% Mounted on
...
/dev/mapper/centos-root xfs 50G 50G 340M 100% /
/dev/mapper/centos-home xfs 142G 42M 142G 1% /home
...
- 备份原数据
xfsdump -f /tmp/home.dump /home
备份时,需要填写session和media
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> home_session
session label entered: "home_session"
--------------------------------- end dialog ---------------------------------
...
...
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> home_media
media label entered: "home_media"
--------------------------------- end dialog ---------------------------------
...
...
xfsdump: Dump Status: SUCCESS
备份成功后,将在/tmp下生成home.dump home_media home_session这三个文件
- 卸载home分区
umount /home
- 移除centos-home分区
lvremove /dev/centos/home
- 重新创建home分区,分配较小的容量,空余的容量将给root进行扩容
lvcreate -L 41.12G -n home centos
- 使用XFS格式化home分区
mkfs.xfs -f /dev/centos/home
- 重新挂载home
mount /dev/centos/home /home
- 恢复数据
xfsrestore -f /tmp/home.dump /home
- 将空余的100G增加给root
lvextend -L +100G /dev/mapper/centos-root //增加100G
xfs_growfs /dev/mapper/centos-root //执行调整
# 再次查看文件系统
df -h
# --- --- ---
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 150G 50G 100G 25% /
overlay 150G 50G 100G 25% /var/lib/docker/overlay2/xxx/merged