Yes you can. (But before you do, make sure to back up your data.)
The exact procedure depends on whether you chose to create a dynamic or fixed size disk when you created the virtual drive, on your host OS, and on your version of VirtualBox.
If you created a dynamical disk and you're running version 4.0 (or higher), you need to do the following:
Resize the dynamical drive using the command line tool:
$ VBoxManage modifyhd path/to/drive_file.vdi --resize NewSizeInMegaBytes
(Ubuntu host) or
C:\> "C:\Path to VirtualBox\VBoxManage.exe" modifyhd "C:\path\to\drive.vdi --resize NewSizeInMegaBytes
(Windows host).
Expand the partition on the larger disk, for exampel by booting your virtual machine from an Ubuntu LiveCD, and using gparted
. To boot from a LiveCD, just set the virtual machine to use the ISO file as a CD drive, and boot from that drive.
If you created a fixed-size disk and/or you're running an older version of VirtualBox, you need to clone the drive first, before you can do the above:
- Create a new virtual drive, which is the size you want after the resize.
Clone the old one to the new one, using a command like the following:
$ VBoxManage clonehd path/to/old.vdi path/to/new.vdi --existing
(Ubuntu host - the change for a Windows host is analogous to above).
Replace the old drive with the new one in the settings for your virtual drive.
Expand the partition on the new drive, as in step 2. above.
Delete the old drive file and the backups when you know everything is working, to free up disk space.
Note: I haven't tested any of this myself - I'm just re-iterating what is already written in the guide I linked to, for completeness in case of link rot. The guide there is more complete, with thorough descriptions and screenshots for all the steps.