I recently ran out of space on my VirtualBox VM and found that it’s difficult to increase the size of your HDD. One option is to simply add another disk.
If you’d rather increase the size of an existing vdi file, you will need to use a Partition Editor. There is another blog about this here.
So, to add another HDD, Start the VirtualBox Manager, select the VM, click on Settings, then select Storage,.then right click on the SATA controller and select the Add Hard Disk option.
Use the ‘Create New Disk’ option to create a new vdi file.
Choose the Dynamically Allocated option.
Enter a name for the disk and choose the size, then press Create.
Now start the VM and login as root. Open a Terminal window and enter:
Here we can see the new disk: /dev/sdb 42,9 GB
Firstly, we’ll create a partition.
Enter ‘p’ to see information about the disk.
To create a new partition, issue the command “n” and then select “p” for primary and 1-4 depending on which partition on the drive this is (first, second, third, or fourth), and the size: 42949672960 bytes / 83886080 sectors.
Left the last sector as the default (83886079) for a 40GB partition.
Then enter ‘w’ to save and exit fdisk.
Now we can use the mkfs command to create a file system on the new disk.
mkfs.ext3 /dev/sdb1 (Where sdb1 is Partition 1)
Next, create a mount point and mount the disk.
mount /dev/sdb1 /u01
Then edit the /etc/fstab file so the disk mounts when the VM starts.
Add the device mountpoint fstype options dump fsck
/dev/sdb1 /u01 ext3 defaults 0 0
Save the file then shutdown and restart the VM.
The df -h command shows the /u01 directory:
So now we have another 40GB of disk space.