After popular demand by existing customers using CentOS 7 servers, we have prepared this tutorial on how to resize root partition after deleting the default /home partition.
In graphical installation of CentOS 7, unless specified otherwise, the installer will create the following partitions: /centos-root , /centos-home and /swap.
This happens usually when system admins forget to customize the partitioning layout during the installation process. There is a solution though which does not require you to re-install the server.
Steps to Resize Root Partition in CentOS and Deleting Home Partition
Pre-requisites:
- SSH Access on CentOS 7 Server with root or sudo privileged user
- XFS Filesystem with LVM
- Ensure you have taken all necessary backups – any disk related operations are high risk!
Step 1: Copy contents of /home directory
Regardless if you already took backup of your entire server, do another quick backup of the /home directory in a location within the server. After the completion of the resize operation, you will be able to quickly transfer back the contents to the /home directory.
root@localhost:~$ mkdir /temp && cp -a /home /temp/
Step 2: Unmount /home
The following command will unmount /home directory. This is a crucial step as without unmounting you cannot proceed to the next steps.
root@localhost:~$ umount -fl /home
Once done, execute the lvs command to display the attributes of the LVM volumes (you will need these in Step 3).
root@localhost:~$ lvs
Step 3: Remove the Home LVM Volume
Run the following command to remove the LVM volume for home.
root@localhost:~$ lvremove /dev/centos/home
Important: We used …/centos/… because of the “VG” attribute from Step 2. If yours is different please adjust your command in Step 3 accordingly.
Step 4: Resize/Extend the Root LVM Volume
From Step 2, we see (in our example) that the LSize of home volume is ~2,13T. Therefore, it is safe to extend our root LVM by 2 TB.
root@localhost:~$ lvextend -L+2T /dev/centos/root
Then run the following command to finalize the resizing of root partition:
root@localhost:~$ xfs_growfs /dev/mapper/centos-root
Step 5: Copy contents of /home back to original directory
root@localhost:~$ cp -a /temp/home /
Confirm that you see all of your directories and files in /home by executing the command ls /home/.
If you are happy with what you see, proceed and delete the temporary directory you created in Step 1 as follows:
root@localhost:~$ rm -rf /temp
Step 6: Update /etc/fstab and Sync systemd with all changes
At this point we have resized the root partition successfully but we need to ensure that the system will not look to mount the /home partition on its next boot. For this reason you need to remove the line for /dev/mapper/centos-home from file /etc/fstab. Do so using your favorite editor (nano, vi, etc).
Finally, run the following command to sync systems with all changes above.
root@localhost:~$ dracut --regenerate-all --force
You are all set! Enjoy your newly resized Root partition in CentOS!