Extend Partition CentOS 7 – How to Extend Partition with Unallocated Space on CentOS 7

centos7disk-space-utilization

I have centos 7 server (CentOS Linux release 7.3.1611 (Core)) When I was updated my server I saw error you need extra space. But I had 20GB disk on server when I check disk spaces I saw only 4.5GB partition created and 16GB partition is free space no unallocated.
How I can extend partition from 16GB free space?

lsblk:

NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0   20G  0 disk
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0  4.5G  0 part
  ├─centos-root 253:0    0    4G  0 lvm  /
  └─centos-swap 253:1    0  512M  0 lvm  [SWAP]
sr0              11:0    1 1024M  0 rom

enter image description here

Best Answer

There are three steps to make:

  1. alter your partition table so sda2 ends at end of disk
  2. reread the partition table (will require a reboot)
  3. resize your LVM pv using pvresize

Step 1 - Partition table

Run fdisk /dev/sda. Issue p to print your current partition table and copy that output to some safe place. Now issue d followed by 2 to remove the second partition. Issue n to create a new second partition. Make sure the start equals the start of the partition table you printed earlier. Make sure the end is at the end of the disk (usually the default).

Issue t followed by 2 followed by 8e to toggle the partition type of your new second partition to 8e (Linux LVM).

Issue p to review your new partition layout and make sure the start of the new second partition is exactly where the old second partition was.

If everything looks right, issue w to write the partition table to disk. You will get an error message from partprobe that the partition table couldn't be reread (because the disk is in use).

Reboot your system

This step is neccessary so the partition table gets re-read.

Resize the LVM PV

After your system rebooted invoke pvresize /dev/sda2. Your Physical LVM volume will now span the rest of the drive and you can create or extend logical volumes into that space.

Related Topic