Virtualbox and VM management

In 1 of the previous posts, I had indicated that its difficult to resize the VM hard disk that was created during VM creation. My friend pointed me to few links on how to do this. It turned out be pretty straightforward.

Also, I learnt that when we try different applications and different configurations in the VM, its very easy for the VM OS to be screwed up and it is necessary to either take snapshots, backups, clones and restore them to be on the safe side.

In this blog, I will try to cover some of the common tasks that we would need from VM management perspective like VM backup and restore, resizing VM hard disk. I will say this in the context of Virtualbox, lot of these would apply to other VM hosting software like VMware player, etc. Also, I will cover some things that I have learnt in Virtual box along the way..

VM backup and restore:

Following are different approaches:

Taking snapshots:

This approach is preferable if we want to restore the VM to a known state when we took the snapshot. Virtualbox stores only the differences from the snapshot, so from space perspective, this is efficient approach. For example, we can take a snapshot after a significant milestone and later if something goes bad, we can go back to that state. In Virtualbox, Snapshot management can be done from “Snapshots” tab.

Taking backup of VM:

This approach is preferable if we want to export the VM to a different host or to just keep the backup and use them when needed. In Virtualbox, export can be done using File->Export appliance. “ova” format is used to store the image. VM can be imported with File->Import appliance. When VM export is done, the size of the ova image depends on the amount of used disk space and this approach is efficient when compared to copying VDI image from space perspective.

Cloning VM:

This approach is similar to taking backup of VMs, but here, some settings like mac address are not copied so that its useful in situations where we need to make multiple copies for students in a class etc. In Virtual box, use the “reinitialize mac” option to get a unique mac address for each VM. This can be done by rightclicking on the VM and select “Clone” option.

Copying Vbox and VMDK:

We can move the .vbox and associated VMDK file to a new machine and do a Machine->Add to import the .vbox file. .vbox is a xml file and it will use the .VMDK file in that directory which is the hard disk for the VM. Sometimes this approach fails with “could not open hard disk” error. In that scenario, we can create a new VM and point to the VMDK file, this approach is detailed here.

Resizing VM hard disk:

Following is the list of steps that I followed and it worked great.

Step 1(Getting information about current partitioning):

vdi size can be found from settings->storage in Virtualbox.

Partitioning information can be found from “Disk utility” in ubuntu or by using “df -k” or by using gparted tool. gparted tool can be installed in Ubuntu.

In my case, I initially had a 10GB hard disk size with Ubuntu 12.04 installed. Following was my partition detail:

smakam@smakam-VirtualBox:~/Pictures$ df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        9288056 7531184   1285064  86% /
udev             4079368       4   4079364   1% /dev
tmpfs            1635600     888   1634712   1% /run
none                5120       0      5120   0% /run/lock
none             4088996     124   4088872   1% /run/shm
cgroups          4088996       0   4088996   0% /sys/fs/cgroup
/dev/sr0           58236   58236         0 100% /media/VBOXADDITIONS_4.2.16_86992

I had 9GB of user space and 1GB of swap. I had already consumed 86% of my hard disk and I  wanted to increase the user space.

Step 2(Increase VDI size using cloneVDI tool):

With this tool, we can take clone the hard disk(VDI) and increase the VDI size in parallel. The advantage with this approach is even if something goes wrong with the partitioning, we can go back to the original vdi.

Following is the screenshot of Clonevdi tool:


Specify the source vdi location, select increase vdi size and specify new size. The tool chooses the clone location automatically in the same location as original vdi.

In my case, I specified new VDI size of 18GB(from original 10GB)

To get more information on the tool and to download, pls refer here.

Step 3(Repartition using gparted):

Use step 3 in this link to repartition using gparted. The main steps are:

  • Downloading gparted.
  • Creating a new VM with gparted.
  • Select gparted iso and cloned vdi in VM storage.
  • Start gparted VM, use unallocated space specified to resize VDI.

In my case, extended partition was in between user space and unallocated. I had to first delete extended partition, resize user partition and then create extended partition again. The steps are in the same link above. I chose 15GB for user space and 3GB for extended space for my VM.

Step 4(Replace with new VDI):

Goto the original VM in Virtualbox and modify the VDI to use the cloned VDI under storage tab. Start the VM and make sure that the VM boots up fine and new partitioning is in effect.

In my case, following was the partition detail.

smakam@smakam-VirtualBox:~$ df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       15503336 7505352   7210376  52% /
udev             4079368      12   4079356   1% /dev
tmpfs            1635600     880   1634720   1% /run
none                5120       0      5120   0% /run/lock
none             4088996      76   4088920   1% /run/shm
cgroups          4088996       0   4088996   0% /sys/fs/cgroup

Now I have 50% of disk space free!

Step 5(Final cleanup):

Once all verification is done, delete the old VDI.

Other Virtualbox tips:

Guest additions:

