Difference between revisions of "VirtualBox Extras"

From ArchWiki
Jump to: navigation, search
(GTK host integration: Information hopefully evident via the links given to QT)
(Guest additions: Already exist in VirtualBox.)
(23 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[[Category:Emulators (English)]]
+
[[Category:Emulators]]
 
[[Category:Virtualization]]
 
[[Category:Virtualization]]
[[Category:Remote Desktop Protocol (English)]]
+
[[zh-CN:VirtualBox Extras]]
{{i18n|VirtualBox Extras}}
+
{{Article summary start}}
 +
{{Article summary text|Describes some additional functionality of VirtualBox.}}
 +
{{Article summary heading|Related}}
 +
{{Article summary wiki|VirtualBox}} - Main VirtualBox article.
 +
{{Article summary end}}
  
 
==Basic virtual machine setup==
 
==Basic virtual machine setup==
Line 26: Line 30:
 
                     uninstall [--force] <name> |
 
                     uninstall [--force] <name> |
 
                     cleanup
 
                     cleanup
As an alternative, you could also use {{Package AUR|virtualbox-ext-oracle}} from the [[AUR]].
+
As an alternative, you could also use {{AUR|virtualbox-ext-oracle}} from the [[AUR]].
  
 
==Networking==
 
==Networking==
 
VirtualBox guests may be networked through various methods; among them, there is [[#NAT]] and [[#Bridged]] networking. Using the [[#NAT]] method is the simplest and the default for new virtual machines.
 
VirtualBox guests may be networked through various methods; among them, there is [[#NAT]] and [[#Bridged]] networking. Using the [[#NAT]] method is the simplest and the default for new virtual machines.
  
In order to use host-only and internal network settings you have to load the {{Codeline|vboxnetadp}} kernel module. The [http://www.virtualbox.org/manual/UserManual.html VirtualBox manual] covers the available options for these two network types. They have been omitted here due to them being, for the most part, OS agnostic.
+
In order to use host-only and internal network settings you have to load the {{ic|vboxnetadp}} kernel module. Host-only Networks have to be created first in VBox Manager->File->Preferences->Network, only then will you be able to select the adapters name in a VMs Network settings. The [http://www.virtualbox.org/manual/UserManual.html VirtualBox manual] covers the available options for these two network types. They have been omitted here due to them being, for the most part, OS agnostic.
  
 
===NAT===
 
===NAT===
Line 54: Line 58:
  
 
Start the virtual machine and configure its network as usual; e.g., DHCP or static.
 
Start the virtual machine and configure its network as usual; e.g., DHCP or static.
 
==Guest additions==
 
The Guest Additions make the shared folders feature available, improve video card acceleration support, and enable bi-directional clipboard between the guest and host. Mouse integration is another feature, taking away the need of releasing the mouse after using it in the guest.
 
 
===Windows guests===
 
After installing Windows (XP etc.) on your virtual machine, simply select ''Devices &rarr; Install Guest Additions...''
 
 
This will mount the iso image and windows should then automatically launch the guest additions installer. Follow the instructions to the end.
 
If you have Guest Additions installed for one virtual machine, and you want to install it for another one, there is no need to re-download the .iso. Select ''Devices &rarr; CD/DVD Devices &rarr; Choose virtual CD/DVD drive'' and navigate to ~/.VirtualBox where the image is located. This is the case if you have multiple VMs.
 
  
 
==Sharing keyboard and mouse==
 
==Sharing keyboard and mouse==
Line 69: Line 64:
  
 
To get seamless mouse integration between host and guest, install the [[#Guest Additions]] inside the guest.
 
To get seamless mouse integration between host and guest, install the [[#Guest Additions]] inside the guest.
 
==Linux and X display configuration==
 
When generating the guests' {{Filename|xorg.conf}} with {{Codeline|X -configure}}, the InputDevice section may feature the {{Codeline|mouse}} driver. After installing the Guest Additions, replace {{Codeline|mouse}} with {{Codeline|vboxmouse}} and then restart X or reboot the guest.
 
 
Alternatively, add the following to the guest's {{Filename|xorg.conf}}:
 
<pre>
 
Section "InputDevice"
 
  Identifier  "Mouse0"
 
  Driver      "vboxmouse"
 
  Option      "Protocol" "auto"
 
  Option      "Device" "/dev/input/mice"
 
  Option      "ZAxisMapping" "4 5 6 7"
 
EndSection
 
 
Section        "ServerLayout"
 
  Identifier  "X.org Configured"
 
  Screen    0 "Screen0" 0 0
 
  InputDevice  "Mouse0" "CorePointer"
 
  InputDevice  "Keyboard0" "CoreKeyboard"
 
EndSection
 
</pre>
 
 
===Full host resolution===
 
Set the resolution of your guest in the grub boot script {{Filename|/boot/grub/menu.lst}}, i.e. add the correct vga code to the kernel command line. For a resolution of 1280x1024, this would e.g. look like
 
# kernel /vmlinuz-linux root=/dev/disk/by-uuid/7bdc5dee-8fb0-4260-bc43-60ac6e4e4a54 ro vga=795
 
 
Add the resolution to {{Filename|/etc/X11/xorg.conf}}, e.g.
 
<pre>
 
Section "Screen"
 
...
 
SubSection "Display"
 
Viewport  0 0
 
Depth    24
 
Modes "1280x1024" "1024x768"
 
EndSubSection
 
...
 
EndSection
 
</pre>
 
If you experience problems with your resolution dropping back to second lower resolution in the 'Modes' setting, simply omit the second resolution. Example
 
                Modes "1280x1024"
 
  
 
==Sharing files==
 
==Sharing files==
Line 127: Line 82:
 
  net use x: \\VBOXSVR\sharename
 
  net use x: \\VBOXSVR\sharename
  
While {{Codeline|VBOXSVR}} is a fixed name, replace {{Codeline|x:}} with the drive letter that you want to use for the share, and sharename with the share name specified with VBoxManage.
+
While {{ic|VBOXSVR}} is a fixed name, replace {{ic|x:}} with the drive letter that you want to use for the share, and sharename with the share name specified with VBoxManage.
  
 
In a Windows guest, to improve loading and saving files (e.g. MS Office) by VirtualBox Shared Folders edit ''c:\windows\system32\drivers\etc\hosts'' as below:
 
In a Windows guest, to improve loading and saving files (e.g. MS Office) by VirtualBox Shared Folders edit ''c:\windows\system32\drivers\etc\hosts'' as below:
Line 135: Line 90:
 
  # mount -t vboxsf [-o OPTIONS] sharename mountpoint
 
  # mount -t vboxsf [-o OPTIONS] sharename mountpoint
 
   (Notes: sharename is optional or same as selected in the VirtualBox-Dialog , mountpoint of the shared directory in the hosts filesystem)
 
   (Notes: sharename is optional or same as selected in the VirtualBox-Dialog , mountpoint of the shared directory in the hosts filesystem)
:Automatically mounting a shared folder is possible through the linux-guest {{Filename|/etc/fstab}} file. You may also specify the uid=#,gid=# (where # is replaced by the actual numerical uid and gid) to mount the share with normal user permissions instead of root permissions. (this can be helpful to mount parts of your host {{Filename|~/home}} for use in your Linux-guest. To do this add an entry in the following format to the linux-guest {{Filename|/etc/fstab}}:
+
:Automatically mounting a shared folder is possible through the linux-guest {{ic|/etc/fstab}} file. You may also specify the uid=#,gid=# (where # is replaced by the actual numerical uid and gid) to mount the share with normal user permissions instead of root permissions. (this can be helpful to mount parts of your host {{ic|~/home}} for use in your Linux-guest. To do this add an entry in the following format to the linux-guest {{ic|/etc/fstab}}:
  
 
  sharename mountpoint vboxsf uid=#,gid=# 0 0
 
  sharename mountpoint vboxsf uid=#,gid=# 0 0
  
Replace {{Codeline|sharename}} with the share name specified with VBoxManage, and mountpoint with the path where you want the share to be mounted (e.g. /mnt/share). The usual mount rules apply, that is, create this directory first if it does not exist yet. Note that if you have told VirtualBox to "automatically mount" the shared folder, this step may not be necessary and your folder will be found somewhere under {{Filename|/media}}.
+
Replace {{ic|sharename}} with the share name specified with VBoxManage, and mountpoint with the path where you want the share to be mounted (e.g. /mnt/share). The usual mount rules apply, that is, create this directory first if it does not exist yet. Note that if you have told VirtualBox to "automatically mount" the shared folder, this step may not be necessary and your folder will be found somewhere under {{ic|/media}}.
  
 
Beyond the standard options supplied by the mount command, the following are available:
 
Beyond the standard options supplied by the mount command, the following are available:
Line 150: Line 105:
 
Recent versions of Virtualbox have support for accelerating OpenGL inside guests.  This can be enabled with a simple checkbox in the machine's settings, right below where video ram is set, and installing the Virtualbox guest additions.  However, most Windows games use Direct3D (part of DirectX), not OpenGL, and are thus not helped by this method.  However, it is possible to gain accelerated Direct3D in your Windows guests by borrowing the d3d libraries from Wine, which translate d3d calls into OpenGL, which is then accelerated.   
 
Recent versions of Virtualbox have support for accelerating OpenGL inside guests.  This can be enabled with a simple checkbox in the machine's settings, right below where video ram is set, and installing the Virtualbox guest additions.  However, most Windows games use Direct3D (part of DirectX), not OpenGL, and are thus not helped by this method.  However, it is possible to gain accelerated Direct3D in your Windows guests by borrowing the d3d libraries from Wine, which translate d3d calls into OpenGL, which is then accelerated.   
  
After enabling OpenGL acceleration as described above, go to http://www.nongnu.org/wined3d/ in your Windows guest and grab the "Latest version (Installer):". Reboot the guest into safe mode (press F8 before the Windows screen appears but after the Virtualbox screen disappears), and install wined3d, accepting the defaults during the install. (You may check the box for DirectX 10 support if you like, dont touch anything else.) Reboot back to normal mode and you should have accelerated Direct3D.  
+
After enabling OpenGL acceleration as described above, go to http://www.nongnu.org/wined3d/ in your Windows guest and grab the "Latest version (Installer):". Reboot the guest into safe mode (press F8 before the Windows screen appears but after the Virtualbox screen disappears), and install wined3d, accepting the defaults during the install. (You may check the box for DirectX 10 support if you like, don't touch anything else.) Reboot back to normal mode and you should have accelerated Direct3D.  
  
 
{{Note | This hack may or may not work for some games depending on what hardware checks they make and what parts of D3D they use.}}
 
{{Note | This hack may or may not work for some games depending on what hardware checks they make and what parts of D3D they use.}}
Line 156: Line 111:
  
 
==Virtual hard disks==
 
==Virtual hard disks==
 +
=== Cloning a Disk Image and Reassigning a UUID ===
 +
Assigns a new UUID to the given image file. This way, multiple copies of a container can be registered.
 +
 +
$ VBoxManage internalcommands sethduuid /path/to/disk.vdi
 +
 
=== Compacting Linux disks ===
 
=== Compacting Linux disks ===
 
Boot the Linux guest VM and remove all bloat (unwanted packages, temp files, etc.).  When satisfied, wipe the freespace using dd or preferably dcfldd:
 
Boot the Linux guest VM and remove all bloat (unwanted packages, temp files, etc.).  When satisfied, wipe the freespace using dd or preferably dcfldd:
Line 202: Line 162:
  
 
===Disk image format conversion===
 
===Disk image format conversion===
The {{Codeline|qemu-img}} program can be used to convert images from one format to another or to add compression or encryption to an image. {{Codeline|qemu-img}} is provided by the {{Pkg|qemu}} package.
+
The {{ic|qemu-img}} program can be used to convert images from one format to another or to add compression or encryption to an image. {{ic|qemu-img}} is provided by the {{Pkg|qemu}} package.
  
 
====QEMU to VDI====
 
====QEMU to VDI====
To convert a [[QEMU]] image for use with VirtualBox, first convert it to ''raw'' format, then use VirtualBox's conversion utility to convert and compact it in its native format.
+
From [[QEMU]] 0.12.x on, {{ic|qemu-img}} is able to convert directly to VDI and back, if necessary:
  $ qemu-img convert -O raw test.qcow2 test.raw
+
$ qemu-img convert -O vdi test.qcow2 test.vdi
  $ VBoxManage modifyvdi /full/path/to/test.vdi compact
+
or
+
  $ qemu-img convert -O raw test.qcow2 test.raw
+
  $ VBoxManage convertfromraw /full/path/to/test.raw /full/path/to/test.vdi
+
  $ VBoxManage modifyvdi      /full/path/to/test.vdi compact
+
 
+
From QEMU 0.12.x on, {{Codeline|qemu-img}} is able to convert directly to VDI and back, if necessary:
+
  $ qemu-img convert -O vdi test.qcow2 test.vdi
+
  
 
====VMware to VDI====
 
====VMware to VDI====
Line 224: Line 176:
 
To get working Windows XP and Nokia phones with PC Suite mode, VirtualBox needs two simple steps:
 
To get working Windows XP and Nokia phones with PC Suite mode, VirtualBox needs two simple steps:
  
'''1.''' Add a rule to [[udev]] with {{Filename|/etc/udev/rules.d/40-permissions.rules}}:
+
'''1.''' Add a rule to [[udev]] with {{ic|/etc/udev/rules.d/40-permissions.rules}}:
 
  LABEL="usb_serial_start"
 
  LABEL="usb_serial_start"
 
  ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", \
 
  ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", \
Line 230: Line 182:
 
  LABEL="usb_serial_end"
 
  LABEL="usb_serial_end"
  
'''2.''' Create the group {{Codeline|usbfs}} and add its user to it
+
'''2.''' Create the group {{ic|usbfs}} and add its user to it
 
  # groupadd usbfs
 
  # groupadd usbfs
 
  # usermod -a -G usbfs $USER
 
  # usermod -a -G usbfs $USER
Line 253: Line 205:
  
 
==Starting VMs at system boot on headless servers==
 
==Starting VMs at system boot on headless servers==
Add this line to {{Filename|/etc/rc.local}}
+
Add this line to {{ic|/etc/rc.local}}
 
  exec /bin/su -c 'VBoxManage startvm --type headless <''UUID|NAME''>' ''PREFERED_USER'' >/dev/null 2>&1
 
  exec /bin/su -c 'VBoxManage startvm --type headless <''UUID|NAME''>' ''PREFERED_USER'' >/dev/null 2>&1
 
Where <UUID|NAME> is the guest identifier, and PREFERRED_USER is the user profile that contains the VM definitions and .vdi files.
 
Where <UUID|NAME> is the guest identifier, and PREFERRED_USER is the user profile that contains the VM definitions and .vdi files.
Line 259: Line 211:
 
Since exec replaces the currently running process, you will not be able to start a second VM, or execute any other commands, after the exec. Try the following if this is a problem:
 
Since exec replaces the currently running process, you will not be able to start a second VM, or execute any other commands, after the exec. Try the following if this is a problem:
 
  su -c 'VBoxHeadless -s <''UUID|NAME''> &' -s /bin/sh ''PREFERED_USER'' >/dev/null 2>&1
 
  su -c 'VBoxHeadless -s <''UUID|NAME''> &' -s /bin/sh ''PREFERED_USER'' >/dev/null 2>&1
Using fully qualified path to su and VBoxHeadless is recommend.  Add additional lines like above to start additional VMs.  Commands following these in {{Filename|/etc/rc.local}} will be executed.  Based on some rooting around in the VirtualBox documentation, I get the impression this will be a little more robust than 'VBoxManage ... --type headless' in future VBox releases.
+
Using fully qualified path to su and VBoxHeadless is recommend.  Add additional lines like above to start additional VMs.  Commands following these in {{ic|/etc/rc.local}} will be executed.  Based on some rooting around in the VirtualBox documentation, I get the impression this will be a little more robust than 'VBoxManage ... --type headless' in future VBox releases.
  
 
To determine the available VMs for a user:
 
To determine the available VMs for a user:
Line 266: Line 218:
 
To save the state of a running VM:
 
To save the state of a running VM:
 
  su -c 'VBoxManage controlvm <UUID|NAME> savestate' PREFERED_USER
 
  su -c 'VBoxManage controlvm <UUID|NAME> savestate' PREFERED_USER
{{Filename|/etc/rc.local.shutdown}} would be a good spot for this.
+
{{ic|/etc/rc.local.shutdown}} would be a good spot for this.
 
+
== Virtual machine control daemon ==
+
Below is a [[daemon]] for controlling virtual machines. Guests will be initialized on start, and state-saved on stop, or you will just get a "./vbox_service: line 31: out[${m[1]}]: bad array subscript" message when you run it.
+
 
+
The configuration file:
+
{{File|name=/etc/conf.d/vbox_service|content=<nowiki>
+
# Guests to manage:
+
#VB_GUESTS=('OpenBSD' 'Slackware' 'Windows XP')
+
#
+
# Disable a guest by prepending a bang:
+
#VB_GUESTS=('OpenBSD' 'Slackware' !'Windows XP')
+
#
+
# Default value matches none:
+
VB_GUESTS=()
+
 
+
# User to run Virtual Box as:
+
VB_USER='vbox'
+
</nowiki>}}
+
 
+
The script:
+
{{File|name=/etc/rc.d/vbox_service|content=<nowiki>
+
#!/bin/bash
+
 
+
. /etc/rc.conf
+
. /etc/rc.d/functions
+
 
+
unset VB_GUESTS
+
unset VB_USER
+
[[ -r /etc/conf.d/vbox_service ]] && . /etc/conf.d/vbox_service
+
[[ ${VB_GUESTS[@]} ]] || VB_GUESTS=()
+
[[ ${VB_USER[@]} ]]  || VB_USER='vbox'
+
 
+
 
+
match() {
+
[[ $REPLY =~ $1 ]] && m=("${BASH_REMATCH[@]}")
+
}
+
 
+
 
+
vm_raw() {
+
local argv=''
+
printf -v argv ' %q ' "$@"
+
su -c "/usr/bin/VBoxManage $argv" -s /bin/sh "$VB_USER"
+
}
+
 
+
vm_ls() {
+
local -A out=''
+
local -i ret=1
+
 
+
local m=()
+
while read -r; do
+
  match '^"(.+)" \{(.+)\}$'
+
  out[${m[1]}]=${m[2]}
+
done < <(vm_raw list vms)
+
 
+
local i=''
+
for i in "${VB_GUESTS[@]##!*}"; do
+
  if [[ ${out[$i]} ]]; then
+
    printf ' %q ' "${out[$i]}"
+
    ret=0
+
  fi
+
done
+
 
+
return $ret
+
}
+
 
+
vm_envinit() {
+
local m=()
+
while read -r; do
+
  match '^(.+)="?([^"]+)'
+
  env[$1:${m[1]}]=${m[2]}
+
done < <(vm_raw showvminfo --machinereadable "$1")
+
}
+
 
+
 
+
start() {
+
if [[ ${env[$1:VMState]} != 'running' ]]; then
+
  vm_raw startvm --type headless "$1"
+
fi
+
}
+
 
+
stop() {
+
if [[ ${env[$1:VMState]} == 'running' ]]; then
+
  vm_raw controlvm "$1" savestate
+
fi
+
}
+
 
+
restart() {
+
stop "$1"
+
sleep 3
+
start "$1"
+
}
+
 
+
usage() {
+
printf '%s\n' "usage: $0 <start|stop|restart> [name|uuid]..." >&2
+
}
+
 
+
 
+
if [[ ! $1 =~ ^(start|stop|restart)$ ]]; then
+
  usage
+
  exit 2
+
fi
+
cmd=$1
+
shift
+
(($#)) || eval set -- "$(vm_ls)"
+
 
+
stat_busy "${cmd^}ing VMs:"
+
trap 'stat_die' ERR
+
set -Ee
+
 
+
declare -A env=''
+
 
+
for i; do
+
  [[ $i ]]
+
  vm_envinit  "$i"
+
  stat_append "${env[$i:name]}, "
+
  $cmd        "${env[$i:UUID]}" &>/dev/null
+
done
+
 
+
stat_done
+
</nowiki>}}
+
  
 
==Accessing a guest server==
 
==Accessing a guest server==
Line 401: Line 233:
  
 
==Daemon Tools==
 
==Daemon Tools==
While VirtualBox can mount ISO images without a problem, there are some image formats which cannot reliably be converted to ISO. For instance, ccd2iso ignores .ccd and .sub files, which can give disk images with broken files. cdemu, fuseiso, and MagicISO will do the same. In this case there is no choice but to use Daemon Tools inside VirtualBox.
+
While VirtualBox can mount ISO images without a problem, there are some image formats which cannot reliably be converted to ISO. For instance, ccd2iso ignores .ccd and .sub files, which can give disk images with broken files, fuseiso and MagicISO will do the same.  
 +
 
 +
In this case you will either have to use [[CDEmu]] for Linux or Daemon Tools inside VirtualBox.
  
 
==VirtualBox on a USB key==
 
==VirtualBox on a USB key==
 
When using VirtualBox on a USB key, for example to start an installed machine with an ISO image, you will manually have to create VDMKs from the existing drives. However, once the new VMDKs are saved and you move on to another machine, you may experience problems launching an appropriate machine again. To get rid of this issue, you can use the following script to launch VirtualBox. This script will clean up and unregister old VMDK files and it will create new, proper VMDKs for you:
 
When using VirtualBox on a USB key, for example to start an installed machine with an ISO image, you will manually have to create VDMKs from the existing drives. However, once the new VMDKs are saved and you move on to another machine, you may experience problems launching an appropriate machine again. To get rid of this issue, you can use the following script to launch VirtualBox. This script will clean up and unregister old VMDK files and it will create new, proper VMDKs for you:
<pre>
+
{{bc|<nowiki>
 
#!/bin/bash
 
#!/bin/bash
  
Line 446: Line 280:
 
# Start VirtualBox
 
# Start VirtualBox
 
VirtualBox
 
VirtualBox
</pre>
+
</nowiki>}}
 
Note that your user has to be added to the "disk" group to create VMDKs out of existing drives.
 
Note that your user has to be added to the "disk" group to create VMDKs out of existing drives.
  
 
==phpVirtualBox==
 
==phpVirtualBox==
An open source, AJAX implementation of the VirtualBox user interface written in [[PHP]]. As a modern web interface, it allows you to access and control remote VirtualBox instances. Much of its verbage and some of its code is based on the (inactive) vboxweb project. It allows the administrator to remotely and graphically administer their virtual machines without having to log in to their headless VirtualBox servers.
+
An open source, AJAX implementation of the VirtualBox user interface written in [[PHP]]. As a modern web interface, it allows you to access and control remote VirtualBox instances. See [[PhpVirtualBox]] for more information.
 
+
This requires the PUEL edition for VirtualBox (may be wrong).
+
 
+
See [[PhpVirtualBox]] for more information about the Arch Linux-specific installation process.
+
 
+
An installation guide is available here:
+
http://code.google.com/p/phpvirtualbox/wiki/Installation
+
 
+
Arch Linux users should uncomment these 2 extensions in {{Filename|/etc/php/php.ini}}:
+
extension=json.so
+
extension=soap.so
+
  
==Troubleshooting OpenBSD==
+
==Troubleshooting==
 +
===OpenBSD===
 
Some people with older computers can have trouble running an OpenBSD VM, manifesting as bunch of segmentation faults and total unusability. Starting VirtualBox with the -norawr0 argument may solve the problem. You can do it like this:
 
Some people with older computers can have trouble running an OpenBSD VM, manifesting as bunch of segmentation faults and total unusability. Starting VirtualBox with the -norawr0 argument may solve the problem. You can do it like this:
 
  $ VBoxSDL -norawr0 -vm NameOfYourOpenBSDVM
 
  $ VBoxSDL -norawr0 -vm NameOfYourOpenBSDVM

Revision as of 03:22, 8 March 2013

Summary help replacing me
Describes some additional functionality of VirtualBox.
Related
VirtualBox - Main VirtualBox article.

Basic virtual machine setup

Audio

In the machine settings, go to the audio tab and select the correct driver according to your sound system (ALSA, OSS or PulseAudio).

RAM and video memory

You can change the default values by going to Settings → General.

CD-ROM

You can change the default values by going to Settings → CD/DVD-ROM.

Check mount CD/DVD drive and select one of the following options.

Extension pack

VirtualBox requires an extension pack in order to provide support for RDP, as well as USB 2.0 and PXE booting for Intel network cards, etc., available at this webpage: VirtualBox Downloads. This PUEL licensed extension pack is free for personal use.

To install the Extension pack you download and save it to your hard drive and then open the VirtualBox main program. Click on preferences and on the left side click Extensions. On the right side, click the add package icon and then open the folder that has the extension and click to install it.

Additionally you can install the Extension Pack from the command line using VBoxManage.

VBoxManage extpack install <tarball> |
                   uninstall [--force] <name> |
                   cleanup

As an alternative, you could also use virtualbox-ext-oracleAUR from the AUR.

Networking

VirtualBox guests may be networked through various methods; among them, there is #NAT and #Bridged networking. Using the #NAT method is the simplest and the default for new virtual machines.

In order to use host-only and internal network settings you have to load the vboxnetadp kernel module. Host-only Networks have to be created first in VBox Manager->File->Preferences->Network, only then will you be able to select the adapters name in a VMs Network settings. The VirtualBox manual covers the available options for these two network types. They have been omitted here due to them being, for the most part, OS agnostic.

NAT

From VirtualBox:

  • access the VM's Settings menu;
  • click on Network from the list to the left; finally,
  • in the Attached to drop-down list, select NAT.

VirtualBox's bundled DHCP server enables the guest system to be configured with DHCP. The NAT IP address on the first card is 10.0.2.0, 10.0.3.0 on the second and so on.

Bridged

Bridged networking may be setup through various methods; among them, there is the native way, which requires minimal setup at the expense of having less control. For other methods, see Advanced VirtualBox Networking. Since newer versions, VirtualBox can bridge between a guest and a wireless host interface without the help of third party utilities.

Before continuing, load the required module:

# modprobe vboxnetflt

From VirtualBox:

  • access the VM's Settings menu;
  • click on Network from the list to the left;
  • in the Attached to drop-down list, select Bridged Adapter; finally,
  • in the Name drop-down list, select the name of the host interface that is connected to the network that the guest OS should be part of.

Start the virtual machine and configure its network as usual; e.g., DHCP or static.

Sharing keyboard and mouse

  • To capture the keyboard and mouse, click the mouse inside the virtual machine display.
  • To uncapture, press right Template:Keypress.

To get seamless mouse integration between host and guest, install the #Guest Additions inside the guest.

Sharing files

In the settings of the virtual machine go to shared folders tab and add the folders you want to share.

  • NOTE: You need to install Guest Additions in order to use this feature.
In a Linux host, Devices → Install Guest Additions
Yes (when asked to download the CD image)
Mount (when asked to register and mount)

In a Linux host, create one or more folders for sharing files, then set the shared folders via the virtualbox menu (guest window).

In a Windows guest, starting with VirtualBox 1.5.0, shared folders are browseable and are therefore visible in Windows Explorer. Open Windows Explorer and look for it under My Networking Places → Entire Network → VirtualBox Shared Folders.

Launch the Windows Explorer (run explorer command) to browse the network places -> expand with the (+) sign : entire network → VirtualBox shared folders → \\Vboxsvr → then you can now expand all your configured shared folders here, and set up shortcuts for Linux folders in the guest filesystem. You can alternatively use the "Add network place wizard", and browse to "VBoxsvr".

Alternatively, on the Windows command line, you can also use the following:

net use x: \\VBOXSVR\sharename

While VBOXSVR is a fixed name, replace x: with the drive letter that you want to use for the share, and sharename with the share name specified with VBoxManage.

In a Windows guest, to improve loading and saving files (e.g. MS Office) by VirtualBox Shared Folders edit c:\windows\system32\drivers\etc\hosts as below:

127.0.0.1 localhost vboxsvr

In a Linux guest, use the following command:

# mount -t vboxsf [-o OPTIONS] sharename mountpoint
  (Notes: sharename is optional or same as selected in the VirtualBox-Dialog , mountpoint of the shared directory in the hosts filesystem)
Automatically mounting a shared folder is possible through the linux-guest /etc/fstab file. You may also specify the uid=#,gid=# (where # is replaced by the actual numerical uid and gid) to mount the share with normal user permissions instead of root permissions. (this can be helpful to mount parts of your host ~/home for use in your Linux-guest. To do this add an entry in the following format to the linux-guest /etc/fstab:
sharename mountpoint vboxsf uid=#,gid=# 0 0

Replace sharename with the share name specified with VBoxManage, and mountpoint with the path where you want the share to be mounted (e.g. /mnt/share). The usual mount rules apply, that is, create this directory first if it does not exist yet. Note that if you have told VirtualBox to "automatically mount" the shared folder, this step may not be necessary and your folder will be found somewhere under /media.

Beyond the standard options supplied by the mount command, the following are available:

iocharset=CHARSET

to set the character set used for I/O operations (utf8 by default) and

convertcp=CHARSET

to specify the character set used for the shared folder name (utf8 by default).

D3D acceleration in Windows guests

Recent versions of Virtualbox have support for accelerating OpenGL inside guests. This can be enabled with a simple checkbox in the machine's settings, right below where video ram is set, and installing the Virtualbox guest additions. However, most Windows games use Direct3D (part of DirectX), not OpenGL, and are thus not helped by this method. However, it is possible to gain accelerated Direct3D in your Windows guests by borrowing the d3d libraries from Wine, which translate d3d calls into OpenGL, which is then accelerated.

After enabling OpenGL acceleration as described above, go to http://www.nongnu.org/wined3d/ in your Windows guest and grab the "Latest version (Installer):". Reboot the guest into safe mode (press F8 before the Windows screen appears but after the Virtualbox screen disappears), and install wined3d, accepting the defaults during the install. (You may check the box for DirectX 10 support if you like, don't touch anything else.) Reboot back to normal mode and you should have accelerated Direct3D.

Note: This hack may or may not work for some games depending on what hardware checks they make and what parts of D3D they use.
Note: This has only been tried on Windows XP and Windows 7 RC guests AFAIK, and does not work on the Windows 7 guest. If you have experience with this on a different windows version, please add that data here.

Virtual hard disks

Cloning a Disk Image and Reassigning a UUID

Assigns a new UUID to the given image file. This way, multiple copies of a container can be registered.

$ VBoxManage internalcommands sethduuid /path/to/disk.vdi

Compacting Linux disks

Boot the Linux guest VM and remove all bloat (unwanted packages, temp files, etc.). When satisfied, wipe the freespace using dd or preferably dcfldd:

$ dcfldd if=/dev/zero of=fillfile bs=4M

When the fillfile hits the limit of the virtual hdd, the vast majority of user-space (non-reserved blocks) will be filled. Alternatively, run the command as root to get all of them. Example message: "8192 blocks (8192Mb) written.dcfldd:: No space left on device."

Once this occurs, simply remove the fill file and powerdown the VM:

$ rm -f fillfile && sudo shutdown -hF now
Note: The -F switch will force a disk check upon a reboot which is advised following the compact operation.

Now compact the disk:

$ VBoxManage modifyhd /path/to/your.vdi --compact

Compacting Windows disks

See this article.

Increasing Windows disk size

Warning: This has only been tested with Windows XP and Windows 7 guests.

If you find that you are running out of space due to the small hard drive size you selected when created your VM, you can take the following steps:

Create a new vdi in ~/.VirtualBox/HardDisks by running:

# cd ~/.VirtualBox/HardDisks
# VBoxManage createhd -filename new.vdi --size 10000

where size is in mb, in this example 10000MB ~= 10GB, and new.vdi is name of new hard drive to be created.

Next the old vdi needs to be cloned to the new vdi, this may take some time so wait while it occurs:

# VBoxManage clonehd old.vdi new.vdi --existing

Detach old harddrive and attach new hard drive, replace VMName with whatever you called your VM:

# VBoxManage modifyvm VMName --hda none
# VBoxManage modifyvm VMName --hda new.vdi

Boot the VM, run Partition Wizard 5 to resize the partition on the fly, and reboot.

Remove old vdi from VirtualBox and delete

# VBoxManage closemedium disk old.vdi
# rm old.vdi

Disk image format conversion

The qemu-img program can be used to convert images from one format to another or to add compression or encryption to an image. qemu-img is provided by the qemu package.

QEMU to VDI

From QEMU 0.12.x on, qemu-img is able to convert directly to VDI and back, if necessary:

$ qemu-img convert -O vdi test.qcow2 test.vdi

VMware to VDI

You can

  $ VBoxManage clonehd source.vmdk target.vdi --format VDI

although recent versions of VirtualBox are able to use (and also create) .vmdk images directly.

Windows XP guest and Nokia phones

To get working Windows XP and Nokia phones with PC Suite mode, VirtualBox needs two simple steps:

1. Add a rule to udev with /etc/udev/rules.d/40-permissions.rules:

LABEL="usb_serial_start"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", \
GROUP="usbfs", MODE="0660", GROUP="dialout"
LABEL="usb_serial_end"

2. Create the group usbfs and add its user to it

# groupadd usbfs
# usermod -a -G usbfs $USER

After logging out, connect a Nokia phone with PC Suite mode and start Windows XP to test the new rule.

Starting virtual machines with a key binding

It can be useful to start the virtual machines directly rather than start the Virtual Box console. To do this, simply assign a keybinding in .xbindkeysrc to

"VBoxManage startvm vm-name"
keycode
keyname

If you have a space in the vm name, then enclose the vm-name in single apostrophes. For eg.

"VBoxManage startvm 'Windows 7'"
m:0x0 + c:163
XF86Mail

Detecting web-cams and other USB devices

Make sure you filter any devices that are not a keyboard or a mouse so they do not start up at boot and this insures that Windows will detect the device at start-up.

Sending CTRL+ALT+F1

If your guest O/S is a Linux distro, and you want to open a new tty text shell or exit X via typing Template:Keypress+Template:Keypress+Template:Keypress, you can easily send this command to the guest O/S simply by hitting your 'Host Key' (usually the Template:Keypress in the Right side of your keyboard) + Template:Keypress or Template:Keypress, etc.

Starting VMs at system boot on headless servers

Add this line to /etc/rc.local

exec /bin/su -c 'VBoxManage startvm --type headless <UUID|NAME>' PREFERED_USER >/dev/null 2>&1

Where <UUID|NAME> is the guest identifier, and PREFERRED_USER is the user profile that contains the VM definitions and .vdi files.

Since exec replaces the currently running process, you will not be able to start a second VM, or execute any other commands, after the exec. Try the following if this is a problem:

su -c 'VBoxHeadless -s <UUID|NAME> &' -s /bin/sh PREFERED_USER >/dev/null 2>&1

Using fully qualified path to su and VBoxHeadless is recommend. Add additional lines like above to start additional VMs. Commands following these in /etc/rc.local will be executed. Based on some rooting around in the VirtualBox documentation, I get the impression this will be a little more robust than 'VBoxManage ... --type headless' in future VBox releases.

To determine the available VMs for a user:

su -c 'VBoxManage list vms' PREFERED_USER

To save the state of a running VM:

su -c 'VBoxManage controlvm <UUID|NAME> savestate' PREFERED_USER

/etc/rc.local.shutdown would be a good spot for this.

Accessing a guest server

To access apache on a VM from the Host machine ONLY, simply execute the following lines on the Host:

$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/HostPort" 8888
$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/GuestPort" 80
$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/Protocol" TCP

Where 8888 is the port the host should listen on and 80 is the port the VM will send Apache's signal on. To use a port lower than 1024 on the host machine changes need to be made to the firewall on the host machine. This can also be set up to work with SSH, etc.. by changing "Apache" to whatever service and using different ports.

Note: "pcnet" refers to the network card of the VM. If you use an Intel card in your VM settings change "pcnet" to "e1000"

Daemon Tools

While VirtualBox can mount ISO images without a problem, there are some image formats which cannot reliably be converted to ISO. For instance, ccd2iso ignores .ccd and .sub files, which can give disk images with broken files, fuseiso and MagicISO will do the same.

In this case you will either have to use CDEmu for Linux or Daemon Tools inside VirtualBox.

VirtualBox on a USB key

When using VirtualBox on a USB key, for example to start an installed machine with an ISO image, you will manually have to create VDMKs from the existing drives. However, once the new VMDKs are saved and you move on to another machine, you may experience problems launching an appropriate machine again. To get rid of this issue, you can use the following script to launch VirtualBox. This script will clean up and unregister old VMDK files and it will create new, proper VMDKs for you:

#!/bin/bash

# Erase old VMDK entries
rm ~/.VirtualBox/*.vmdk

# Clean up VBox-Registry
sed -i '/sd/d' ~/.VirtualBox/VirtualBox.xml

# Remove old harddisks from existing machines
find ~/.VirtualBox/Machines -name \*.xml | while read file; do
  line=`grep -e "type\=\"HardDisk\"" -n $file | cut -d ':' -f 1`
  if [ -n "$line" ]; then
    sed -i ${line}d $file
    sed -i ${line}d $file
    sed -i ${line}d $file
  fi
  sed -i "/rg/d" $file
done

# Delete prev-files created by VirtualBox
find  ~/.VirtualBox/Machines -name \*-prev -exec rm '{}' \;

# Recreate VMDKs
ls -l /dev/disk/by-uuid | cut -d ' ' -f 9,11 | while read ln; do
  if [ -n "$ln" ]; then
    uuid=`echo "$ln" | cut -d ' ' -f 1`
    device=`echo "$ln" | cut -d ' ' -f 2 | cut -d '/' -f 3 | cut -b 1-3`

    # determine whether drive is mounted already
    checkstr1=`mount | grep $uuid`
    checkstr2=`mount | grep $device`
    checkstr3=`ls ~/.VirtualBox/*.vmdk | grep $device`
    if [[ -z "$checkstr1" && -z "$checkstr2" && -z "$checkstr3" ]]; then
      VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/$device.vmdk -rawdisk /dev/$device -register
    fi
  fi
done

# Start VirtualBox
VirtualBox

Note that your user has to be added to the "disk" group to create VMDKs out of existing drives.

phpVirtualBox

An open source, AJAX implementation of the VirtualBox user interface written in PHP. As a modern web interface, it allows you to access and control remote VirtualBox instances. See PhpVirtualBox for more information.

Troubleshooting

OpenBSD

Some people with older computers can have trouble running an OpenBSD VM, manifesting as bunch of segmentation faults and total unusability. Starting VirtualBox with the -norawr0 argument may solve the problem. You can do it like this:

$ VBoxSDL -norawr0 -vm NameOfYourOpenBSDVM