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?


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

You can do this without rebooting centos 7 Assuming your disk is /dev/vda and standard rhel/centos partitioning.

Extend partition

# fdisk /dev/vda

Enter p to print your initial partition table.

Enter d (delete) followed by 2 to delete the existing partition definition (partition 1 is usually /boot and partition 2 is usually the root partition).

Enter n (new) followed by p (primary) followed by 2 to re-create partition number 2 and enter to accept the start block and enter again to accept the end block which is defaulted to the end of the disk.

Enter t (type) then 2 then 8e to change the new partition type to "Linux LVM".

Enter p to print your new partition table and make sure the start block matches what was in the initial partition table printed above.

Enter w to write the partition table to disk. You will see an error about Device or resource busy which you can ignore.

Update kernel in-memory partition table

If you have changed your partition table run the following command to update the kernel's partition table

# partx -u /dev/vda

Resize physical volume

Resize the PV to recognize the extra space

# pvresize /dev/vda2

Resize LV and filesystem

In this command centos is the PV, root is the LV and /dev/vda2 is the partition that was extended. Use pvs and lvs commands to see your physical and logical volume names if you don't know them. The -r option in this command resizes the filesystem appropriately so you don't have to call resize2fs or xfs_growfs separately.

# lvextend -r centos/root /dev/vda2