Guest additions allow for VM customizations like full screen mode, copying from host OS etc. For my scenario where my host machine is Windows and I have linux VMs(Ubuntu, Fedora), I did the following.

  • Download and install Virtual box extension pack in Windows.
  • After base OS installation and when Ubuntu or Fedora VMs are up, do Devices->Install guest OS additions. This will mount the ISO image.
  • Execute autorun file. In some scenarios, installation will fail because kernel header files are not present. In that scenario, reinstall kernel developer pack using Yum and then rerun the guest addition file.
  • Reboot the VM.
  • With Ubuntu 14.04, I had issues with installing Guest additions where it did not work and I did not get fullscreen mode. Following steps needs to be followed. First run “sudo apt-get update” to update package list. Next, run “sudo apt-get install dkms” to update kernel modules. Next, do Devices->Install guest OS additions. After that, need to do restart from shutdown button.

Networking options:

Following are the important types:

  • NAT – VM is in a private network and Virtual box does the NAT translation to outside world. In this case, VM is not accessible from host OS as well as to other VMs. Adapter address by default is in “10.0.2.x” range. To change the NAT range, use File->Preferences->Network->NAT. To do port forwarding between the host and the VM, use settings->Network->Port forwarding under the NAT adapter. With port forwarding option, we can access the VM from the guest machine.
  • Host only adapter – In this case, multiple private VM-only networks can be created. In each host-only network, the VMs can talk to each other as well as to the host. By default, Virtualbox creates 1 host-only adapter and the adapter has ip address and has a dhcp server running at The settings for default host-only adapter as well as more host-only adapters can be added from File->Preferences->Network->host-only.
  • Bridged adapter – In this case, VM gets the ip address from the same gateway as host and will be in same network as host.

Other Minor tips:

  • To exit scale mode, Right Ctrl (Host Key) + C.
  • To enable copy, paste from host machine, do devices->shared clipboard->bidirectional.
  • To  mount host filesystem into the VM, do devices->shared folder, add the folder that needs to be shared. Do “sudo mount -t vboxsf <folder-name> /media/” from the terminal. “folder-name” is the name specified in the shared folder. In case, shared folder errors are seen, please use the procedure mentioned here to correct it.
  • To access VM file system from host machine, install Samba and then share the folder from VM. From host machine(windows), run \\<VM ip> to access the shared folder.
  • When VM is started and if you get the error that VT-x is disabled, follow the procedure here. In my case, I had to enable acceleration going to bios settings under security->virtualization.
  • When we get duplicate uuid error when vdi files are moved,use “VBoxManage internalcommands sethduuid” to set uuid.

Nested Virtualization:

There will be some scenarios where its needed to run VM within Virtualbox inside a VM that’s hosted on Virtualbox. After some playing around and searching in the Internet, I found that this is possible but there are some limitations. 1 limitation is that we cannot use 64 bit OS within the nested VM and another is we cannot use multiple CPU for the nested VM. More details are here. I tried the following combination and it worked fine.

  • Base Virtualbox – 4.3.20
  • Base VM – Ubuntu 14.04
  • Guest Virtualbox – 4.3.20
  • Guest VM – hashicorp/precise32 Ubuntu12 Vagrant image

Importing VMs from VMware to Virtualbox:

There are scenarios where we need to import VM from VMWare to Virtualbox. I faced few issues and I used following steps to overcome it. When I imported OVA file directly to Virtualbox, I got “no bootable medium found” error. VMWare uses “.vmdk” storage format and Virtualbox uses “.VDI” storage format. When I looked at the Virtualbox storage directory, i saw that the “.vmdk” filesize was incorrect. I directly copied the “.vmdk” file from VMWare and used it and that seemed to work most of the times as Virtualbox understands “.vmdk” format. In some cases, I found that I was not able to save to “.vmdk” file from Virtualbox. The better approach is to convert the “.vmdk” to “.vdi” and use in Virtualbox. To convert “.vmdk” to “.vdi”,

vboxmanage <vmdk file> <vdi file>

Connecting VMs between VMWare player and Virtualbox:

There are scenarios where we spawn VMs in both VMWare player and Virtualbox in the same host and we need the VMs to be able to talk to each other. If the networking mode selected is bridged, both VMs get IP address from the same router and they will be able to talk to each other. Following link shows an approach to connect the VMs between VMWare player and Virtualbox when using host-only adapter. The steps are to modify the bridged adapter(VMnet0) to use the Virtualbox network’s dhcp server and then have the VM in VMWare player use the bridged VMnet0 adapter.


To replicate VMs, 1 approach is to replicate, clone VMs using OVA files. With Vagrant software, VM configuration can be stored in a configuration file and VMs can be recreated with configuration file rather than distributing OVA files. I have covered more details about Vagrant in another blog.

I recently wrote a blog on networking options with VMWare player that could be useful for folks using it.



4 thoughts on “Virtualbox and VM management

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s