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.
Make the partition bootable:
Write changes and quit:
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
sudo vim /etc/fstab
Now reboot for the changes to take effect.
Once your guest has rebooted and you have logged in again, resize the filesystem to fill the partition:
sudo resize2fs /dev/sda1
- Ask Ubuntu - How do I increase the hard disk size of the virtual machine?
- Programster's Blog - Expand Qcow2 Root Filesystem
First published: 22nd December 2019