Use GParted to increase disk size of a Linux native partition

Share This:

Use GParted to increase disk size of a Linux native partition 1

If you have a Linux virtual machine in VMware, there might be a time when you need to increase the disk size of a Linux native partition. In this article, we’ll guide you through the process using a GParted Live CD (available at gparted.org). Important Notes: During the time that the GParted ISO is mounted you will be booted into this live CD rather than your normal operating system, basically meaning that during this process there will be down time from normal server operations. Be very careful when following this article as this process has the potential to cause a lot of damage to your data. If you are working with virtual machines make sure you take a snapshot of your virtual machine beforehand, or otherwise have some other form of up to date backup before proceeding. Note that a snapshot must not be taken until after the virtual disk has been increased in the first step below, otherwise you will not be able to increase the disk until it has been removed. It could also be worth cloning the virtual machine first and testing out this method on the clone.

Increasing the Virtual Hard Disk

The first step is to increase the allocated disk space on the virtual machine. This is done by right clicking the virtual machine in vSphere, selecting edit settings, and then selecting the hard disk. In the below image I have changed the previously set hard disk of 20gb to 30gb while the virtual machine is up and running. Once complete click OK, this is all that needs to be done in VMware for this process.

Use GParted to increase disk size of a Linux native partition 2

If you are not able to modify the size of the disk, the provisioned size setting is greyed out. This can happen if the virtual machine has a snapshot in place, these will need to be removed prior to making the changes to the disk. Alternatively you may need to shut down the virtual machine if it does not allow you to add or increase disks.

Booting into the GParted Live CD

Right click on the virtual machine in vSphere and select “Edit Settings“.

Select the CD/DVD Drive and then select your GParted ISO, in this instance I have already uploaded this file to the datastore so I have just clicked the browse button to select it. Make sure that connect at power on is ticked.

Use GParted to increase disk size of a Linux native partition 3

I have also selected for the boot options to be presented on the next boot so that I can select to boot into the ISO easier. You can also adjust the time to delay the boot so that you have appropriate time to select that you want to boot from CD, in the below image this is set to 5 seconds, and force to boot into BIOS is enabled so that I can select to boot from CD on next boot.

Use GParted to increase disk size of a Linux native partition 4

When you power on your virtual machine, you can go into the BIOS and change the boot order so that it boots to the CD drive before the hard disk. Once you get to this GParted boot screen, you can enter through all of the default options unless you want to change the language.

Use GParted to increase disk size of a Linux native partition 1

Use GParted to increase disk size of a Linux native partition 6

Use GParted to increase disk size of a Linux native partition 7

Use GParted to increase disk size of a Linux native partition 8

Once complete you will be presented with the GUI with GParted already open, if it is not already open you can select it from the Desktop icon.

Use GParted to increase disk size of a Linux native partition 9

As you can see the original /dev/sda1 partition that is making use of the 20gb disk is there, as well as the new unallocated 10gb from when we increased the size of the virtual hard disk earlier. The space between the two is the swap space. The total /dev/sda disk size of 30gb is also shown.

What needs to be done now is get /dev/sda1 to take up that unallocated space, this is not currently possible because swap is in the way so we need to move things around. If you do not have swap in between the partition to be extended and the unallocated space then you will be able to skip down a few steps until you arrive at the image where /dev/sda1 and the unallocated space are next to each other.

First we select /dev/sda2 which is the extended partition containing the swap, we want to expand this to include the 10gb of unallocated space.

Select /dev/sda2 and click “Resize/Move” and you will be presented with the following:

Use GParted to increase disk size of a Linux native partition 10

Basically you just need to drag the black arrow of /dev/sda2 all the way to the end of the unallocated space and click the Resize/Move button.

Use GParted to increase disk size of a Linux native partition 11

After doing this, you should see /dev/sda2 (represented by the blue box) spread out over the unallocated space.

Use GParted to increase disk size of a Linux native partition 12

Next, we want to select /dev/sda5 which is the swap partition and select Resize/Move, this will result in the following.

Use GParted to increase disk size of a Linux native partition 13

This time rather than expanding the partition, we want to just move swap all the way to the end of the /dev/sda2 space that it is in, this is done by just dragging the box to the end which will then look like this.

Use GParted to increase disk size of a Linux native partition 14

Click the Resize/Move button and then a warning may appear informing you that moving a partition might cause your operating system to fail to boot. It also warns that performing this move may take a long time to apply, read the warning then click OK to continue.

The GUI should now look something like the below image, where /dev/sda1 is located right next to /dev/sda2 which contains the unallocated space.

Use GParted to increase disk size of a Linux native partition 15

Select the /dev/sda2 extended partition and click Resize/Move.

Use GParted to increase disk size of a Linux native partition 16

Drag this to the right so that only the swap space is contained and the grey unallocated space is freed, click Resize/Move once complete.

Use GParted to increase disk size of a Linux native partition 17

Once this is complete the disk will look like this.

Use GParted to increase disk size of a Linux native partition 18

Now we have /dev/sda1 next to the unallocated space so we are finally ready to expand /dev/sda1. Select /dev/sda1 and click the Resize/Move button.

Use GParted to increase disk size of a Linux native partition 19

Drag the arrow over so that the unallocated space is then consumed by /dev/sda1 as shown below, then click Resize/Move.

Use GParted to increase disk size of a Linux native partition 20

Once this is done the /dev/sda1 partition will now be using the unallocated space that was previously there. All that is left to do is click the apply button which will apply the changes – you will be prompted to confirm with a warning that data loss may occur.

Note that this may take a while depending on how much of the disk is currently in use and the amount of disk space you are increasing, because a file system check (fsck) is run before the expansion and after it to ensure that there are no issues.

Once complete you will see something similar to the below image, you will be able to click close once finished.

Use GParted to increase disk size of a Linux native partition 21

Everything is now finished, you just need to reboot the virtual machine and then boot from disk rather than CD, alternatively shut down the virtual machine and unmount the live CD and then power it back on.


Share This:

 

Leave a Reply