Linux – Trying to increase centos-root partition size to consume full SSD capacity

disk-volumelinux

I have cent-os 7 installed on an ssd with capacity 160GB. The Cent-os partitions only consume 20GB in total, such that when I run fdisk -l this is my output:

Disk /dev/sda: 171.8 GB, 171798691840 bytes, 335544320 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: 0x000a2b1e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM

Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-root: 18.8 GB, 18798870528 bytes, 36716544 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

When I try to run pvs I get the following:

  PV         VG     Fmt  Attr PSize  PFree
  /dev/sda2  centos lvm2 a--  19.51g    0

What steps do I need to take in order to get CentOS to recognise the full 160GB physical volume, and then be able to either extend centos-root directly or first create another logical partition (of size 140GB), remove it and then allow centos-root to expand into the that space?

Apologies if my terminology is incorrect, I'm not a Linux expert.

Best Answer

Your physical volume is 19.51g with no free space (pvs results). So you first have to resize the physical volume.

pvresize /dev/sda2

Then you need to resize the logical volume centos-root to fill all the free space.

lvresize -l +100%FREE /dev/mapper/centos-root

Now its time for the filesystem. Its not obvious what filesystem you are using but i bet that its either ext4 or xfs.

In the first case:

resize2fs /dev/mapper/centos-root

In the second case:

xfs_growfs /
Related Topic