Resizing VirtualBox VMs is easy, when you know the right commands and third-party tools to use. Here's everything you'll need.
If you happen to employ VirtualBox as your virtual machine technology, chances are you've come across an instance or two where you've needed to resize the drive you've created for your virtual machine. If that's the case, you've probably checked into the GUI for a setting option that might allow you to take care of that the easy way.
Unfortunately, that particular GUI control doesn't exist. Sure you can attach a new drive to the VM, but growing the size of the main drive is beyond the scope of the GUI. Instead, you are relegated to the command line. Fortunately, the developers of VirtualBox have made this process quite simple. I will warn you, depending upon your guest operating system, you will have to follow through with extra steps (more on that in a bit). But first, let's find out how to grow that original drive.
The VBoxManage command
I'm going to be resizing a VM named NGINX.vdi from its original 16GB to a 30GB disk. Surprisingly enough, you can manage this task if the virtual machine is either shutdown or in a paused state (however, not when it is running). To do this, the following command will be run (from within the directory housing the .vdi file):
VBoxManage modifyhd NGINX.vdi --resize 30000
Surprisingly enough, that command will complete very quickly. You can then go into the VirtualBox GUI, select the VM in question, click Settings | Storage, and see the size is now at (or very near) 30GB (Figure A).
The virtual machine is now capable of a full 30GB. However, if you're using a Linux host, you have to make use of a third-party tool to resize your virtual machine drive to have the full size available.
The tool you need is GParted. Download the .iso file. Once that is downloaded, shut down your VM, go into its settings and then click Storage. Click Controller: IDE in the Storage Tree, click the + button for Add new storage attachment, and then click Add Optical Drive (Figure B).
Click Choose Disk, navigate to where you downloaded the GParted ISO, and select it. Click OK and then start the VM. This should now boot into GParted, where you can then resize the Linux partition to take advantage of the newly created space.
You must first right-click the active partition and select Deactivate. Once you've done that, you can then right click the partition and select Resize/Move and then resize the partition to use the unallocated space. Apply the changes, shut down the machine, remove the GParted ISO from the Storage Tree, and you're good to go.
This process will come in very handy, especially when you've miscalculated the space necessary for a virtual machine. With a few quick steps, you'll have your VMs stretching their legs with enough room to grow.
- How to export VirtualBox virtual machines as appliances (TechRepublic)
- How to import and export VirtualBox appliances from the command line (TechRepublic)
- How to automate VirtualBox snapshots with the VBoxManage command (TechRepublic)
- System Administration and Infrastructure Management Bundle (TechRepublic Academy)
- Windows on Linux moves forward with new Wine 2.0 release (ZDNet)