In CentOS 7, if you want to adjust the capacity of the /home
partition and allocate it to the root directory /
, you can achieve this using LVM (Logical Volume Management). Here is a basic step-by-step guide:
- Backup Your Data: Before performing any partition operations, make sure to back up all data in the
/home
directory to prevent any loss. - Unmount the
/home
Partition: Use the commandumount /home
. - Reduce the Size of the LVM Logical Volume: Use the
lvreduce
command to decrease the size of the/home
partition. The-L -100G
flag indicates that you want to reduce it by 100GB; adjust the value according to your needs. Run:lvreduce -L -100G /dev/mapper/centos-home
. - Reformat the Partition: After shrinking the partition, you need to reformat it. Use the command
mkfs.xfs
with the-f
flag to force the format. Run:mkfs.xfs /dev/mapper/centos-home -f
. - Remount the
/home
Partition: Use the commandmount /dev/mapper/centos-home /home
. - Extend the Root Partition: Use the
lvextend
command to expand the root partition/dev/mapper/centos-root
, adding the same amount of space that was reduced from the/home
partition. Run:lvextend -L +100G /dev/mapper/centos-root
. - Apply the File System Expansion: For XFS file systems, use the
xfs_growfs
command to extend the file system to utilize the new partition space. Run:xfs_growfs /dev/mapper/centos-root
. - Verify the Partition Changes: Use the
df -h
command to check the new size of the partition and ensure that the adjustment has taken effect.
Please note that these steps involve operations on file systems and partitions, which may pose risks to system data. If there is data in the
/home
partition, ensure you back it up first!!! Backup first!!! Backup first!!!