CentOS 7 LVM Partitioning Resizing

LVM Extension – Resize partition Method, no need to create a new partition. This is for the CentOS 7 based images

1. Resize disk in VMWare
2. As root use fdisk to delete the LVM partition, and then create a new one using all the space, and change the partition type to 8e – Linux LVM

fdisk /dev/sda
Command (m for help): p

Disk /dev/sda: 68.7 GB, 68719476736 bytes, 134217728 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: 0x000e5376

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 67108863 32504832 8e Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-134217727, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-134217727, default 134217727):
Using default value 134217727
Partition 2 of type Linux and of size 63 GiB is set

Command (m for help): t
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sda: 68.7 GB, 68719476736 bytes, 134217728 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: 0x000e5376

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 134217727 66059264 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.

Detect new space:

# partprobe -s
/dev/sda: msdos partitions 1 2

Extend LVM Physical Volume

pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos_centos7 lvm2 a-- <63.00g 32.00g

Extend LVM Volume Group

lvextend -l +100%FREE /dev/centos_centos7/root
Size of logical volume centos_centos7/root changed from <27.80 GiB (7116 extents) to <59.80 GiB (15308 extents).
Logical volume centos_centos7/root successfully resized.

Grow XFS file system to new space

xfs_info /dev/centos_centos7/root
meta-data=/dev/mapper/centos_centos7-root isize=512 agcount=4, agsize=1821440 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=7285760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3557, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
xfs_growfs /dev/centos_centos7/root
meta-data=/dev/mapper/centos_centos7-root isize=512 agcount=4, agsize=1821440 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=7285760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3557, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7285760 to 15675392

Leave a Reply