VirtualBox Gotchas

This is ongoing post listing different challenges and how those can be overcome when utilizing VirtualBox for your development needs

1. VirtualBox host only supports 32bit guest OS

This was a problem on Windows 8 Intel processor machine that didn’t have vt-x enabled. The vt-x is feature of Intel processor that allows the virtualization of some kind. Once enabled, the VirtualBox host can load also 64bit Guest OS. To enable, boot Vindows 8 in BIOS and enable the vt-x feature

2. Freezes with “Building initial module for 3.x”

Make sure the guest OS you are installing is for the right processor.

3. Cannot Change Display Resolution

Install the VirtualBox additions at the Guest

sudo apt-get install virtualbox-guest-dkms

Afterwards, reboot and the display resolution works as you like

4. Cannot Copy & Paste from VirtualBox Host to Client and from Client to Host

Copy/paste is not enabled by default. You have to enable in host ‘Settings’ under ‘General’->’Advanced’ and check ‘Shared Clipboard’ and ‘Drag & Drop’. Note, that changes can only made when client OS is turned off.

5. Sharing folders Between VirtualBox Host and Guest

There are two ways to share directories between Host and Guest – via VirtualBox Shares or via independent Samba Server. As we learn later, the VirtualBox Shares solutions is very slow for Apache to service web applicaitons such as Drupal. So we strongly recommend Samba solution for sharing directories, however. Here are setup for both solutions:

  • Share Via Samba

    Please, see post “Sharing Vis Samba Instead VirtualBox Shares” for sharing directories via Samba

  • Share Via VirtualBox Shares

    There are two steps:

    1. In the host settings under ‘shared folder’ directory, add the shared directory and give a name ‘some-host-share-name’. Make sure you check “Permanent”, so its available on each reboot
    2. Next, physically mount the shared directory

      sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) some-host-share-name ~/guest-dir
      

    Make sure the ‘~/guest-dir’ exists on the guest OS. Otherwise, you will get error “/sbin/mount.vboxsf: mounting failed with the error: No such file or directory” or no any error and it will just not mount

To mount it automatically on reboot, add the entry in the /etc/rc.local as following:

  • For Samba solution:
    mount.cifs //HOST-IP/SHARE-NAME /path/to/shared/dir -o uid=1000,iocharset=utf8,rw,username=HOST-USER,password=HOST-USER-PASSWORD,nounix
    
  • For VirtualBox shares solution:
    mount.vboxsf -w some-host-share-name /home/<username>/guest-dir
    

This will mount the the shared drive on each reboot automatically.

5A. Share Between Guest OS of Windows XP

First ensure, the Guest addition is installed for the Guest Windows XP OS by grabbing appropriate ISO of your VirtualBox solution at the http://download.virtualbox.org/virtualbox/ dir.
Next, add the ISO to the Optical CD/DVD drive of the Guest OS.
At last, run the executable/installer in the ISO rood directory. This will install Guest additions necessary, so that at the next boot it creates the shared dir in the Guest Windows OS automatically in the “Network Drives”

6. Easily access your NAT configured virtual machine

You probably need host access servers on the guest OS, while your guest OS, probably, need access internet at the same time. Here is NAT + Host ONLY solution to address both needs configurable as following.

  1. Create new Network Go to VirtualBox VM->Preferences->Network->Host Only Networks and add new one with the following settings:
    IP:10.88.12.0
    Mask:255.0.0.0
    

    Keep DHCP server disable, so you can configure static IP much more easier than looking up the new IP every time it changes

  2. Add Network Interfaces Add the network interfaces by going to Guest Settings->Network->Adapter
    • Adapter 1: NAT
    • Adapter 2: Host Only Adapter with “name” of network you configured in step 1 above
  3. Configure Two Guest OS Interfaces. In your guest OS, edit /etc/network/interfaces for Deb or Ubuntu as following:
    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback
    
    #the primary network interface
    auto eth0
    iface eth0 inet dhcp
    
    #The secondary network interface
    auto eth1
    iface eth1 inet static
    address 10.88.12.4
    netmask 255.0.0.0
    

    This will configure two network interfaces one for NAT and another for Host Only network

Afterwards, reboot guest OS and you should access guest OS at 10.88.12.4 from host, access host at 10.88.12.0 from guest all which while your guest OS have internet connection via the NAT network

7. Slow Performance for Guest xUbuntu

The following settings improved Guest performance:

  • Check “Storage” -> “Use Host I/O Cache”
  • Check “Display” -> “Enable 3D Acceleration”
  • Install guest addtions, utilities and drivers:
    sudo apt-get install virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
    
  • Add extra CPUs “System”->”Processor”
  • Check “Enable PAE/NX” under “System”->”Processor”
  • Add more RAM to Video Card “Display” -> “Video” -> “Video Ram”
  • Install VB extension pack on the host machine:
    1. Download the extension pack from VirtualBox Download page
    2. Run the following command:
      sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.18-96516.vbox-extpack 
      sudo VBoxManage list extpacks
      
  • look into logs to see if it shows any issues that may affect performance

