On my previous projects, I used the default installation settings for centos. But after some heavy usage getting logs from all networking devices. / directory started getting full and that struck the realization to resize the /home directory to get more space. (Dumb random command: df -h).
Before starting, the mount point name would be different depending on your installation. So be careful before applying to on production machine.
NOTE: Check /etc/fstab file to verify the /home entry is in the file. If its UUID of the device note that ID. You will need to change the UUID at the end of this process as the reconstruction of logical volume will create new UUID. And if it contents the location of device you don’t need to worry about this
NOTE: You need root account to perform steps below
- First, let’s take a backup of your home directory as we will delete the mount point completely.
tar -czvf /root/home.tgz -C /home .
- Test your backup
tar -tvf /root/home.tgz
- Unmount the logical volume home
umount /dev/mapper/centos-home
- Remove home logical volume
lvremove /dev/mapper/centos-home
- Now create a new home directory with reduces size. Here is kept 40GB.
lvcreate -L 40GB -n home centos
- Let’s construct newly created logical volume with XFS filesystem
mkfs.xfs /dev/centos/home
- Mount the volume back to /home point
mount /dev/mapper/centos-home
- Now extend the root directory using the free space we created by reconstructing /home volume
lvextend -r -l +100%FREE /dev/mapper/centos-root
- Use a previously created backup to put important files to its place
tar -xzvf /root/home.tgz -C /home