DEV Community

Vuk Stojkovic
Vuk Stojkovic

Posted on

Extending Virtual Machine memory

Have you ever been in situation where you don't have enough memory in your virtual machine? As the matter of fact, this issue was very urgent in my case. Namely, I used Oracle VM Ubuntu 20.04 LTS machine in order to run ROS (Robotic Operating System) application. This one required that very specific Ubuntu version, and since I've been using 22.04 as the main OS, I proceeded with Oracle VM.

During installation, I dedicated 50GB for the entire VM image, without any idea how robust ROS application actually is. ROS automated script stalled in the middle of the installation due to lack of memory. Getting completely new VM image with the more memory was time consuming, and I was sure that there must be a quicker way to extend the existing disk memory. And I was right.

Oracle Virtual machine is essentially a .vdi file stored in your local system. All I had to do was to resize (expand in my case) existing allocated memory. Above-mentioned .vdi file is located at:

~/VirtualBox VMs/Ubuntu 20.04

The command used to extend the disk size was:

VBoxManage modifyhd "Ubuntu 20.04.vdi" --resize 122880

Resize flag will accept disk size in Mb, which was 120GB in this case.

Finally, I had to use GParted in order to memory changes within the VM disk. The idea was to use GParted ISO file to boot your VM. It comes with a simply GUI that helps you to manually enable memory expansion of selected partition.

Step are following:

  1. Download GParted ISO file
  2. Configure your VM to boot it: Settings -> Storage. Under Controller: IDE, right click on Empty disk, using Optical Drive disk icon on the right side select Choose a disk file in order to identify GParted iso file. OK!

Starting VM will boot GParted partition manager.
You will have to go through 3 basic configuration steps at the beginning, to choose the Keymaps (no keymaps), Language (British, my dear) and the way how to start GParted (automatically - can't be wrong).

Voilà!

Booting GParted

Start GParted

You will notice that /dev/sda2/ partition, in the File System column have a extended tag. Right click on to Resize/Move. Drag the rectangular till the end, or manually enter extended disk size in MBs and click Resize/Move:

Resizing disk space

Next, conduct the same step for /dev/sda5 partition and Apply all operations:

Apply operations

Upon successful finish, Exit and turn off VM. Good thing - GParted just extended disk size, and it won't reboot again. It was short-term helper that saved my day and disappeared immediately. Lovely.

Now all you have to do is to ensure that your disk size is extended. Simple command:

df -h

Check your partition, and Avail column.

That should be it.

Hopefully you'll find this quick post useful, as it was for me. GParted can be generally used to manage your partitions, or to, for instance, format you external devices. Pretty handy tool.

Have a good one! 😊

Top comments (0)