Two Methods to Grow A VirtualBox Disk Image (.vdi) 🌱

NOTE: Make a backup copy of the .vdi before attempting these steps

In this example, we'll be taking an 8GB Raspberry Pi OS VirtualBox VM and increasing the .vdi disk size to 32GB

Method 1: Increasing the .vdi size

This method requires that the virtual disk be dynamically allocated. If the .vdi is fixed size the size cannot be changed and VirtualBox will throw an error when you try to resize it

  1. Launch VirtualBox Manager
  2. Select File > Virtual Media Manager
  3. Find and click the .vdi file to increase in size
  4. Change the size at the bottom of the dialog window
  5. Click Apply and then Close
  6. Download the GParted live disc Download
  7. Back in VirtualBox Manager, right click the VM using the resized .vdi > Settings...
  8. Select Storage from the left navigation pane
  9. Click on or add a new optical drive
  10. Select the disc dropdown to the right > Choose a virtual optical disc file...
  11. Browse to and select the downloaded GParted .iso file
  12. Click OK
  13. Make sure the VM using the resized .vdi is selected and click Start > Normal
  14. If prompted, press a key to boot to the CD-ROM
  15. GParted should begin loading
  16. Follow the prompts to set a keyboard layout and language
  17. GParted will automatically start once the desktop environment is displayed
  18. In the top right corner, select the correct device identifier to work with (ie /dev/sdb)
  19. In the middle section of the interface, right click the partition to resize > Resize/Move
  20. Drag the slider or set the numerical values to set the new partition size > Click Resize
  21. Click the check mark icon at the top center of the interface to Apply All Operations
  22. Once the resizing has completed, shutdown the VM
  23. Back in VirtualBox Manager, right click the VM > Settings...
  24. Select Storage from the left navigation pane
  25. Click on the optical drive
  26. Select the disc dropdown to the right > Remove Disk from Virtual Drive
  27. Click OK
  28. Make sure the VM is selected and click Start > Normal
  29. The VM should boot normally with the OS showing the additional storage available

Method 2: Cloning to a new, larger .vdi

This method can be used on either fixed size or dynamically allocated virtual disks

  1. Launch VirtualBox Manager
  2. Select File > Virtual Media Manager
  3. Click the Create icon at the top left of the dialog window
  4. Select VDI > Next
  5. Select Dynamically allocated > Next
  6. Set the file location and disk size > Create
  7. Click Close
  8. Download the GParted live disc Download
  9. Back in VirtualBox Manager, right click the VM > Settings...
  10. Select Storage from the left navigation pane
  11. Click the Controller to select it > Add Hard Disk...
  12. Find and select the .vdi created previously > Choose
  13. Click on or add a new optical drive
  14. Select the disc dropdown to the right > Choose a virtual optical disc file...
  15. Browse to and select the downloaded GParted .iso file
  16. Click OK
  17. Make sure the VM using the resized .vdi is selected and click Start > Normal
  18. If prompted, press a key to boot to the CD-ROM
  19. GParted should begin loading
  20. Follow the prompts to set a keyboard layout and language
  21. Once the desktop environment loads, minimize the GParted application
  22. Launch the terminal application from the desktop
  23. Run the following commands making absolutely certain the source/if and destination/of are input correctly in the dd command
    # output disk information, note the disk identifier for the source and destination targets
    sudo fdisk -l
    # use dd to clone the source to the destination
    dd if=/dev/sda of=/dev/sdb bs=4M status=progress
  24. Once dd has completed, restore the minimized GParted application
  25. In the top right corner, select the new larger device identifier to work with (ie /dev/sdb)
  26. In the middle section of the interface, right click the partition to resize > Resize/Move
  27. Drag the slider or set the numerical values to set the new partition size > Click Resize
  28. Click the check mark icon at the top center of the interface to Apply All Operations
  29. Once the resizing has completed, shutdown the VM
  30. Back in VirtualBox Manager, right click the VM > Settings...
  31. Select Storage from the left navigation pane
  32. Click on the optical drive
  33. Select the disc dropdown to the right > Remove Disk from Virtual Drive
  34. Right click on the original virtual disk > Remove Attachment
  35. Click OK
  36. Make sure the VM is selected and click Start > Normal
  37. The VM should boot normally with the OS showing the additional storage available