Changing the CentOS 7 LVM Configuration: Delete /home and Expand /
When installing CentOS 7, the default settings use LVM to split the storage into / (root) and /home. This time, although we were utilizing the lvm home volume as storage for Docker, upon closer organization, we realized that it wasn’t occupying that much space and decided that there was no special need to keep the home volume separate.
Therefore, we performed the procedure to delete the home volume’s logical volume and integrate that freed-up space into the / volume.
Current Partition Configuration
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 238.5G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 238G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.7G 0 lvm [SWAP] └─centos-home 253:2 0 180.2G 0 lvm /var/lib/docker/vfs
LVM Logical Volumes
# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-a----- 180.23g root centos -wi-ao---- 50.00g swap centos -wi-ao---- <7.69g
Steps to Delete /home and Expand /
Back up /home Data
If there is important data in /home, please back it up in advance. In our case, since only Docker images were stored there, we did not create a backup.
$ tar -cvzf /root/home_backup.tar.gz /home
Unmount /home
$ umount /home
If you cannot unmount the directory, check for any processes currently using it and stop them as necessary.
$ lsof +D /home $ systemctl stop docker # If Docker is using it
Delete the centos-home Logical Volume
# lvremove /dev/centos/home Do you really want to remove active logical volume centos/home? [y/n]: y Logical volume "home" successfully removed$ lvremove /dev/centos/home
When the confirmation message appears, type y to delete it.
Check Volume Group Free Space
# vgdisplay centos --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 237.98 GiB PE Size 4.00 MiB Total PE 60924 Alloc PE / Size 14768 / <57.69 GiB Free PE / Size 46156 / <180.30 GiB VG UUID FEeX6Q-XXX
Verify that the free space after deleting /home is displayed under Free PE / Size.
Expand the / Logical Volume
# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <230.30 GiB (58956 extents). Logical volume centos/root successfully resized.
# vgdisplay centos --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 237.98 GiB PE Size 4.00 MiB Total PE 60924 Alloc PE / Size 60924 / 237.98 GiB Free PE / Size 0 / 0 VG UUID FEeX6Q-XXX
# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <230.30g swap centos -wi-ao---- <7.69g
Expand the File System
# xfs_growfs /
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 60370944
7. Verification
# df -h ファイルシス サイズ 使用 残り 使用% マウント位置 /dev/mapper/centos-root 231G 32G 200G 14% / /dev/sda1 497M 466M 32M 94% /boot
Verify that the capacity of / has been expanded.
Conclusion
While default CentOS 7 installations often allocate a large amount of space to /home, if you do not actually need a separate /home partition in your operational environment, deleting /home and integrating it into / like we did here allows you to utilize your storage more efficiently.
Leveraging LVM enables flexible partition management, so reviewing your configuration according to your environment is also important.