Visit VMARENA.COM For More Advanced Technical Posts , Learn More .

Monday, March 13, 2017

Increase disk size of a Linux VM native partition Using GParted

Increase disk size of a Linux VM native partition


Here I explain how to increase disk space for a VMware virtual machine that is using a Linux native partition rather than logical volume manager (LVM).

Firstly we will increase the size of the virtual disk on the virtual machine at the hardware level and then once this is complete we will boot into a GParted live CD and perform the changes required to make use of the additional disk space so that the operating system is able to use it.

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.

Prerequisites: GParted live CD ISO ,

Download #   http://downloads.sourceforge.net/gparted/gparted-live-0.28.1-1-amd64.iso


I will be working with a VMware virtual machine running Debian Linux,with20gb disk and we will be increasing it by 10gb for a total final size of 30gb.

1. Log in to the linux vm and verify the partitions  using df -h command



It is important to identify that you are actually using a Linux native partition .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 .
Note:- that /dev/sda1 is the partition we will be expanding.
2. Increasing the virtual hard disk
First off we increase the allocated disk space on the virtual machine itself. 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.



Note:- 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 on the fly, if this is the case shut down and make the change, do not power the virtual machine .



3. Attach the GParted Live CD ISO to vm and boot with that

Right click on the virtual machine in vSphere and select “Edit Settings” to bring up the properties.
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.




4. Change the Boot setting of the VM

Select for the boot options to be presented on the next boot so you 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.



5. Power on and VM 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).


6. Next Screen do-not change anything and just accepted the defaults by pressing enter.



7. You will then be prompted to select a language, pressing enter defaults to English.



8. Next we select the default option 0 by pressing enter as we will be working with the GUI.



9. 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.



As you can see the original /dev/sda1 partition have 20gb disk and  new unallocated 10gb .Also there is a space between the two is the swap space.
The total /dev/sda disk size of 30gb is also shown.

Here we have to modify  /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.

10. 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.

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.


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


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.

11.  select /dev/sda5 which is the swap partition and select Resize/Move, this will result in the following.


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.





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.



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


13. 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.


Once this is complete the disk will look like below.



14. 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.



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.

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



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 :-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.

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



17. 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.


18. Once the operating system has booted verify that disk space has expanded correctly. Below you can see that /dev/sda1 is now 30gb in size.
























No comments:

Post a Comment