Extend /home LV with a New Partition

Provides a tutorial example on how to extend the /home file system on a LV (Logical Volume) on the fly with an newly added PV (Physical Volume) on the VG (Volume Group).

How To Extend /home LV? By default CentOS 8 uses a LV (Logical Volume) for /home directory. If /home is running out of space, you can easily extend the LV by adding a new partition to the VG (Volume Group).

1. Check current usage of /home. I see only 23% free space left.

herong$ df -m

Filesystem          1M-blocks  Used Available Use% Mounted on
/dev/mapper/cl-root     51175  6133     45043  12% /
/dev/mapper/cl-home     39857 30595      9262  77% /home
...

2. Find the VG that hosts the /home LV. I see "cl" as the VG name.

herong$ sudo lvs
  LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log
  home cl -wi-ao---- 38.94g
  root cl -wi-ao---- 50.00g
  swap cl -wi-ao----  7.71g

3. Check the usage of the "cl" VG. I see 0 free space left.

herong$ sudo vgs
  VG #PV #LV #SN Attr   VSize  VFree
  cl   1   3   0 wz--n- 96.65g    0

4. Check the usage the second hard disk /dev/sdb. I see 2000GB free space left.

herong$ sudo parted /dev/sdb print free

Number  Start   End     Size    File system  Name     Flags
       17.4kB  1049kB  1031kB  Free Space
1      1049kB  2000GB  2000GB  ext4         primary
       2000GB  4000GB  2000GB  Free Space

5. Create a new partition of 1000GB on /dev/sdb as a new PV (Physical Volume). I see /dev/sdb2 ready as a partition.

herong$ sudo parted /dev/sdb mkpart primary ext4 2000GB 3000GB
Information: You may need to update /etc/fstab.

herong$ sudo parted /dev/sdb print free
Number  Start   End     Size    File system  Name     Flags
        17.4kB  1049kB  1031kB  Free Space
..
1       1049kB  2000GB  2000GB  ext4         primary
2       2000GB  3000GB  1000GB               primary
        3000GB  4000GB  1000GB  Free Space

6. Convert /dev/sdb2 into a new PV with "pvcreate" command. I see /dev/sdb2 ready as PV.

herong$ sudo pvcreate /dev/sdb2
  Physical volume "/dev/sdb3" successfully created.

herong$ sudo pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda7  cl   lvm2 a--   96.65g      0
  /dev/sdb2       lvm2 a--  931.69g 831.69g

7. Add /dev/sdb2 as a PV to "c1" VG with "vgextend" command. I see "c1" VG with 924.82g free space now.

herong$ sudo vgextend cl /dev/sdb2
 Volume group "cl" successfully extended

herong$ sudo vgs
   VG #PV #LV #SN Attr   VSize  VFree
   cl   3   3   0 wz--n- 1.10t 924.82g

8. Find the device path for /home LV. I see /dev/cl/home.

herong$ sudo lvdisplay

  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                GTeo46-cl6I-XFL8-tCvb-vCeN-swL7-lyCV2n
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-03-27 05:01:49 +0800
  LV Status              available
  # open                 1
  LV Size                38.94 GiB
  Current LE             9969
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

8. Extend /home LV with an extra 100GB with "lvextend" command.

herong$ sudo lvextend /dev/cl/home -L +100G
  Size of logical volume cl/home changed from 38.94 GiB (9969 extents)
    to 138.94 GiB (35569 extents).
  Logical volume cl/home successfully resized.

9. Check storage spaces of all LVs with "lvscan" command. I see an extra 100GiB added to /dev/cl/home.

herong$ sudo lvscan
 ACTIVE            '/dev/cl/swap' [7.71 GiB] inherit
 ACTIVE            '/dev/cl/home' [138.94 GiB] inherit
 ACTIVE            '/dev/cl/root' [50.00 GiB] inherit

10. Check file system usage on /home. I see no changes, because the file system on /dev/cl/home is not extended yet.

herong$ df -m

Filesystem          1M-blocks  Used Available Use% Mounted on
/dev/mapper/cl-root     51175  6133     45043  12% /
/dev/mapper/cl-home     39857 30595      9262  77% /home
...

11. Extent the file system on /dev/cl/home to the end of the LV "partition" with "resize2fs" command. I see an error, because "resize2fs" command supports ext2/3/4 file system types only.

herong$ sudo resize2fs /dev/cl/home
resize2fs 1.44.6 (5-Mar-2019)
resize2fs: Bad magic number in super-block while trying to open /dev/cl/home
Couldn't find valid filesystem superblock.

12. Check the file system type on /dev/cl/home with "file -s" command. I see "SGI XFS" file system type.

herong$ sudo file -s /dev/cl/home
[sudo] password for herong:
/dev/cl/home: symbolic link to ../dm-2

herong$ sudo file -s /dev/dm-2
/dev/dm-2: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)

13. Try to extent the file system on /dev/cl/home to the end of the LV "partition" with "xfs_growfs" command. I see an error, because "xfs_growfs" command takes the mounting point /home as its argument, instead of the device file name.

herong$ sudo xfs_growfs /dev/cl/home

xfs_growfs: /dev/cl/home is not a mounted XFS filesystem

14. Extent the mounted /home to the end of the LV "partition" with "xfs_growfs" command. I see no errors.

herong$ sudo xfs_growfs /home

meta-data=/dev/mapper/cl-home isize=512    agcount=4, agsize=2552064 blks
         =                    sectsz=4096  attr=2, projid32bit=1
         =                    crc=1        finobt=1, sparse=1, rmapbt=0
         =                    reflink=1
data     =                    bsize=4096   blocks=10208256, imaxpct=25
         =                    sunit=0      swidth=0 blks
naming   =version 2           bsize=4096   ascii-ci=0, ftype=1
log      =internal log        bsize=4096   blocks=4984, version=2
         =                    sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                extsz=4096   blocks=0, rtextents=0
data blocks changed from 10208256 to 36422656

15. Confirm the storage usage of /home. I see only 78% free space now.

herong$ df -m

Filesystem             1M-blocks  Used Available Use% Mounted on
/dev/mapper/cl-root       51175  13743     37433  27% /
/dev/mapper/cl-home      142257  30595    113683  22% /home
...

Cool. I have successfully extended the /home LV with a new partition added to the VG on the fly with /home still in use. If you want to be on the safer side, disconnect all users, stop all applications that are using /home. Take a backup of /home files, and then follow above steps.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

 Files and Directories

 Users and Groups

 File Systems

 Block Devices and Partitions

LVM (Logical Volume Manager)

 What Is LVM (Logical Volume Manager)

 Create New PV (Physical Volume)

 Add/Remove PV on VG on the Fly

 Create LV on VG on the Fly

Extend /home LV with a New Partition

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Software Package Manager on CentOS - DNF and YUM

 Running Apache Web Server (httpd) on Linux Systems

 Running PHP Scripts on Linux Systems

 Running MySQL Database Server on Linux Systems

 Running Python Scripts on Linux Systems

 vsftpd - Very Secure FTP Daemon

 Postfix - Mail Transport Agent (MTA)

 Dovecot - IMAP and POP3 Server

 Email Client Tools - Mail User Agents (MUA)

 LDAP (Lightweight Directory Access Protocol)

 GCC - C/C++ Compiler

 Graphics Environments on Linux

 Conda - Environment and Package Manager

 Tools and Utilities

 Administrative Tasks

 References

 Full Version in PDF/EPUB