Friday, September 5, 2014

GParted - Increase disk size of a Linux native partition


Prerequisites:
You will need to download the GParted live CD ISO file so that you can use it later, you can get this here.
Below is an image displaying disk information on the server before we begin.
disk free and fdisk
It is important to identify that you are actually using a Linux native partition – as this is what we are extending. As you can see in the above image /dev/sda1 is listed as “Linux” and it has the ID of 83. The 83 hex code shows that it is a Linux native partition, while 8e shows a Linux LVM.
Note that /dev/sda1 is the partition we will be expanding.
Increasing the virtual hard disk
First off we increase the allocated disk space on the virtual machine itself.
VMware virtual disk increase
Booting into the GParted Live CD
Mount GParted live CD



Now we are ready to power on the virtual machine.
Once the virtual machine has powered on and you have booted to the CD, you will be presented with the following menu, just press enter to boot into GParted Live (Default Settings).
GParted
After some time you will then arrive at the following screen, for this I did not change anything and just accepted the defaults by pressing enter.
GParted
You will then be prompted to select a language, pressing enter defaults to English.
GParted
Next we select the default option 0 by pressing enter as we will be working with the GUI.
GParted
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.
GParted
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.
GParted
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.
GParted
After doing this, you should see /dev/sda2 (represented by the blue box) spread out over the unallocated space.
GParted
This change and all further changes will not yet be applied, you can see the tasks down the bottom of the GParted interface and these will be applied only once you click the Apply button. Alternatively you can click the Undo button to remove a pending change.
This time we want to select /dev/sda5 which is the swap partition and select Resize/Move, this will result in the following.
GParted
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.
GParted
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.
GParted
Select the /dev/sda2 extended partition and click Resize/Move.
GParted
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.
GParted
Once this is complete the disk will look like this.
GParted
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.
GParted
You will be able to perform this action straight away if you did not have swap in between /dev/sda1 and the unallocated space, the previous steps were to get swap out of the way in GParted.
Drag the arrow over so that the unallocated space is then consumed by /dev/sda1 as shown below, then click Resize/Move.
GParted
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. I have performed this method on a 400gb server in the past and to increase it 100gb took approximately 5 hours. In this example I am only increasing by 10gb and there is only about 1gb of data on the disk so this took approximately 2 minutes to finish applying.
Once complete you will see something similar to the below image, you will be able to click close once finished.
GParted
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.
Once the operating system has booted you can confirm that the disk space has expanded correctly. Below you can see that /dev/sda1 is now 30gb in size.
GParted


No comments:

Post a Comment