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
/homedirectory to prevent any loss. - Unmount the
/homePartition: Use the commandumount /home. - Reduce the Size of the LVM Logical Volume: Use the
lvreducecommand to decrease the size of the/homepartition. The-L -100Gflag 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.xfswith the-fflag to force the format. Run:mkfs.xfs /dev/mapper/centos-home -f. - Remount the
/homePartition: Use the commandmount /dev/mapper/centos-home /home. - Extend the Root Partition: Use the
lvextendcommand to expand the root partition/dev/mapper/centos-root, adding the same amount of space that was reduced from the/homepartition. Run:lvextend -L +100G /dev/mapper/centos-root. - Apply the File System Expansion: For XFS file systems, use the
xfs_growfscommand 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 -hcommand 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!!!