Resize root partition by removing the default /home partition) on CentOS 8
Resize root partition by removing the default /home partition) on CentOS 8
This requires you to be able to ssh into the instance using the root user account and that no services be running as users out of /home on the target machine. You can check this by command fuser /home
The examples are from a default installation with no customation-you NEED to know what you're working with for volumes/partitions to not horribly break things. Use this at your own risk. AT YOUR OWN RISK . Im only tested this on Centos 8 of mine.
By default, CentOS 8 uses XFS for the file system and Logical Volume Manager (LVM), creating 3 partitions: /
,/home
and /boot
. Check with df -h and du -h of /home
to make sure the space is enough.
Step 1 - Copy /home Contents
To backup the contents of /home, do the following:
mkdir /newhome
cp -rfp /home/* /newhome
Once that is finished at your back at the prompt, you can proceed to step 2.
Step 2 - Unmount the /home directory
umount -fl /home
Step 3 - Note the size of the home LVM volume
We run the lvs
command to display the attributes of the LVM volumes
lvs
Sample output:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home cl -wi-a----- 937.00g
root cl -wi-ao---- 50.00g
swap cl -wi-ao---- 7.81g
Step 4 - Remove the home LVM volume
lvremove /dev/cl/home
Step 5 - Resize the root LVM volume
Based on the output of lvs
above, we can safely extend the root LVM by 100% of free space.
lvextend -l +100%FREE /dev/cl/root
Step 6 - Resize the root partition
xfs_growfs /dev/mapper/cl-root
Step 7 - Remove the /home
rmdir /home
Step 8 - rename /newhome to /home directory
mv /newhome /home
Step 9 - Remove the entry from /etc/fstab
Using your preferred text editor, ensure you open /etc/fstab
and remove (or put # to comment out) the line for /dev/mapper/cl-home.
Step 10 - Don't miss this!
Run the following command to sync systemd up with the changes.
dracut --regenerate-all --force
orginal from [https://gist.github.com/troyfontaine/87091bd6a5c68f45dd62ced3d12bc377]