Linux – How to integrate /home back into main partition, then grow partition

linuxpartition

I made a mistake in setting up one of our XenServer-based Linux VMs. I created a separate swap (good) and a large separate /home directory (bad) when really it should have been a large separate /var directory instead.

Now that /var has almost saturated the root disk, I would like to reintegrate /home back into the root partition, delete the old 921GB /home partition, then grow the root partition to 921GB leaving the /swap partition untouched.

Currently:

[root@ /]# df -h

Filesystem                       Size  Used Avail Use% Mounted on 
/dev/mapper/VolGroup-lv_root      50G   43G  4.0G  92% / 
tmpfs                            3.9G     0  3.9G   0% 
/dev/shm /dev/xvda1              485M   72M  388M  16% /boot 
/dev/mapper/VolGroup-lv_home     921G  200M  874G   1% /home

So more clearly, I need to know how to move /home and it's contents to the root partition (/dev/mapper/VolGroup-lv_root) and have Linux recognize it as the OS's home directory, delete the /dev/mapper/VolGroup-lv_home partition, and then grow the /dev/mapper/VolGroup-lv_root partition to take up the additional 921GB available.

I'm open to swapping /home and /var's locations if possible, but this is a production server. I can make instant snapshots at will though, so some late night experimentation is possible! 😉

Thanks!

Best Answer

It's fairly straightforward, as root:

mkdir /home2
mv /home/* /home2/
umount -fl /home
lvremove /dev/VolGroup/lv_home
mv /home2 /home
  • edit your fstab and remove the entry for /dev/VolGroup/lv_home
  • check how much space you now have available in VolGroup with vgdisplay and add that much to lv_root with lvextend
  • use resize2fs or xfs_growfs as appropriate on lv_root
Related Topic