How to add physical volume and resize LVM

I have a LVM partition that uses 3 physical drives. I need to increase size of this LVM partition by adding a new disk.

I have a drive with 452 GB free disk space.

[root@sok ~]# parted /dev/nvme0n1 print
Model: NVMe Device (nvme)
Disk /dev/nvme0n1: 512GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  4296MB  4295MB  primary  linux-swap(v1)
 2      4296MB  6443MB  2147MB  primary  ext3
 3      6443MB  60.1GB  53.7GB  primary  ext4
 4      60.1GB  512GB   452GB   primary

[root@sok ~]#

Create Physical volume with pvcreate comand

[root@sok ~]# pvcreate /dev/nvme0n1p4
  Physical volume "/dev/nvme0n1p4" successfully created.
[root@sok ~]#

Extend Volume Group

Current volume group size is 4.19 TB

[root@sok ~]# vgs
  VG  #PV #LV #SN Attr   VSize VFree
  vg1   3   1   0 wz--n- 4.19t    0 
[root@sok ~]#

Lets extend the volume group vg1 by adding the newly created physical volume

[root@sok ~]# vgextend vg1 /dev/nvme0n1p4
  Volume group "vg1" successfully extended
[root@sok ~]#

Now the volume group size is 4.6 TB

[root@sok ~]# vgs
  VG  #PV #LV #SN Attr   VSize VFree   
  vg1   4   1   0 wz--n- 4.60t <420.94g
[root@sok ~]#

Increase size of LVM

Lets find details about the current logical volumes

[root@sok ~]# lvs
  LV    VG  Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data1 vg1 -wi-a----- 4.19t                                                    
[root@sok ~]#

We have one logical volume with name data1, size is 4.9 TB.

To extend the logical volume, rune the command

[root@sok ~]# lvextend -l +100%FREE /dev/vg1/data1
  Size of logical volume vg1/data1 changed from 4.19 TiB (1098852 extents) to 4.60 TiB (1206612 extents).
  Logical volume vg1/data1 successfully resized.
[root@sok ~]#

This will extend logical volume "data1" to use all available free disk space on the volume group vg1.

Lets check the new size of LVM with lvs command

[root@sok ~]# lvs
  LV    VG  Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data1 vg1 -wi-a----- 4.60t                                                    
[root@sok ~]# 

Now LVM size is increased to 4.6 TB.

Reszie filesystem

Let us find more info on the logical volume using blkid command

[root@sok ~]# blkid | grep data1
/dev/mapper/vg1-data1: UUID="55a38b6b-a0a7-48a2-b314-36b1f0ce2f05" BLOCK_SIZE="512" TYPE="xfs"
[root@sok ~]# 

The volume is formatted as xfs file system.

Let us find out the mount point.

[root@sok ~]# df -h | grep data1
/dev/mapper/vg1-data1  4.2T  1.1T  3.2T  25% /usr/share/nginx/html
[root@sok ~]#

The volume is mounted at /usr/share/nginx/html

To resize the xfs filesystem, run the command

[root@sok ~]# xfs_growfs /usr/share/nginx/html
meta-data=/dev/mapper/vg1-data1  isize=512    agcount=5, agsize=268435455 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=1125224448, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=521728, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1125224448 to 1235570688
[root@sok ~]#

If the file system is not mounted, you need to mount it before resizing.

Let us verify the size

[root@sok ~]# df -h | grep data1
/dev/mapper/vg1-data1  4.7T  1.1T  3.6T  23% /usr/share/nginx/html
[root@sok ~]# 

Size of the volume now changed from 4.2T to 4.7T.

Back to lvm

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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