2

This question already has an answer here:

Running df -h gives me the following:

Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/centos-root           50G   49G  1.3G  98% /
devtmpfs                         7.8G     0  7.8G   0% /dev
tmpfs                            7.8G     0  7.8G   0% /dev/shm
tmpfs                            7.8G  769M  7.1G  10% /run
tmpfs                            7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-home           78G  182M   78G   1% /home
/dev/sda1                        497M  338M  160M  68% /boot
tmpfs                            1.6G     0  1.6G   0% /run/user/0

I want to allocate more spare to /dev/mapper/centos-root, by reducing the allocation for /dev/mapper/centos-home

How would I remove 50GB from home and give it to root?


Further Info

Running mount tells me the following:

/dev/mapper/centos-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

Does this mean it's the XFS filesystem? When I run resize2fs I get the following error:

resize2fs: Bad magic number in super-block while trying to open /dev/centos/home Couldn't find valid filesystem superblock.

marked as duplicate by roaima, dr01, jimmij, Archemar, jayhendren Jan 8 '18 at 17:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • That depends entirely on how CentOS manages its device mapping, which is probably LVM... – Shadur Jan 8 '18 at 9:07
  • It can be done. I would not take so much, maybe only 20GB. You have to umount home, shrink the filesystem, than LVM, and then you can add it to root online. – Rui F Ribeiro Jan 8 '18 at 9:15
  • 1
    @Lee you appear to be using two different accounts (confusingly both named Lee). If you want them merged please contact the moderators. – roaima Jan 8 '18 at 9:28
  • 1
    XFS filesystems cannot be shrunk – Fox Jan 8 '18 at 9:37
  • 1
    @Fox agreed. It's also clearly stated in the current best answer on my proposed duplicate. The suggestion there for XFS is backup-resize-restore. – roaima Jan 8 '18 at 10:58
1

First, run vgs as root and check the displayed VFree value of the centos volume group. If it is non-zero, you have unallocated capacity in the VG: it can be used to extend the root filesystem without first shrinking /home. If so, you can jump straight into the last paragraph of this answer.

But if vgs reports that VFree is zero for the centos VG, read on...

Since your /home filesystem apparently contains only 182M of data, you could easily backup its contents to some temporary location (even an USB stick), then unmount the /home filesystem, then destructively resize the logical volume and recreate the filesystem.

XFS filesystems can be on-line extended, but not reduced. Therefore it would be useful to resize your /home LV to as small as practical, since you can then re-extend it as necessary as long as you have unallocated capacity in the volume group.

The procedure could be something like this:

# cd /
# tar --acls --selinux --xattrs jcvf /some/where/home_archive.tar.bz2 home
<verify that the resulting archive is readable and intact>
# umount /home
# lvreduce -L 10G /dev/mapper/centos-home
# mkfs.xfs -f /dev/mapper/centos-home    # WARNING: this will definitely destroy existing contents!
# mount /home
# cd /
# tar --acls --selinux --xattrs xvf /some/where/home_archive.tar.bz2

Now the /home filesystem is only 10G in size, and the remaining capacity is free in the centos volume group. You can see this with the vgs command.

To on-line extend the root filesystem (or any XFS filesystem located on a LVM logical volume), the procedure is:

# lvextend -L <new size> /dev/mapper/centos-root  # lvextend wants the LV device name
# xfs_growfs /   # xfs_growfs wants the filesystem mount-point as argument

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