Definitions
PV - Physical volume
VG - Volume Groups
LV - Logical Volumes
FS - File System
Don't forget:
PV cannot belong to more than one VG
VG can be part of one or more PVs (i.e. /dev/sdb1)
LV can only belong to a single VG
To show all PV, VG and LV information
vgdisplay -v
Check block devices
[root@vmtools01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 500M 0 part /boot
└─vda2 252:2 0 4.5G 0 part
├─centos-root 253:0 0 4G 0 lvm /
└─centos-swap 253:1 0 512M 0 lvm [SWAP]
Check the FS we want to increase
[root@vmtools01 ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 4.0G 1.2G 2.9G 29% /
Look for the Volume Group (VG) it belongs to
[root@vmtools01 ~]# lvdisplay /dev/mapper/centos-root | grep "VG Name"
VG Name centos
Check if we have available space on the VG
[root@vmtools01 ~]# vgs centos
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 4.51g 40.00m
As shown above no available space on VG, so We need to increase VG first
Create new partition using fdisk
[root@vmtools01 ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/vda: 26.8 GB, 26843545600 bytes, 52428800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000616f9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 10485759 4729856 8e Linux LVM
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (10485760-52428799, default 10485760):
Using default value 10485760
Last sector, +sectors or +size{K,M,G} (10485760-52428799, default 52428799):
Using default value 52428799
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/vda: 26.8 GB, 26843545600 bytes, 52428800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000616f9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 10485759 4729856 8e Linux LVM
/dev/vda3 10485760 52428799 20971520 83 Linux
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vda: 26.8 GB, 26843545600 bytes, 52428800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000616f9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 10485759 4729856 8e Linux LVM
/dev/vda3 10485760 52428799 20971520 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
Renew the partition table
[root@vmtools01 ~]# partprobe
Create Physical Volume (PV)
[root@vmtools01 ~]# pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created.
Check PV's, The new one should be there
[root@vmtools01 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size 4.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1154
Free PE 10
Allocated PE 1144
PV UUID kGW5m5-wDQU-LYC2-GQPQ-3pdu-nyDP-6HAp3g
"/dev/vda3" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vda3
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID puf07O-Fpoj-sYEs-9xnM-gIW0-n64a-GJPfSF
Extend centos Volume Group (VG)
[root@vmtools01 ~]# vgextend /dev/centos /dev/vda3
Volume group "centos" successfully extended
Now PV should belongs to centos VG
[root@vmtools01 ~]# pvdisplay /dev/vda3
--- Physical volume ---
PV Name /dev/vda3
VG Name centos
PV Size 20.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 5119
Free PE 1289
Allocated PE 3830
PV UUID puf07O-Fpoj-sYEs-9xnM-gIW0-n64a-GJPfSF
Check VG available space
[root@vmtools01 ~]# vgdisplay centos | grep " Free PE"
Free PE / Size 5129 / 20.04 GiB
or
[root@vmtools01 ~]# vgs centos
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 24.50g 20.04g
Extend 15 GB root Logical Volume (LV)
[root@vmtools01 ~]# lvextend -L+15G /dev/centos/root
Size of logical volume centos/root changed from 3.97 GiB (1016 extents) to 18.97 GiB (4856 extents).
Logical volume centos/root successfully resized.
or also it could be increace to 15GB
[root@vmtools01 ~]# lvextend -L15G /dev/centos/root
Size of logical volume centos/root changed from 3.97 GiB (1016 extents) to 15.00 GiB (3654 extents).
Logical volume centos/root successfully resized.
Perform an online resize to resize the logical volume
[root@vmtools01 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=260096 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=1040384, imaxpct=25= crc=0 finobt=0 spinodes=0
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 1040384 to 4972544
Check available space
[root@vmtools01 ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 19G 1.2G 18G 6% /
P.S
We have still 5GB available in our VG
[root@vmtools01 ~]# vgs centos
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 24.50g 5.04g
Use -T option on df to get FS type
[root@vmtools01 ~]# df -Th /
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 4.0G 1.2G 2.9G 29% /
No comments:
Post a Comment