Extend LVM after adding new disk to the server Linux

This document describes the procedure to extend your existing mount point after adding the disk in RHEL 7 using LVM.

1.Please create partition on newly added disk

[root@linuxacademy1 ~]# gdisk /dev/xvdf
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1):
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}:
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300): 008a
Exact type match not found for type code 008A; assigning type code for
‘Linux filesystem’
Changed type of partition to ‘Linux filesystem’

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/xvdf.
The operation has completed successfully.
[root@linuxacademy1 ~]# gdisk /dev/xvdg
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}:
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300): 008a
Exact type match not found for type code 008A; assigning type code for
‘Linux filesystem’
Changed type of partition to ‘Linux filesystem’

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/xvdg.
The operation has completed successfully.

2.Now please create physical volume group

[root@linuxacademy1 ~]# pvcreate /dev/xvdf1 /dev/xvdg1
Physical volume “/dev/xvdf1” successfully created.
Physical volume “/dev/xvdg1” successfully created.
[root@linuxacademy1 ~]# pvdisplay

“/dev/xvdf1” is a new physical volume of “<20.00 GiB”
— NEW Physical volume —
PV Name /dev/xvdf1
VG Name
PV Size <20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID a52OwU-svuG-mR1O-wJ2E-pZ2i-HCFa-287P7I

“/dev/xvdg1” is a new physical volume of “<20.00 GiB”
— NEW Physical volume —
PV Name /dev/xvdg1
VG Name
PV Size <20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID cVCWqw-BSdi-FC00-e5JW-2dq9-QQH2-13q7eZ

[root@linuxacademy1 ~]# vgcreate battlestar /dev/xvdf1 /dev/xvdg1
Volume group “battlestar” successfully created
[root@linuxacademy1 ~]# vgdisplay
— Volume group —
VG Name battlestar
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 0 / 0
Free PE / Size 10238 / 39.99 GiB
VG UUID xtAtA6-4WZY-KZK8-wskY-QNcJ-YYKt-3XlSh1

3.Please create logical volume now

[root@linuxacademy1 ~]# lvcreate -n galactica -L 20G battlestar
Logical volume “galactica” created.
[root@linuxacademy1 ~]# mkfs -t xfs /dev/battlestar/galactica
meta-data=/dev/battlestar/galactica isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

4.Mount now.

[root@linuxacademy1 ~]# mkdir /mnt/mydir
[root@linuxacademy1 ~]# mount /dev/battlestar/galactica /mnt/mydir

5.Please add the extra disk to expand mount point

You can use following command to scan newly added disk online(No need to restart server)

echo “- – -” > /sys/class/scsi_host/host0/scan
 echo “- – -” > /sys/class/scsi_host/host1/scan

[root@linuxacademy1 ~]# gdisk /dev/xvdj
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1):
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}:
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300): 008a
Exact type match not found for type code 008A; assigning type code for
‘Linux filesystem’
Changed type of partition to ‘Linux filesystem’

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/xvdj.
The operation has completed successfully.

[root@linuxacademy1 ~]# partprobe

6.Extending volume group now

[root@linuxacademy1 ~]# pvcreate /dev/xvdj1
Physical volume “/dev/xvdj1” successfully created.
[root@linuxacademy1 ~]# vgextend battlestar /dev/xvdj1
Volume group “battlestar” successfully extended
[root@linuxacademy1 ~]# vgdisplay
— Volume group —
VG Name battlestar
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size <59.99 GiB
PE Size 4.00 MiB
Total PE 15357
Alloc PE / Size 5120 / 20.00 GiB
Free PE / Size 10237 / <39.99 GiB
VG UUID xtAtA6-4WZY-KZK8-wskY-QNcJ-YYKt-3XlSh1

[root@linuxacademy1 ~]# lvextend -L 59G /dev/battlestar/galactica
Size of logical volume battlestar/galactica changed from 20.00 GiB (5120 extents) to 59.00 GiB (15104 extents).
Logical volume battlestar/galactica successfully resized.
[root@linuxacademy1 ~]# lvdisplay
— Logical volume —
LV Path /dev/battlestar/galactica
LV Name galactica
VG Name battlestar
LV UUID 0C8PRN-HsxV-mnne-9Awb-Net4-zNAN-kpJrM9
LV Write Access read/write
LV Creation host, time linuxacademy1, 2017-10-16 05:06:56 -0400
LV Status available
# open 1
LV Size 59.00 GiB
Current LE 15104
Segments 3
Allocation inherit
Read ahead sectors auto
– currently set to 8192
Block device 253:0

7.Please check disk space now and this has not reflected new size

[root@linuxacademy1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda2 10G 1.9G 8.2G 19% /
devtmpfs 477M 0 477M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 13M 483M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/1001
tmpfs 100M 0 100M 0% /run/user/0
/dev/mapper/battlestar-galactica 20G 33M 20G 1% /mnt/mydir

 

8.Please use following command to resize mount point

For XFS file system

[root@linuxacademy1 ~]# xfs_growfs /mnt/mydir
meta-data=/dev/mapper/battlestar-galactica isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 5242880 to 15466496

For Ext4 file system

[root@linuxacademy1 ~]# resize2fs /dev/mapper/battlestar-galactica
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/oemcc-oemcc is mounted on /oemcc; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 7
The filesystem on /dev/mapper/oemcc-oemcc is now 14680064 blocks long.

[root@linuxacademy1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda2 10G 1.9G 8.2G 19% /
devtmpfs 477M 0 477M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 13M 483M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/1001
tmpfs 100M 0 100M 0% /run/user/0
/dev/mapper/battlestar-galactica 59G 33M 59G 1% /mnt/mydir

About the Author

debasis maity

12+ years of rich experience on Database Administrations and on Infrastructure Solution Architect. AWS Certified Solution Architect and Senior Oracle DBA

0 thoughts on “Extend LVM after adding new disk to the server Linux

Leave a Reply

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