Programster's Blog

Tutorials focusing on Linux, programming, and open-source

VirtualBox - Expand Disk Image

Navigate to the folder containing your .vdi disk image file.

Run the following command to expand it:

VBoxManage modifyhd disk1.vdi --resize $SIZE_IN_MB

Then boot up the guest and open a terminal.

Enter the interactive fdisk tool for our disk.

sudo fdisk /dev/sda

Print out the partition table if you like. This can be useful.


Now we are going to delete all the existing partitions before recreating the root one (don't worry this works).

For each partition, delete it by pressing:


... and then entering the partition number. Repeat until all partitions are gone.


Create the root partition with:


Make it a primary partion


Accept the defaults if you wish for the root partition to fill the entire disk. If you get asked whether you wish to delete a signature, I did when testing and it still worked.

Make the partition bootable:


Write changes and quit:


If you feel you made a mistake and want to quit out without saving changes, use q.

Tell the system to perform a filesystem check next boot:

sudo touch /forcefsck

If you deleted a swap partition (or any other partitions that auto mount), make sure to remove them from /etc/fstab.

sudo vim /etc/fstab

If you accidentally forget this step, don't panic, you will just have to wait a loooong time for the VM to boot up.

Now reboot for the changes to take effect.

sudo reboot

Don't panic if it takes a little longer for your guest to boot up than normal.

Once your guest has rebooted and you have logged in again, resize the filesystem to fill the partition:

sudo resize2fs /dev/sda1


Last updated: 11th August 2022
First published: 22nd December 2019