Reducing /home partition size and increasing /root space in CentOS 8
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:
- Check space usage with
df -h
and 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.
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*
Check the final adjustment result
Check the size of each partition.
df -lh
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.
- 原文作者:春江暮客
- 原文链接:https://www.bobobk.com/en/745.html
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。