I create a virtual machine every now and then and even less have to resize the hard drive. Below is my mental notes jotted down so I can easily remember how to do what I normally do with virtual machines using Oracle VirtualBox 4.2.14 for windows host.
The notes are raw and by no means a complete list and/or an exact step by step tutorial. I figured, if I find it helpful so will someone else. Enjoy!
First, the manual.
Creating a virtual machine
The below sample creates a new W2008R2 Server and is assumed to be on a Windows host machine.
- Select New button in VirtualBox Manager, give it a name, type is MS Windows & Version is Windows 2008 (64bit).
- Give it the amount of RAM you want.
- For Hard drive there are three options, do not add, create, use an existing.
- Create a new HD is likely what you will want unless you downloaded an existing virtual hard drive file. If the latter is true select use an existing.
- For creating a hard drive, select VHD (Microsoft's version) OR VDI (VirtualBoxes version) or VMDK (VMWare version).
- There are tools to convert each to the other. Choose what you believe is the best for your situation.
- Select Dynamically allocated for hard drive type.
- Choose the size you feel you need to be able to adequately run the box on. Be sure to consider the OS size, updates and all of the extras you need on the machine. The default is 25GB which mean the hard drive can grow to 25GB at most. For a windows OS this is a little on the small size.
- The default location for the virtual machine file is under your user profile (c:\users\<profile>\) VirtualBox VMs\<virtual machine name>.
- You can change this on the size wizard page by selecting the folder icon and specifying where you want it.
- This does not effect snapshot location. See snapshots below for more.
The Windows 2008R2 OS before updates is around 7GB but after all the updates through 7/1/2013 puts it at 24GB. A hard drive around 40-50GB may be more appropriate.
There are several ways to setup the network for the virtual machine. The choice effects how the machine is or is not seen on a network.
The most common for a developer station is either host-only or bridged.
- Host-only means the VM is only visible to the host machine. This is a great option if you don't need any external resources for the VM.
- Bridged - The VM will use the NIC card on the host to connect with network resources. The bridge creates it's own MAC serving as a virtual NIC card.
For more in depth review see the manual.
Under the advanced tab you can enable sharing of the clipboard between host and guest as well as drag and drop.
You can only make changes to settings for the VM when it is shutdown. If it isn't, you can view the settings but everything will be greyed out.
For more on settings see the manual.
After the image is created, you'll need to install the OS. You can do this with an ISO and/or an actual install disk.
To select this, select your VM in the Virtual Manager, select settings, select the storage item & in the controller IDE select either the CD/DVD drive on your host machine or choose the ISO to run against.
Now start the virtual machine and follow your normal procedures for install/post install configuration needs/instructions to get your VM ready to go.
Install Guest Additions
After the OS is installed and you are in the VM, from the Devices menu select Install Guest Additions and follow the wizard to install.
"Host Key" - default is the right ctrl key.
Sending ctrl+alt+del - host key + del
You can cycle through screen sizes:
host key + f - full screen
host key + c - scale
host key + a - allow you to resize...
More on special characters.
VirtualBox can save the VM at it’s current state with snapshots. This is a great way to save off the VM at points in time that you may want to go back to. One great example would be to snapshot the VM before you do a major update on it. If something goes wrong you can go back to a snapshot.
Snapshots are created by right clicking on the VM and selecting snapshot.
Snapshots are stored separately from the main virtual hard drive. The default is under your user profile in VirtualBox VMs\<VMName>\snapshots. <VMName> is the name you gave the VM.
You can change where snapshots are stored under the General settings, advanced tab.
Cloning copies a VM. You can also clone from a snapshot. Right click on the VM and/or in the snapshot view and select clone.
Resizing the virtual machine hard drive
Assumed using Oracle VirtualBox 4.2.14.
You can resize a virtual hard drive if it is dynamically allocated. Fixed drives can not be resized*.
If you used snapshots you also need to clone your drive and merge all of the snapshots thus loosing the snapshots first. :-(
From the command line run VBoxmanage
vboxmanage modifyhd "path\virtualharddrivename" --resize <megabytes>
<megabytes> is the size you want to resize to, say 40GB would be 40000.
Assuming windows server OS, fire up the VM, go into disk management, right click on the partitioned space (likely your C drive) and select Extend Volume. The newly created unpartitioned space (the difference between your original hard drive size and the newly created size) will be added to your disk.
* You could convert the fixed to dynamic and then resize by cloning the drive to a dynamic first.
By no means am I an expert on VirtualBox. There may be slicker ways to resize or use VirtualBox.