Fix unallocated disk space to extend a disk partition in Ubuntu Debian RHEL and CentOS

It is a very common issue for configured Linux Machine's disk space not to reflect all its resources. To successfully allocate all the Disk space capacity to the disk partition, a careful approach needs to be applied. It is important to not that doing it the wrong way could be devastating and result to loss of data.



This guide will put you through the safest method to allocate all the available disk resources in your Linux Machine. This approach has been tested on the most popular Linux distribution such as Debian, Ubuntu, CentOS and others.


Changing the Partition Table

To start with, we need to change the Partition table to ensure that sda2 terminates at the end of disk. Following the process in this guide is very safe and you will not loose any data. At some point in this process, a reboot of the server will be done to enable changes to be fully effected.


The first thing to do is to enable the terminal enter fdisk mode. Use the command below;


fdisk /dev/sda


Then Enter "p" which is a print function to print the current partition table. It is vital to note the numeric values of the START and END columns for the /dev/sda2  partition.


Next Enter "d" to access the delete mode in order to delete the existing partition. Note that the first partition is the "/boot" and partition 2 stated above is the root partition.


Then you should type "n" in order to create a new Partition in place of the previous displaced one. This can be achieved by selecting the same numeric Value as before (2). This should be made default and make sure the end of the disk is reached.


Afterwards, type "t" then "2" followed by "8e" to modify the new partition type to "Linux LVM".


At this stage , you can print the new partition to the disk by Entering "p". It is important to ensure that the start block matches what was in the first partition table printed previously.


Finally Enter "w" to write the partition table to the disk. You might see an error but this doesn't have any effect on the disk.


Rebooting the Machine

To ensure that your settings are fully applied to the system, it is recommend that you reboot the machine and this will correct the error that might appear while completing the processes above.


Expanding the LVM Partition

As soon as the system completed the rebooting process, you can extend the LVM partition by applying the command;

pvresize /dev/sda2


You should do a second reboot of the machine to ensure that this process is successfully applied.




Extending the Logical volume

partition space is now ready to accommodate the logical volume. You can get the right path via the command;


lvdisplay -v


It should be the first in the list.Lets say the path is /dev/path, you can extend the logical volume via the command;

lvextend -l +100%FREE /dev/path


Extending the File System

The file system's volume needs to be same with the extended logical volume since it was extended to use all the unallocated disk space. To achieve this, simply run the following commands:


For EXT4 system, run;

resize2fs /dev/vg/lv_root



While for XFS file system, run;

xfs_growfs /root



Having to deal with allocating all the disk space is a very delicate process and Care needs to be taken to avoid loosing all your data. This why you need Experts in Server Administration to handle such processes for your and your organization.

Allowing your server disk to use all its disk space will help to improve the functionality and performance of your server in general. It is very common for unallocated disk space to be unused by default.

Related Posts