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.


[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! ;)



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
  • Thanks very much, however I get "Logical volume VolGroup/lv_home contains a filesystem in use." Did I need to do this in single user mode? – stet Jul 20 '13 at 15:32
  • I mixed answers below and rebooted with the /home commented out of fstab and then removed it. Thanks. – stet Jul 20 '13 at 17:51
  • Thanks for the reply. Very useful. I'd like to add something: It's better to use "root" account in "rescue mode" so you can unmount home dir successfully (because root user uses another home dir). – M A Jun 8 '18 at 1:03

This process will work if your root filesystem is resizeable (ext4 for example).

  1. modify a existing user or create a new user whose home directory is not under /home.
  2. verify that you can login as that user and su to root
  3. ensure all other users are logged out
  4. umount /home - if this fails then user processes may still be using /home. Check with fuser or lsof
  5. remount /dev/mapper/VolGroup-lv_home on a temporary mount - /mnt/home for example
  6. use rsync, cp -p or some other tool to copy the user home directories from /mnt/home to /home - verify that the permissions and ownerships are correct
  7. edit fstab to comment out /home
  8. users can now be allow to log back in
  9. lvremove /dev/VolGroup/lv_home
  10. lvextend -L+921G /dev/VolGroup/lv_root
  11. resize2fs /dev/VolGroup/lv_root
  • Thank you for the clarifications in steps 10 and 11! I hope people vote up this answer. – stet Jul 20 '13 at 17:51

You could also do this without growing the partition by just swapping the mount points:

unmount the home partition:

umount /home

mount it somewhere else, e.g. to /mnt:

mount /dev/mapper/VolGroup-lv_home /mnt

move everything from the partition to your home directory (which is on the root partition now):

mv /mnt/* /home/

move the data from your /var directory to the partition:

mv /var/* /mnt/

remount your partition to /var:

umount /mnt

mount /dev/mapper/VolGroup-lv_home /var

Make sure to change the contents of your /etc/fstab afterwards accordingly.

  • Will this move the files that are held open by daemons correctly or will they continue to be written to the original ? – user9517 Jul 20 '13 at 15:13
  • I'd suggest to stop any services accessing /var beforehand and start them again afterwards. Between the steps of moving the data from /var/ to /mnt and remounting to /var/, the /var directory will be empty so anything accessing it won't work anyway. – etagenklo Jul 20 '13 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.