I recently set up a CentOS 8 virtual machine to experience the latest CentOS system, allocating 127GB of space. Due to actual needs, I found that the /home partition had tens of gigabytes of space, and since I only use the root user, I don’t need /home space. Therefore, I found a method to adjust the /home space to /root in CentOS 8, which differs from what’s found online for CentOS 7.

Steps:

  1. Check space usage with df -h and back up /home.
  2. Unmount the /home file system.
  3. Delete the LV where /home is located.
  4. Extend the LV where /root is located.
  5. Extend the /root file system.
  6. Recreate the /home LV and mount /home.
  7. Check the final adjustment result.

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

df_h_space

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

backup_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

remove_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

xfs_growfs_error

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

xfs_growfs /

xfs_growfs_success


Recreate the /home LV and mount /home

Create a 1GB /home partition.

lvcreate -L 1G -n home cl

lvcreate_1g_home Set the file system type.

mkfs.xfs /dev/cl/home

mkfs_xfs_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*

Check the final adjustment result

Check the size of each partition.

df -lh

adjust_success


Summary:

This article primarily explains how to adjust partition sizes in CentOS 8, specifically the /home and /root partitions, highlighting the differences in parameters between CentOS 7 and CentOS 8. It familiarizes you with adjusting file system partitions in Linux. This guide is helpful for users who have just installed the system and need to adjust CentOS partition sizes due to inappropriate initial partitioning. Feel free to contact me via email if you have any questions.