CentOS7‎ > ‎CentOS7 General‎ > ‎

XFS LVM Grow CentOS7

This page describes how to increase the size of the various xfs LVM's on a CentOS7 desktop which uses LVM and xfs filesystems.  In this case, I had purchased a laptop with a small 500Gb HDD and after I setup my complete CentOS system with source builds of LXC, OpenvSwitch and SCST, and had installed and confgured dynamic DNS/DHCP, I decided that I wanted to have (a) a copy of this fully-configured disk, and (b) have that copy on a much larger disk.  So I found the largest 7mm laptop HD on Amazon which is a Seagate 5400 RPM 2Tb 7mm drive (granted a slow beast) and then I used Ubuntu install disk and booted into that Ubuntu disk to do a dd copy of the old disk to the new larger disk (example "dd if=/dev/sda of=/dev/sdb bs=128M").

After I was done with that, I put the new larger copy of the HDD into the original Lenovo ThinkPad P70 laptop and booted up with Gparted disk, and extended the 500Gb partition to the end of the 2Tb device giving me another 1.5 Tb or so of available space.

jNext boot up the laptop and now it's necessary to dole out that extra 1.5 Tb or so of space to the CentOS filesystem xfs filesystems in LV's, and that's what this guide is for to remind me how that was done when it's necessary to do that.

Here's an example of the kind of filesystem setup this guide covers as shown below.

[root@stlns01 ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        54G  6.3G   48G  12% /
devtmpfs                devtmpfs   34G     0   34G   0% /dev
tmpfs                   tmpfs      34G  164k   34G   1% /dev/shm
tmpfs                   tmpfs      34G  9.5M   34G   1% /run
tmpfs                   tmpfs      34G     0   34G   0% /sys/fs/cgroup
/dev/sda1               xfs       518M  226M  293M  44% /boot
/dev/mapper/centos-home xfs       438G  682M  437G   1% /home
tmpfs                   tmpfs     6.7G   13k  6.7G   1% /run/user/1000
[root@stlns01 ~]#

Extend the LV

Extend the LV as shown below.  My reference for this was here.

[root@stlns01 ~]# lvextend -L60G /dev/centos/root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 60.00 GiB (15360 extents).
  Logical volume root successfully resized.
[root@stlns01 ~]#

Recheck Filesystem Size

The filesystem should be the same size because it has not been grown yet even though the LV has already been extended.


[root@stlns01 ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        54G  6.3G   48G  12% /
devtmpfs                devtmpfs   34G     0   34G   0% /dev
tmpfs                   tmpfs      34G  164k   34G   1% /dev/shm
tmpfs                   tmpfs      34G  9.5M   34G   1% /run
tmpfs                   tmpfs      34G     0   34G   0% /sys/fs/cgroup
/dev/sda1               xfs       518M  226M  293M  44% /boot
/dev/mapper/centos-home xfs       438G  682M  437G   1% /home
tmpfs                   tmpfs     6.7G   13k  6.7G   1% /run/user/1000
[root@stlns01 ~]#

Grow the XFS Filesystem

[root@stlns01 ~]# xfs_growfs /
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=3276800 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=0        finobt=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=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 15728640
[root@stlns01 ~]#

View the PV, VG and LV Information

Check the output of the following commands as shown below.

[root@stlns01 ~]# pvdisplay

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               1.82 TiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              476806
  Free PE               355153
  Allocated PE          121653
  PV UUID               gxYGbp-5QSG-v2gc-2W2P-fm74-P9bL-o0D02V
  
[root@stlns01 ~]# vgdisplay
  --- 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                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.82 TiB
  PE Size               4.00 MiB
  Total PE              476806
  Alloc PE / Size       121653 / 475.21 GiB
  Free  PE / Size       355153 / 1.35 TiB
  VG UUID               Pt0wBI-bQrK-uvlQ-KPp5-YlJd-7tUu-5nJfNt
  
[root@stlns01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                KkLnrg-UeeS-BO6U-N5hA-3okg-gyNi-ftvQFH
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-08-13 00:05:20 -0500
  LV Status              available
  # open                 1
  LV Size                60.00 GiB
  Current LE             15360
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                pgn4Be-ZiGv-vaxh-bUz4-UVvP-H26m-wNcaeZ
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-08-13 00:05:20 -0500
  LV Status              available
  # open                 1
  LV Size                407.58 GiB
  Current LE             104341
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
  
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                re0udb-ePma-lYH2-P0ck-WBAz-OSCf-vp2pM1
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-08-13 00:05:23 -0500
  LV Status              available
  # open                 2
  LV Size                7.62 GiB
  Current LE             1952
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  
[root@stlns01 ~]#

That's all there was to it.  Note that xfs filesystems cannot be "shrunk" in any straigtforward easy was like this as there is no shrink equivalent command for xfs filesystems similar to "xfs_growfs".  Therefore, only growth is readily possible without much more involved measures.

Update 2019-04-05

There is a nice writeup on how to shrink an xfs filesystem here.


Comments