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.
p
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:
d
... and then entering the partition number. Repeat until all partitions are gone.
1
Create the root partition with:
n
Make it a primary partion
p
Accept the defaults if you wish for the root partition to fill the entire disk.
Make the partition bootable:
a
Write changes and quit:
w
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
Now reboot for the changes to take effect.
sudo reboot
Once your guest has rebooted and you have logged in again, resize the filesystem to fill the partition:
sudo resize2fs /dev/sda1
References
- 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