How to increase Linux partition

increase Linux partition
5/5 - (3 votes)

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:

increase linux partition

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

How to increase Linux partition

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

How to increase Linux partition

We want LVM, so type 8e.

learn to increase Linux partition

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.

increase hard disk in linux

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.

Related articles