This occurs mainly because main partition is followed by a smaller Linux SWAP partition. This small partition behaves like a boundary between the main partition and the empty unallocated space after the SWAP partition.
The VirtualBox is not smart enough to allocate more memory to the main partition by skip this small partition. In such scenario we have to move the swap partition a little bit and allocate more memory to the main partition manually.
In this post we are going to look at a way in which we can manually allocate more memory to the main partition using a tool called GParted.
General Disclaimer: Before doing anything mentioned in this post please take a backup of your virtual machine, because if something goes wrong then it can cause a lot of damage to your data and Author cannot be held responsible for that :)
These are the steps involved to manually allocate more space to the virtual hard drive.
Resize the logical capacity of the virtual disk if required
This step is only required if your logical capacity of the virtual disk is smaller than what you actually want. VirtualBox 4.0+ now directly supports resizing the logical size of the virtual disk. Run the following commands on the host OS to resize the logical capacity of the virtual disk
This command should show you details about the virtual disk.
As we can see the current logical size of the disk is around 108 GB. Let's increase the logical from 108 GB to around 500 GB. Run the following command to achieve this.
Remember that the parameter to the --resize option is the new size in MB's its not the delta but actually the new size in MB's.After running this command if we run the showhdinfo command again we should see the change has taken place
As we can see the logical size of the virtual disk has been increased from around 108 GB to 500 GB. We have achieved what we intended to do in this step. Let's move on with the next step.
Download and mount the GParted ISO
Download the GParted ISO from here. We don't need to burn it to a disk just keep the ISO download to the host OS.
Open the VirtualBox GUI and open the settings of the desired VM. Under the Storage section click the "Add CD/DVD device" option. A dialog will open up asking whether you want to keep the CD/DVD drive empty or choose an ISO to mount. At this step click "Choose Disk" and mount the downloaded GParted ISO.
Now navigate to the System --> Motherboad section of the Settings dialog and make the CD/DVD as the first option in the Boot Order. This will make sure that the GParted will be given an opportunity to load before The Guest OS is booted.
We are all set, now lets do the actual resizing.
Making Sure that Boot from CD/DVD is the first option |
We are all set, now lets do the actual resizing.
Boot the GParted
Now start the VM, since the GParted ISO is mounted on the CD/DVD drive, it will show us an option to Boot the GParted Live. Just press enter on "GParted Live (Default Settings)".
After a few anxious moments you should see a screen similar to this one, do not change anything just click OK
Dont change anything on this screen, Click OK |
Next screen lets you select language (English is selected by default). If you want to change it then enter the number against the language name to choose that language and then press Enter.
Choose Language |
Mode for start GParted, select 0 |
The Home screen of GParted |
Resizing the main partition
First we will need to move the SWAP partition a bit. We have to move it in such a way that there is enough unallocated space between the main partition and SWAP partition.
Select the SWAP partition and Click the "Resize/Move" button at the top. A dialog will be shown that will let us move the SWAP partition.
Dialog to resize SWAP partition |
Moving the SWAP partition towards right |
After you are satisfied with the size click the "Resize/Move" button. This will show a warning dialog like this one, just click OK.
Warning informing abou the side effects of the moving SWAP partition |
Notice the Free Space between Main and SWAP partitions. |
Now there is space to expand the Main partition. |
Expand the Main partition to occupy the entire unallocated space |
Once you come out of the Resize dialog, the disk should look something like this
Updated disk sizes, notice that the Main has expanded |
Doing the processing when Apply is clicked |
Done Applying the Change |
Shutdown GParted |
Making Hard Disk as the first option to boot from |
That's all folks! Until we meet again, Have Fun!