I use VirtualBox to create Linux development environments where I can install only packages needed for the projects I’m working on.

Last sunday I was working with Yocto to create my own Linux distro, so I created a new linux virtual machine with an HD of 60 GB. (the minimum HD required by yocto)

After a while (4/5 hours) I realized the space was not enough, so I had two choiches:

  1. Create a new virtual machine and restart the yocto process.
  2. Try to resize the HD 

I chose the second option, as I didn’t know how much space the operation would have required.

In a few steps, I was able to to resize my VirtualBox disk.

*** Resizing the disk could cause data loss, so make a backup copy of your data before proceeding ***

Step 1 – Resize the VDI disk

  • Shutdown the virtual machine
  • Make a backup of your vdi disk now, if you don’t have one, yet.
  • Run a windows prompt
  • from the Windows prompt move to the directory where your vdi file is located 

cd <vdi_file_location>

  •  Resize the vdi disk using the following command:

“c:\Program Files\Oracle\VirtualBox\VBoxManage.exe” modifyhd MyLinux.vdi –resize <new_size>

  • Where <new_size> is the size in MB you want to apply

Step 2 – Resize the Linux Partition

At this point your Linux operating system is not able to recognize the new size of your disk, for the opertating system that space is unallocated space.

  • Download GParted Live from here:  GParted Live ISO
  • In VirtualBox create a new virtual machine without adding a disk
  • Select the new virtual machine and in Settings select Storage.
  • For the CD device insert the GParted Live ISO, you have just downloaded.
  • For the HD, select the modified HD

virtual box settings
  • Start the new virtual machine, at the end of the boot you should see something like this:

gparted boot screen

 

  • take note of the size of the linux_swap partition
  • Right click on the linux_swap partition and delete it
  • Right click on the extended partition in which there was the linux_swap partition and delete it.
     
  • Right click on the partition you want to resize and select resize
resize partition with gparted
  • Re-create the swap partition
  • Right click on the unallocated space and select new 
create new partition
  • Select “Extended Partition” and click Add
  • Right click on the unallocated space and select new 
  • Create a new partition as “Logical Partition”, file system “linux-swap”
  • Set the size as in the annotated linux-swap
  • Click the Add button
  • Click the Apply button (note this operation could cause data loss)
  • power off the gparted virtual machine

Now it’s time to restart your original virtual machine, this time you should see a resized disk. If something went wrong you could restore data from the backup 

Gg