10-03-2020, 02:43 PM
How to shrink /home and add more space on CentOS7
CentOS 7 file system is XFS, And resize2fs doesn't work. I need to shrink /home to 400G and add 100G space to /. What should I do?
##
##As others have pointed out, XFS filesystem cannot be shrunk.
## So your best bet is to backup /home, remove and recreate its volume in a smaller size and give the rest to your /root volume just as Koen van der Rijt ## outlined in his post.
## backup the contents of /home
sudo tar -czvf /root/home.tgz -C /home .
## test the backup
sudo tar -tvf /root/home.tgz
## if umount not working
fuser -kim /address
## unmount home
sudo umount /dev/mapper/centos-home
## remove the home logical volume
sudo lvremove /dev/mapper/centos-home
## recreate a new 400GB logical volume for /home, format and mount it
sudo lvcreate -L 400GB -n home centos
sudo mkfs.xfs /dev/centos/home
sudo mount /dev/mapper/centos-home
## extend your /root volume with ALL of the remaining space and resize (-r) the file system while doing so
sudo lvextend -r -l +100%FREE /dev/mapper/centos-root
## restore your backup
sudo tar -xzvf /root/home.tgz -C /home
## check /etc/fstab for any mapping of /home volume. IF it is using UUID you should update the UUID portion. (Since we created a new volume, UUID has changed)
## That's it.
##Hope this helps.
CentOS 7 file system is XFS, And resize2fs doesn't work. I need to shrink /home to 400G and add 100G space to /. What should I do?
##
##As others have pointed out, XFS filesystem cannot be shrunk.
## So your best bet is to backup /home, remove and recreate its volume in a smaller size and give the rest to your /root volume just as Koen van der Rijt ## outlined in his post.
## backup the contents of /home
sudo tar -czvf /root/home.tgz -C /home .
## test the backup
sudo tar -tvf /root/home.tgz
## if umount not working
fuser -kim /address
## unmount home
sudo umount /dev/mapper/centos-home
## remove the home logical volume
sudo lvremove /dev/mapper/centos-home
## recreate a new 400GB logical volume for /home, format and mount it
sudo lvcreate -L 400GB -n home centos
sudo mkfs.xfs /dev/centos/home
sudo mount /dev/mapper/centos-home
## extend your /root volume with ALL of the remaining space and resize (-r) the file system while doing so
sudo lvextend -r -l +100%FREE /dev/mapper/centos-root
## restore your backup
sudo tar -xzvf /root/home.tgz -C /home
## check /etc/fstab for any mapping of /home volume. IF it is using UUID you should update the UUID portion. (Since we created a new volume, UUID has changed)
## That's it.
##Hope this helps.