Merge (or Resize) the /home partition on CentOS 7

Merge (or Resize) the /home partition on CentOS 7

CentOS7 by default partitions your storage by putting a large amount of space in the /home directory partition. For most use-cases, this is perfectly fine. However, if you’re working with limited space, and have already installed a default install of CentOS, you may find you need to reclaim some of the space in your /home parition for use with other partitions.

Before continuing, you will want to MAKE A BACKUP OF YOUR /HOME DIRECTORY if there’s anything in it you want to keep. Once you’ve got your files backed up, you can merge your /home partition with your /root partition using the following commands. I’ll show you the output as well so you can know what to expect.

[root@localhost ~]# umount /home

[root@localhost ~]# lvremove /dev/centos/home
Do you really want to remove active logical volume centos/home? [y/n]: y
  Logical volume "home" successfully removed

[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <444.81 GiB (113871 extents).
  Logical volume centos/root successfully resized.

[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 116603904

[root@localhost ~]#

Next you’ll need to edit your /etc/fstab file so that CentOS doesn’t try to mount a /home partition that no longer exists. Just edit /etc/fstab in your preferred editor and remove or comment out the following line:

/dev/mapper/centos-home /home                   xfs     defaults        1 2

That’s it! Your root directory should now have all the space that used to be allocated to your /home directory and you should be good on your next reboot as well.

Hope this helps.

3 thoughts on “Merge (or Resize) the /home partition on CentOS 7

  1. In my case the volume was not named ‘centos’, so the lvremove /dev/centos/home command didn’t work. “Volume group “centos” not found. Cannot process volume group centos.”
    You can type lvscan to get a list of volumes. In my case, I entered lvremove /dev/cl/home, but I get the error “Logical volume cl/home contains a filesystem in use.” Typing umount /home shows “umount: /home: not mounted.” So I’m not sure what’s wrong here.

  2. Wondering if the usage for xfs_growfs changed between CentOS 7 and 8? When I tried xfs_growfs /dev/cl/root as shown above, I got the error ‘/dev/cl/root is not a mounted XFS filesystem’ However, I was able to get xfs_growfs / to work.

    1. Thank you for mentioning that! I love it when others are able to figure stuff out based on what I’ve written. It makes the effort of posting it worthwhile. =)

Leave a Reply

Your email address will not be published. Required fields are marked *

nineteen + 16 =