How to increase Linux partition

If you are a system administrator, you know that increasing a Linux partition is a common task: as data grows, you may need to extend a partition or a disk. In this post from the series of Avanetco Linux guides, we cover how to do it.
When you present a new LUN or extend a virtual disk in VMware, you need to run a few commands to increase the Linux partition.
In this scenario we add an LVM partition to cover the more complex case, but you can use these steps for any other file system. We skip the part where you add the capacity itself, whether by presenting a new LUN or extending your VM disk.
First, list your partitions and their mount points with fdisk -l:

Now enter the fdisk interactive menu by specifying the hard disk you want, like sda3:

After creating the partition, specify its type. Press L to see the list of available partition type codes:

We want LVM, so type 8e.

Press w to save all settings, then run the following commands:
partprobe -s # or: reboot pvcreate /dev/sdaXXX vgdisplay
vgdisplay shows the details of your LVM partition. Copy its name and go to the next step.

In the last step, run the commands below and replace every X with your own values. Note that these lines are for LVM: if you use another file system, you do not need them, and you should change xfs to your file system type.
vgextend vg-nameXX /dev/sdaX pvscan lvextend /dev/mapper/vg-nameXX /dev/sdaX xfs_growfs /dev/vg-nameXX /root
That’s it: you now know how to increase a Linux partition. Finally, check that everything is configured correctly with df -h.