Reducing /home partition size and increasing /root space in CentOS 8
I recently set up a CentOS 8 virtual machine with 127GB of disk space and then realized that /home had been given tens of gigabytes that I did not really need. Since I mainly work as root in this environment, the more practical layout was to shrink /home and give that space back to /root.
This guide records the CentOS 8 LVM workflow for doing that. It differs in a few important details from many older CentOS 7 examples, especially around logical-volume names and the way xfs_growfs is applied.
Steps:
- Check space usage with
df -hand back up /home. - Unmount the /home file system.
- Delete the LV where /home is located.
- Extend the LV where /root is located.
- Extend the /root file system.
- Recreate the /home LV and mount /home.
- Check the final adjustment result.
Before You Do Anything
- This process deletes the original
/homelogical volume, so back it up first. - It is safest on a VM, test machine, or any environment where a short maintenance window is acceptable.
- If real user data lives under
/home, do not skip the backup and restore steps.
Check space usage with df -lh and back up /home
First, log in via SSH and use df -lh to check space usage.
df -lh

Root is already insufficient, and since I’m the only one using the VPS, I don’t need /home at all. 1GB for /home is enough; the rest can go to /root, which will give root an additional 73GB of space.
Because I didn’t take a screenshot at the beginning, what you see now is 1GB, but initially, /home was 74GB.
Back up /home files to the /tmp directory.
tar cvf /tmp/home.tar /home
# zip -r /tmp/home.zip /home

Unmount the /home file system
fuser -km /home/
umount /home
Release the /home directory’s occupation and unmount the /home directory.
Delete the LV where /home is located
This step is significantly different in CentOS 8, because in CentOS 7 the directory was /dev/mapper/centos-home, while in CentOS 8 it’s /dev/mapper/cl-home. Therefore, pay attention to the device name when unmounting.
lvremove /dev/mapper/cl-home

Extend the LV where /root is located
Extend the root space LV.
lvextend -L +73G /dev/mapper/cl-root
Extend the /root file system
This step is where the root space is actually increased. There’s a significant difference between CentOS 7 and CentOS 8. In CentOS 7, xfs_growfs /dev/mapper/centos-root was used. Logically, in CentOS 8 it should be xfs_growfs /dev/mapper/cl-root, but the result is:
xfs_growfs /dev/mapper/cl-root

After some exploration, I found that you should just use /.
xfs_growfs /

Recreate the /home LV and mount /home
Create a 1GB /home partition.
lvcreate -L 1G -n home cl
Set the file system type.
mkfs.xfs /dev/cl/home

Mount to the /home directory.
mount /dev/cl/home /home
Restore files to the /home directory.
mv /tmp/home.tar /home
cd /home
tar xvf home.tar
mv home/* .
rm -rf home*
Also check /etc/fstab before you call the job finished. If the old /home mount entry still points to the previous logical volume name, the system may fail to mount /home correctly after reboot. In practice, you should make sure the new /dev/cl/home entry, or its UUID, is what the system will mount.
Check the final adjustment result
Check the size of each partition.
df -lh

Summary:
This article walks through the key CentOS 8 steps for shrinking /home and growing /root: back up first, remove the old logical volume, extend root, then rebuild /home and verify the mount configuration. That is more useful than copying commands blindly because each stage has a clear purpose.
If the final layout still looks wrong, check three things first: whether you referenced the correct LV names, whether xfs_growfs / actually succeeded, and whether /etc/fstab still points to an outdated /home device.
- 原文作者:春江暮客
- 原文链接:https://www.bobobk.com/en/745.html
- 版权声明:本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。