Resize disks in a Centos 7 Install

The default layout for disks in a Centos deployment may make sense for the average use case, but not for using the machine as a Tripleo all-in-one development box. I have 500 GB of Disk space, and the default installer puts 400GB into /home and 50 GB into /. However, since most of the work here is going to be done in virtual machines, the majority of the /home space is wasted, and I found I have filled up the 50 GB partition on / on a regular basis. So, I want to remove /home and put all the space under /.

Here is my start state.

# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   50G   18G   33G  35% /
devtmpfs                  16G     0   16G   0% /dev
tmpfs                     16G     0   16G   0% /dev/shm
tmpfs                     16G   33M   16G   1% /run
tmpfs                     16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/centos-home  411G  1.9G  409G   1% /home
/dev/sda1                497M  167M  331M  34% /boot
tmpfs                    3.2G     0  3.2G   0% /run/user/0

Thus far, I only have 1.9 GB under /home, and 33 out of 50 GB under /, so I have enough space to work with. I start by backing up the /home subdirectories to space on the partition that holds /.

mkdir /home-alt
df -h
mv /home/stack/ /home-alt/
umount /home

Edit the Filesystem table to remove the home directory in the future.

# /etc/fstab
# Created by anaconda on Wed Jan 20 14:27:36 2016
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=3347d9ba-bb62-44cf-8dfc-1b961279f428 /boot                   xfs     defaults        0 0
#/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0

From the above, we can see that the partition for / and /home are /dev/mapper/centos-root and /dev/mapper/centos-home.

using the pvs command, I can see one physical volume:

  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  476.45g 64.00m

Using vgs, I can see a singe volume group:

  VG     #PV #LV #SN Attr   VSize   VFree 
  centos   1   3   0 wz--n- 476.45g 64.00m

And finally, using lvs I see the three logical volumes that appeared in my fstab;

  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-a----- 410.70g                                                    
  root centos -wi-ao----  50.00g                                                    
  swap centos -wi-ao----  15.69g 

Remove the centos-home volume:

lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume home? [y/n]: y
  Logical volume "home" successfully removed

Extend the centos-root volume by 410GB. I can resize the underlying file system at the same time by passing -r.

lvextend -r /dev/mapper/centos-root /dev/sda2

Check if it worked:

# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  461G   20G  442G   5% /
devtmpfs                  16G     0   16G   0% /dev
tmpfs                     16G     0   16G   0% /dev/shm
tmpfs                     16G   33M   16G   1% /run
tmpfs                     16G     0   16G   0% /sys/fs/cgroup
/dev/sda1                497M  167M  331M  34% /boot
tmpfs                    3.2G     0  3.2G   0% /run/user/0

I’ll admit, that was easier than I expected.

Return the /home subdirectories to their correct positions in the directory tree.

# mv /home-alt/ayoung/ /home/
# mv /home-alt/stack/ /home/
# rmdir /home-alt/

For references I used:

  1. How to Extend/Reduce LVM’s (Logical Volume Management) in Linux – Part II
  2. Resize your disks on the fly with LVM
  3. and the man pages for the commands listed.

4 thoughts on “Resize disks in a Centos 7 Install

  1. Thanks for this 🙂

    I was running out of space on a production server and this was the first post I came across on a google search.

    Much easier that I thought it was going to be.

  2. You are quite welcome. I keep notes like these public with the hope that they will help others, but also so I can find them myself in a pinch.

  3. After following these steps I can’t boot in default mode. It always goes to emergency mode

  4. Not enough information in your response for me to provide anything helpful. Many things you could have done that triggers that.

Leave a Reply

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