Note: After analyzing performance for my Drupal site running on VirtualBox(see more details at post looking-at-drupal-performance-with-xprof-and-xhgui), it shows that the top 6 slowest functions are “file_scan_directory”. It made me conclude that reading/writing on disk is the slowest. I upgraded HD to SSD HD, but while there was performance improvement it still was noticeable. This applies to the shared directories between Guest and Host. If not shared then ‘file_scan_directory’ is not any more the bottleneck and Drupal site runs really fast.

UPDATE: The best improvement by far was moving away from sharing directories via VirtualBox Shares solution to the sharing via Samba Server as described in post Sharing Via Samba Instead VirtualBox Shares

8. Increase Size for VB Guest Hard Drive

After about 3 weeks running VB, it run out of space on Hard Drive that was set of fixed size. Here are steps to increase Hard Drive space

  1. [ONLY IF FIXED SIZE] Re-clone HD .VDI to be able use ModifyHD
    Resizing HD involves runing command ‘modifyhd’, however. This only works for HD that were not fixed, so before we are able to use “modifyhd”, we re-clone our HD .vdi file:

    sudo VBoxManage clonehd "/full/path/to/disk1.vdi" ClonedFixedHD.vdi --format VDI --variant Standard
    

    This will prepare our Hard Drive .vdi file for modifyhd command to use in next step

  2. Resize the HD Drive .vdi
    sudo VBoxManage modifyhd "/full/path/to/ClonedDevelLamp.vdi" --resize 20000
    

    This will increase the size of the hard drive to 20GB

  3. Update Partition Size for VB Guest
    Once the size is changed for hard drive, we need to update also the VB Guest partition that mounts the new sized Hard drive. It is accomplish by booting from GParted

    1. Download CD of GParted
    2. Mount to CD drive of the VB Guest
    3. Boot into your VB Guest
    4. Resize partition.Here is good article
  4. Remove Old Hard Drive & Attache New Resized HD
    Go to Setting->Storage and remove the old HD .vdi. Then add your new resized HD. Afterwards, reboot the machine

Check Logs

In the following are directories for logs per OS:

  • On Windows, this is %HOMEDRIVE%%HOMEPATH%\\.VirtualBox\\Machines\\\\Logs; typically some- thing like C:\\Documents and Settings\\Username\\.VirtualBox\\Machines\\\\Logs\\vbox.log
  • On Mac OS X, this is $HOME/Library/VirtualBox/Machines//Logs
  • On Unix-like systems (Linux, Solaris), this is $HOME/.VirtualBox/Machines//Logs

Troubleshooting

1. No extension pack by the name ‘Oracle VM VirtualBox Extension Pack’ was found

Go to VirtualBox Download page and download extension pack. Afterwards, install it as following:

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.18-96516.vbox-extpack 

To verify:

sudo VBoxManage list extpacks

This should display descriptions of the extension pack or 0 for no extension pack present

2. VBoxManage: error: Cannot register the hard disk ‘/path/to/disk1.vdi’ {8e28be07-2543-4967-a83f-8a6a07d18c64} because a hard disk ‘path/to/disk1.vdi’ with UUID {..} already exists

We got this after cloning and then trying to resize hard drive. The solution was to reset UUID:

sudo VBoxManage internalcommands sethduuid "/full/path/to/disk1.vdi"

Make sure you provide full path to the HD file .vdi, otherwise, you will get another error at least on Mac OS.

3. Progress state: VBOX_E_NOT_SUPPORTED

This error came up when trying to resize the HD file .vdi, because the HD was configured fixed and command “modifyhd” doesn’t work with fixed HD .vdi. The solution was convert the HD .vdi into one that is not fixed size by re-cloning as following:

sudo VBoxManage clonehd "/full/path/to/disk1.vdi" ClonedNewVDIfile --format VDI --variant Standard

This will create new .vdi size ready to work with “modifyhd”

4. My .VDI is missing

I was looking at $HOME/VirtualBox VM/SOME_VM_BOX_DIR just to find there is no .vdi file, however, the particular Box was loading okey. I was unaware that the HD(i.e. .vdi file) can be outside the Box directory. See “Settings”->”Storage” to locate where is the Hard Drive .vdi file located

VBoxManage: error: Could not find file for the medium ‘/full/path/to/disk1.vdi’ (VERR_FILE_NOT_FOUND)/h6>
This error is because the path specified is not correct or it is not full path that is required for running VBoxManage commands

5. “the parameter is incorrect” Or “the network name cannot be found” OR “is not accessible”

This error happened when I was sharing files of mac host with Window XP as guest OS and I didn’t have the Guest Additions installed. To install, grab appropriate ISO of your VirtualBox solution at the http://download.virtualbox.org/virtualbox/ dir. Next, add the ISO to the Optical CD/DVD drive of the Guest OS. At last, run the executable/installer in the ISO rood directory. This will install Guest additions necessary, so that at the next boot it creates the shared dir in the Guest Windows OS automatically in the “Network Drives” dir

References

https://forums.virtualbox.org/viewtopic.php?f=24&t=50661
http://drwho.virtadpt.net/archive/2014/02/04/problems-cloning-virtualbox-disk-images

Resizing vmdk harddisks for VirtualBox

One thought on “VirtualBox Gotchas

  1. Pingback: Sharing via Samba Instead VirtualBox Shares | Margots Kapacs Blog

Leave a Reply

Your email address will not be published. Required fields are marked *