In this tutorial, I will explain how to extend a partition on Linux (Ubuntu).
This type of operation is common when using virtual machines on Hyper-V for example or on VPS (Virtual Private Server).
Before doing anything, you need to make a backup of the virtual machine or the data on it even before the disk expansion operation.
The operation requires a restart.
Hyper-V: extend a virtual disk
This can be done with the virtual machine turned on.
From the parameters of the virtual machine, go to the disk to extend 1 and click on Modify 2.
Select the Extend 1 action and click Next 2.
Enter the new size 1 and click Next 2.
Validate by clicking on Finish 1.
Extend Volume on Linux
The operation is performed on the command line
Enter the following command for the disk space on the linux computer
As we can see from the screenshot below, the additional 10G is not available.
Now enter the following command to display the list of disks and partitions:
sudo fdisk -l
With the fdisk command, we can see that the disk is 60 GB, but an error is displayed GPT PMBR size mismatch.
If you have this error, you must correct it before you can expand the disk.
Enter the following command to correct the error:
sudo parted -l
The parted tool detects the error and offers us to correct the error by entering Fix.
Enter the fdisk -l command again to verify that the error is no longer present.
Now that everything is good, we’ll move on to modifying the score. In the tutorial, I modify the sda disk and the sda2 partition. The controls should be adapted to your environment.
Open the fdisk tool on the disk:
sudo fdisk /dev/sda
The first step is to delete the information from the partition. Enter the d command and indicate partition 2.
It is now necessary to create a new partition which will take into account the new blocks. Enter the n command, then indicate the number of the partition 2, for the start and end sector of the partition, I leave the default value proposed by the tool.
If the score contains signatures, enter N so as not to delete them.
It remains only to write the information to the disk, enter the command w.
Restart the computer using the following command:
Once the computer has restarted, we have one command left to make to enlarge the partition:
Check the size of the partition by entering the command again: df -h
We can see that the 10G has been added to the sda2 partition.