Difference between revisions of "VirtualBox"

From ArchWiki
Jump to: navigation, search
(Rebuild the vboxdrv Module: correct last edit; virtualbox_bin no longer provides vbox_build_module)
m (Reverted edits by Haleyg (talk) to last revision by Alad)
 
(968 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[Category:Emulators (English)]]
+
[[Category:Hypervisors]]
[[Category:HOWTOs (English)]]
+
[[cs:VirtualBox]]
{{i18n|VirtualBox}}
+
[[de:VirtualBox]]
 +
[[el:VirtualBox]]
 +
[[es:VirtualBox]]
 +
[[fr:VirtualBox]]
 +
[[hu:VirtualBox]]
 +
[[it:VirtualBox]]
 +
[[ja:VirtualBox]]
 +
[[pt:VirtualBox]]
 +
[[ru:VirtualBox]]
 +
[[zh-hans:VirtualBox]]
 +
{{Related articles start}}
 +
{{Related|VirtualBox/Tips and tricks}}
 +
{{Related|:Category:Hypervisors}}
 +
{{Related|PhpVirtualBox}}
 +
{{Related|RemoteBox}}
 +
{{Related|Moving an existing install into (or out of) a virtual machine}}
 +
{{Related articles end}}
  
[http://www.virtualbox.org VirtualBox] is a virtual pc emulator like vmware. It has many of the features vmware has, as well as some of its own. It is in constant development and new features are implemented all the time. eg. version 2.2 introduced OpenGL 3D acceleration support for Linux and Solaris guests. It has a nice GUI interface (Qt and/or SDL) or command line tools for managing virtual machines. Headless operation is also supported. Running iTunes under VirtualBox is the only way (currently) to sync iPod Touch/iPhone firmware 3.0+.
+
[https://www.virtualbox.org VirtualBox] is a [[Wikipedia:Hypervisor|hypervisor]] used to run operating systems in a special environment, called a virtual machine, on top of the existing operating system. VirtualBox is in constant development and new features are implemented continuously. It comes with a [[Qt]] GUI interface, as well as headless and [[Wikipedia:Simple DirectMedia Layer|SDL]] command-line tools for managing and running virtual machines.
  
==Editions==
+
In order to integrate functions of the host system to the guests, including shared folders and clipboard, video acceleration and a seamless window integration mode, ''guest additions'' are provided for some guest operating systems.
VirtualBox is available in two editions: VirtualBox (OSE) and VirtualBox (Personal Use and Evaluation License (PUEL))
 
  
===VirtualBox (OSE)===
+
== Installation steps for Arch Linux hosts ==
VirtualBox (OSE) is the open source version of VirtualBox, which can be found in the community repository. It lacks some features such as USB device support and the built-in RDP server. 
 
  
===VirtualBox (PUEL)===
+
In order to launch VirtualBox virtual machines on your Arch Linux box, follow these installation steps.
VirtualBox PUEL is a binary-only version (free for personal use).  There are several available from the AUR, but the most popular PKGBUILD was written by thotypous and is currently maintained by cryptocrack.  You can download it from the [http://aur.archlinux.org/packages.php?ID=9753 AUR at this link] or directly from the
 
[http://www.virtualbox.org/wiki/Downloads VirtualBox] website. The PUEL edition offers the following advantages:
 
  
*'''Remote Display Protocol (RDP) Server''' - a complete RDP server on top of the virtual hardware, allowing users to connect to a virtual machine remotely using any RDP compatible client
+
=== Install the core packages ===
  
*'''USB support''' - a virtual USB controller which allows USB 1.1 and USB 2.0 devices to be passed through to virtual machines
+
[[Install]] the {{Pkg|virtualbox}} package. You will need to choose a package to provide host modules:
 +
* for {{Pkg|linux}} kernel choose {{Pkg|virtualbox-host-modules-arch}}
 +
* for other [[kernels]] choose {{Pkg|virtualbox-host-dkms}}
 +
** It is also necessary to install the appropriate headers package(s) for your installed kernel(s): {{Pkg|linux-headers}} or {{Pkg|linux-lts-headers}}. [https://lists.archlinux.org/pipermail/arch-dev-public/2016-March/027808.html] When either VirtualBox or the kernel is updated, the kernel modules will be automatically recompiled thanks to the [[DKMS]] Pacman hook.
  
*'''USB over RDP''' - a combination of the RDP server and USB support, allowing users to make USB devices available to virtual machines running remotely
+
=== Sign modules ===
  
*'''iSCSI initiator''' - a builtin iSCSI initiator making it possible to use iSCSI targets as virtual disks without the guest requiring support for iSCSI
+
When using a custom kernel with {{ic|CONFIG_MODULE_SIG_FORCE}} option enabled, you must sign your modules with  a key generated during kernel compilation.
  
==Installation==
+
Navigate to your kernel tree folder and execute the following command:
 +
# for module in `ls /lib/modules/$(uname -r)/kernel/misc/{vboxdrv.ko,vboxnetadp.ko,vboxnetflt.ko,vboxpci.ko}` ; do ./scripts/sign-file sha1 certs/signing_key.pem certs/signing_key.x509 $module ; done
  
===Install VirtualBox (OSE)===
+
{{Note|Hashing algorithm does not have to match the one configured, but it must be built into the kernel.}}
VirtualBox (OSE) is available from the community repository:
 
# pacman -S virtualbox-ose
 
  
{{Note | 1=This package is not in x86_64 Repositories (see [http://bbs.archlinux.org/viewtopic.php?id=80991&p=1 this thread] why).  See the link to the PKGBUILD by thotypous in the AUR above if you are running Arch x86_64 and want to use VirtualBox.}}
+
=== Load the VirtualBox kernel modules ===
  
{{Note | 1=This package can be installed for x86_64 systems by following the instructions below, however the previous note will remain for those of you who wish to install VirtualBox (OSE) from the AUR.}}
+
{{Pkg|virtualbox-host-modules-arch}} and {{Pkg|virtualbox-host-dkms}} use {{ic|systemd-modules-load.service}} to load all four VirtualBox modules automatically at boot time. For the modules to be loaded after installation, either reboot or load the modules once manually.
  
Once installed, a desktop entry can be located in ''Applications → System Tools → VirtualBox OSE''
+
{{Note|If you do not want the VirtualBox modules to be automatically loaded at boot time, you have to [[mask]] the default {{ic|/usr/lib/modules-load.d/virtualbox-host-modules-arch.conf}} (or {{ic|/usr/lib/modules-load.d/virtualbox-host-dkms.conf}}) by creating an empty file (or symlink to {{ic|/dev/null}}) with the same name in {{ic|/etc/modules-load.d/}}.}}
  
Now, add the desired username to the '''vboxusers''' group:
+
Among the [[kernel modules]] VirtualBox uses, there is a mandatory module named {{ic|vboxdrv}}, which must be loaded before any virtual machines can run.
# gpasswd -a USERNAME vboxusers
 
  
{{Note | You must logout/login in order for this change to take effect.}}
+
To load the module manually, run:
  
To build '''vboxdrv''' module, run as root:
+
# modprobe vboxdrv
  # /etc/rc.d/vboxdrv setup
+
 
 +
The following modules are optional but are recommended if you do not want to be bothered in some advanced configurations (precised here after): {{ic|vboxnetadp}}, {{ic|vboxnetflt}} and {{ic|vboxpci}}.
 +
 
 +
* {{ic|vboxnetadp}} and {{ic|vboxnetflt}} are both needed when you intend to use the [https://www.virtualbox.org/manual/ch06.html#network_bridged bridged] or [https://www.virtualbox.org/manual/ch06.html#network_hostonly host-only networking] feature. More precisely, {{ic|vboxnetadp}} is needed to create the host interface in the VirtualBox global preferences, and {{ic|vboxnetflt}} is needed to launch a virtual machine using that network interface.
 +
 
 +
* {{ic|vboxpci}} is needed when your virtual machine needs to pass through a PCI device on your host.
 +
 
 +
{{Note|If the VirtualBox kernel modules were loaded in the kernel while you updated the modules, you need to reload them manually to use the new updated version. To do it, run {{ic|vboxreload}} as root.}}
 +
 
 +
=== Accessing host USB devices in guest ===
 +
 
 +
To use the USB ports of your host machine in your virtual machines, add users that will be authorized to use this feature to the {{ic|vboxusers}} [[group]].
 +
 
 +
=== Guest additions disc ===
 +
 
 +
It is also recommended to install the {{Pkg|virtualbox-guest-iso}} package on the host running VirtualBox. This package will act as a disc image that can be used to install the guest additions onto guest systems other than Arch Linux. The ''.iso'' file will be located at {{ic|/usr/lib/virtualbox/additions/VBoxGuestAdditions.iso}}, and may have to be mounted manually inside the virtual machine. Once mounted, you can run the guest additions installer inside the guest.
 +
 
 +
=== Extension pack ===
 +
 
 +
The Oracle Extension Pack provides [https://www.virtualbox.org/manual/ch01.html#intro-installing additional features] and is released under a non-free license '''only available for personal use'''. To install it, the {{aur|virtualbox-ext-oracle}} package is available, and a prebuilt version can be found in the [[Unofficial user repositories#seblu|seblu]] repository.
 +
 
 +
If you prefer to use the traditional and manual way: download the extension manually and install it via the GUI (''File > Preferences > Extensions'') or via  {{ic|VBoxManage extpack install <.vbox-extpack>}}, make sure you have a toolkit like [[Polkit]] to grant privileged access to VirtualBox. The installation of this extension [https://www.virtualbox.org/ticket/8473 requires root access].
 +
 
 +
=== Front-ends ===
 +
 
 +
VirtualBox comes with three front-ends:
 +
 
 +
* If you want to use VirtualBox with the regular GUI, use {{ic|VirtualBox}}.
 +
* If you want to launch and manage your virtual machines from the command-line, use the {{ic|VBoxSDL}} command, which only provides a plain window for the virtual machine without any overlays.
 +
* If you want to use VirtualBox without running any GUI (e.g. on a server), use the {{ic|VBoxHeadless}} command. With the VRDP extension you can still remotely access the displays of your virtual machines.
 +
 
 +
Finally, you can also use [[phpVirtualBox]] to administrate your virtual machines via a web interface.
 +
 
 +
Refer to the [https://www.virtualbox.org/manual VirtualBox manual] to learn how to create virtual machines.
 +
 
 +
{{Warning|If you intend to store virtual disk images on a [[Btrfs]] file system, before creating any images, you should consider disabling [[Btrfs#Copy-on-Write (CoW)|copy-on-write]] for the destination directory of these images.}}
 +
 
 +
== Installation steps for Arch Linux guests ==
 +
 
 +
Boot the Arch installation media through one of the virtual machine's virtual drives. Then, complete the installation of a basic Arch system as explained in the [[Installation guide]].
 +
 
 +
=== Installation in EFI mode ===
 +
 
 +
If you want to install Arch Linux in EFI mode inside VirtualBox, in the settings of the virtual machine, choose ''System'' item from the panel on the left and ''Motherboard'' tab from the right panel, and check the checkbox ''Enable EFI (special OSes only)''. After selecting the kernel from the Arch Linux installation media's menu, the media will hang for a minute or two and will continue to boot the kernel normally afterwards. Be patient.
 +
 
 +
Once the system and the boot loader are installed, VirtualBox will first attempt to run {{ic|/EFI/BOOT/BOOTX64.EFI}} from the [[ESP]]. If that first option fails, VirtualBox will then try the EFI shell script {{ic|startup.nsh}} from the root of the ESP. This means that in order to boot the system you have the following options:
 +
 
 +
* [[Unified Extensible Firmware Interface#UEFI Shell|Launch the bootloader manually]] from the EFI shell every time;
 +
* Move the bootloader to the default {{ic|/EFI/BOOT/BOOTX64.EFI}} path;
 +
* Create a script named {{ic|startup.nsh}} at the ESP root containing the path to the boot loader application, e.g. {{ic|\EFI\grub\grubx64.efi}}.
 +
* Boot directly from the ESP partition using a [[EFISTUB#Using a startup.nsh script|startup.nsh script]].
 +
 
 +
Do not bother with the VirtualBox Boot Manager (accessible with {{ic|F2}} at boot), as it is buggy and incomplete. It does not store efivars set interactively. Therefore, EFI entries added to it manually in the firmware (accessed with {{ic|F12}} at boot time) or with {{Pkg|efibootmgr}} will persist after a reboot [https://www.virtualbox.org/ticket/11177 but are lost when the VM is shut down].
 +
 
 +
See also [https://bbs.archlinux.org/viewtopic.php?id=158003 UEFI VirtualBox installation boot problems].
 +
 
 +
=== Install the Guest Additions ===
 +
 
 +
VirtualBox [https://www.virtualbox.org/manual/ch04.html Guest Additions] provides drivers and applications that optimize the guest operating system including improved image resolution and better control of the mouse. Within the installed guest system, install:
 +
 
 +
* {{Pkg|virtualbox-guest-utils}} for VirtualBox Guest utilities with X support
 +
* {{Pkg|virtualbox-guest-utils-nox}} for VirtualBox Guest utilities without X support
 +
 
 +
Both packages will make you choose a package to provide guest modules:
 +
 
 +
* for the default {{Pkg|linux}} kernel choose {{Pkg|virtualbox-guest-modules-arch}}
 +
* for non-default [[kernels]] choose {{Pkg|virtualbox-guest-dkms}}
 +
 
 +
To compile the virtualbox modules provided by {{Pkg|virtualbox-guest-dkms}}, it will also be necessary to install the appropriate headers package(s) for your installed kernel(s) (e.g. {{Pkg|linux-lts-headers}} for {{Pkg|linux-lts}}). [https://lists.archlinux.org/pipermail/arch-dev-public/2016-March/027808.html] When either VirtualBox or the kernel is updated, the kernel modules will be automatically recompiled thanks to the [[DKMS]] Pacman hook.
 +
 
 +
{{Note|<nowiki></nowiki>
 +
* You can alternatively install the Guest Additions with the ISO from the {{Pkg|virtualbox-guest-iso}} package, provided you installed this on the host system. To do this, go to the device menu click Insert Guest Additions CD Image.
 +
* To recompile the vbox kernel modules, run {{ic|rcvboxdrv}} as root.
 +
}}
 +
 
 +
The guest additions running on your guest, and the VirtualBox application running on your host must have matching versions, otherwise the guest additions (like shared clipboard) may stop working. If you upgrade your guest (e.g. {{ic|pacman -Syu}}), make sure your VirtualBox application on this host is also the latest version. "Check for updates" in the VirtualBox GUI is sometimes not sufficient; check the [https://www.virtualbox.org/ VirtualBox.org] website.
 +
 
 +
=== Set optimal framebuffer resolution ===
 +
 
 +
{{Move|VirtualBox/Tips and tricks}}
 +
Typically after installing Guest Additions, a fullscreen Arch guest running X will be set to the optimal resolution for your display; however, the virtual console's framebuffer will be set to a standard, often smaller, resolution detected from VirtualBox's custom VESA driver.
 +
 
 +
To use the virtual consoles at optimal resolution, Arch needs to recognize that resolution as valid, which in turn requires VirtualBox to pass this information along to the guest OS.
 +
 
 +
First, check if your desired resolution is not already recognized by running the command:
 +
 
 +
hwinfo --framebuffer
 +
 
 +
If the optimal resolution does not show up, then you will need to run the {{ic|VBoxManage}} tool on the host machine and add "extra resolutions" to your virtual machine (on a Windows host, go to the VirtualBox installation directory to find {{ic|VBoxManage.exe}}). For example:
 +
 
 +
$ VBoxManage setextradata "Arch Linux" "CustomVideoMode1" "1360x768x24"
 +
 
 +
The parameters "Arch Linux" and "1360x768x24" in the example above should be replaced with your VM name and the desired framebuffer resolution. Incidentally, this command allows for defining up to 16 extra resolutions ("CustomVideoMode1" through "CustomVideoMode16").
 +
 
 +
Afterwards, restart the virtual machine and run {{ic|hwinfo --framebuffer}} once more to verify that the new resolutions have been recognized by your guest system (which does not guarantee they will all work, depending on your hardware limitations).
 +
 
 +
{{Note|As of VirtualBox 5.2, {{ic|hwinfo --framebuffer}} might not show any output, but you should still be able to set a custom resolution following this procedure.}}
 +
 
 +
Finally, add a {{ic|1=video=''resolution''}} [[kernel parameter]] to set the framebuffer to the new resolution, for example:
 +
 
 +
  video=1360x768
 +
 
 +
Additionally you may want to configure your [[bootloader]] to use the same resolution. If you use GRUB, see [[GRUB/Tips and tricks#Setting the framebuffer resolution]].
 +
 
 +
{{Note|Neither the kernel parameter {{ic|vga}} nor the bootloader's resolution settings (e.g. GRUB's {{ic|GRUB_GFXPAYLOAD_LINUX}}) will fix the framebuffer, since they are overriden by virtue of Kernel Mode Setting. The framebuffer resolution must be set by the kernel parameter {{ic|video}} as described above.}}
 +
 
 +
=== Load the VirtualBox kernel modules ===
 +
 
 +
To load the modules automatically, [[enable]] {{ic|vboxservice.service}} which loads the modules and synchronizes the guest's system time with the host.
 +
 
 +
To load the modules manually, type:
 +
 
 +
# modprobe -a vboxguest vboxsf vboxvideo
 +
 
 +
{{Pkg|virtualbox-guest-dkms}} uses {{ic|systemd-modules-load.service}} to load its modules at boot time.
 +
 
 +
{{Note|If you do not want the VirtualBox modules to be loaded at boot time, you have to [[mask]] the default {{ic|/usr/lib/modules-load.d/virtualbox-guest-dkms.conf}} by creating an empty file (or symlink to {{ic|/dev/null}}) with the same name in {{ic|/etc/modules-load.d/}}.}}
 +
 
 +
=== Launch the VirtualBox guest services ===
 +
 
 +
After the rather big installation step dealing with VirtualBox kernel modules, now you need to start the guest services. The guest services are actually just a binary executable called {{ic|VBoxClient}} which will interact with your X Window System. {{ic|VBoxClient}} manages the following features:
 +
 
 +
* shared clipboard and drag and drop between the host and the guest;
 +
* seamless window mode;
 +
* the guest display is automatically resized according to the size of the guest window;
 +
* checking the VirtualBox host version
 +
 
 +
All of these features can be enabled independently with their dedicated flags:
 +
 
 +
$ VBoxClient --clipboard --draganddrop --seamless --display --checkhostversion
 +
 
 +
As a shortcut, the {{ic|VBoxClient-all}} bash script enables all of these features.
 +
 
 +
{{Pkg|virtualbox-guest-utils}} installs {{ic|/etc/xdg/autostart/vboxclient.desktop}} that launches {{ic|VBoxClient-all}} on logon. If your [[desktop environment]] or [[window manager]] does not support [[XDG Autostart]], you will need to set up autostarting yourself, see [[Autostarting#On desktop environment startup]] and [[Autostarting#On window manager startup]] for more details.
 +
 
 +
VirtualBox can also synchronize the time between the host and the guest, to do this, [[start/enable]] the {{ic|vboxservice.service}}.
 +
 
 +
Now, you should have a working Arch Linux guest. Note that features like clipboard sharing are disabled by default in VirtualBox, and you will need to turn them on in the per-VM settings if you actually want to use them (e.g. ''Settings > General > Advanced > Shared Clipboard'').
 +
 
 +
=== Hardware acceleration ===
 +
 
 +
Hardware acceleration can be activated in the VirtualBox options. The [[GDM]] display manager 3.16+ is known to break hardware acceleration support. [https://bugzilla.gnome.org/show_bug.cgi?id=749390] So if you get issues with hardware acceleration, try out another display manager (lightdm seems to work fine). [https://bbs.archlinux.org/viewtopic.php?id=200025] [https://bbs.archlinux.org/viewtopic.php?pid=1607593#p1607593]
 +
 
 +
=== Enable shared folders ===
 +
 
 +
Shared folders are managed on the host, in the settings of the Virtual Machine accessible via the GUI of VirtualBox, in the ''Shared Folders'' tab. There, ''Folder Path'', the name of the mount point identified by ''Folder name'', and options like ''Read-only'', ''Auto-mount'' and ''Make permanent'' can be specified. These parameters can be defined with the {{ic|VBoxManage}} command line utility. See [https://www.virtualbox.org/manual/ch04.html#sharedfolders there for more details].
 +
 
 +
No matter which method you will use to mount your folder, all methods require some steps first.
 +
 
 +
To avoid this issue {{ic|/sbin/mount.vboxsf: mounting failed with the error: No such device}}, make sure the {{ic|vboxsf}} kernel module is properly loaded. It should be, since we enabled all guest kernel modules previously.
 +
 
 +
Two additional steps are needed in order for the mount point to be accessible from users other than root:
 +
 
 +
* the {{Pkg|virtualbox-guest-utils}} package created a group {{ic|vboxsf}} (done in a previous step);
 +
* your username must be in {{ic|vboxsf}} [[group]].
 +
 
 +
==== Manual mounting ====
 +
 
 +
Use the following command to mount your folder in your Arch Linux guest:
 +
 
 +
# mount -cit vboxsf ''shared_folder_name'' ''mount_point_on_guest_system''
 +
 
 +
The vboxsf filesystem offers other options which can be displayed with this command:
 +
 
 +
# mount.vboxsf
 +
 
 +
For example if the user was not in the ''vboxsf'' group, we could have used this command to give access our mountpoint to him:
 +
 
 +
# mount -cit vboxsf -o uid=1000,gid=1000 home /mnt
 +
 
 +
Where ''uid'' and ''gid'' are values corresponding to the users we want to give access to. These values are obtained from the {{ic|id}} command run against this user.
 +
 
 +
==== Automounting ====
 +
 
 +
{{Note|Automounting requires the {{ic|vboxservice.service}} to be [[enabled]]/[[started]].}}
 +
 
 +
In order for the automounting feature to work you must have checked the auto-mount checkbox in the GUI or used the optional {{ic|--automount}} argument with the command {{ic|VBoxManage sharedfolder}}.
 +
 
 +
The shared folder should now appear in {{ic|/media/sf_''shared_folder_name''}}. If users in {{ic|media}} cannot access the shared folders, check that {{ic|media}} has permissions {{ic|755}} or has group ownership {{ic|vboxsf}} if using permission {{ic|750}}. This is currently not the default if media is created by installing {{Pkg|virtualbox-guest-utils}}.
 +
 
 +
You can use symlinks if you want to have a more convenient access and avoid to browse in that directory, e.g.:
 +
$ ln -s /media/sf_''shared_folder_name'' ~/''my_documents''
 +
 
 +
==== Mount at boot ====
 +
 
 +
{{Note|{{ic|mount.vboxsf}} will not mount shared folders from {{ic|/etc/fstab}} on kernels 4.16 or newer. See [[#Cannot mount shared folder from fstab]] for a workaround.}}
 +
 
 +
You can mount your directory with [[fstab]]. However, to prevent startup problems with systemd, {{ic|1=noauto,x-systemd.automount}} should be added to {{ic|/etc/fstab}}. This way, the shared folders are mounted only when those mount points are accessed and not during startup. This can avoid some problems, especially if the guest additions are not loaded yet when systemd reads fstab and mounts the partitions.
 +
''sharedFolderName''  ''/path/to/mntPtOnGuestMachine''  vboxsf  uid=''user'',gid=''group'',rw,dmode=700,fmode=600,noauto,x-systemd.automount
 +
 
 +
* {{ic|''sharedFolderName''}}: the value from the VirtualMachine's ''Settings > SharedFolders > Edit > FolderName'' menu. This value can be different from the name of the real folder name on the host machine. To see the VirtualMachine's ''Settings'' go to the host OS VirtualBox application, select the corresponding virtual machine and click on ''Settings''.
 +
* {{ic|''/path/to/mntPtOnGuestMachine''}}: if not existing, this directory should be created manually (for example by using [[Core utilities#mkdir|mkdir]])
 +
* {{ic|dmode}}/{{ic|fmode}} are directory/file permissions for directories/files inside {{ic|''/path/to/mntPtOnGuestMachine''}}.
 +
 
 +
As of 2012-08-02, mount.vboxsf does not support the ''nofail'' option:
 +
''desktop''  ''/media/desktop''  vboxsf  uid=''user'',gid=''group'',rw,dmode=700,fmode=600,nofail  0  0
 +
 
 +
=== SSH from host to guest ===
 +
 
 +
The network tab of the virtual machine settings contains, in "Advanced", a tool to create port forwarding.
 +
It is possible to use it to forward the Guest ssh port {{ic|22}} to a Host port, e.g. {{ic|3022}} :
 +
 
 +
user@host$ ssh -p 3022 $USER@localhost
 +
 
 +
will establish a connection from Host to Guest.
 +
 
 +
==== SSHFS as alternative to the shared folder ====
  
Lastly, edit {{Filename|/etc/rc.conf}} as root and add '''vboxdrv''' to the MODULES array in order to load the VirtualBox drivers at startup. For example:
+
Using this port forwarding and sshfs, it is straightforward to mount the Guest filesystem onto the Host one:
MODULES=(loop '''vboxdrv''' fuse ...)
 
  
To load the module manually, run the following in a terminal as root:  
+
user@host$ sshfs -p 3022 $USER@localhost:$HOME ~/shared_folder
  # modprobe vboxdrv
+
 
 +
and then transfer files between both.
 +
 
 +
== Virtual disks management ==
 +
 
 +
See also [[VirtualBox/Tips and tricks#Import/export VirtualBox virtual machines from/to other hypervisors]].
 +
 
 +
=== Formats supported by VirtualBox ===
 +
 
 +
VirtualBox supports the following virtual disk formats:
 +
 
 +
* '''VDI''': The Virtual Disk Image is the VirtualBox own open container used by default when you create a virtual machine with VirtualBox.
 +
 
 +
* '''VMDK''': The Virtual Machine Disk has been initially developed by VMware for their products. The specification was initially closed source, but it became now an open format which is fully supported by VirtualBox. This format offers the ability to be split into several 2GB files. This feature is especially useful if you want to store the virtual machine on machines which do not support very large files. Other formats, excluding the HDD format from Parallels, do not provide such an equivalent feature.
 +
 
 +
* '''VHD''': The Virtual Hard Disk is the format used by Microsoft in Windows Virtual PC and Hyper-V. If you intend to use any of these Microsoft products, you will have to choose this format.
 +
:{{Tip|Since Windows 7, this format can be mounted directly without any additional application.}}
 +
 
 +
* '''VHDX''' (read only): This is the eXtended version of the Virtual Hard Disk format developed by Microsoft, which has been released on 2012-09-04 with Hyper-V 3.0 coming with Windows Server 2012. This new version of the disk format does offer enhanced performance (better block alignment), larger blocks size, and journal support which brings power failure resiliency. VirtualBox [https://www.virtualbox.org/manual/ch15.html#idp63002176 should support this format in read only].
 +
 
 +
* '''HDD''' (version 2): The HDD format is developed by Parallels Inc and used in their hypervisor solutions like Parallels Desktop for Mac.  Newer versions of this format (i.e. 3 and 4) are not supported due to the lack of documentation for this proprietary format. {{Note|There is currently a controversy regarding the support of the version 2 of the format. While the official VirtualBox manual [https://www.virtualbox.org/manual/ch05.html#vdidetails only reports the second version of the HDD file format as supported], Wikipedia's contributors are [[Wikipedia:Comparison of platform virtual machines#Image type compatibility|reporting the first version may work too]]. Help is welcome if you can perform some tests with the first version of the HDD format.}}
 +
 
 +
* '''QED''': The QEMU Enhanced Disk format is an old file format for QEMU, another free and open source hypervisor. This format was designed from 2010 in a way to provide a superior alternative to QCOW2 and others. This format features a fully asynchronous I/O path, strong data integrity, backing files, and sparse files. QED format is supported only for compatibility with virtual machines created with old versions of QEMU.
 +
 
 +
* '''QCOW''': The QEMU Copy On Write format is the current format for QEMU. The QCOW format does support zlib-based transparent compression and encryption (the latter is flawed and is not recommended). QCOW is available in two versions: QCOW and QCOW2. QCOW2 tends to supersede the first one. QCOW is [https://www.virtualbox.org/manual/ch15.html#idp63002176 currently fully supported by VirtualBox]. QCOW2 comes in two revisions: QCOW2 0.10 and QCOW2 1.1 (which is the default when you create a virtual disk with QEMU). VirtualBox does not support QCOW2.
 +
 
 +
* '''OVF''': The Open Virtualization Format is an open format which has been designed for interoperability and distributions of virtual machines between different hypervisors. VirtualBox supports all revisions of this format via the [https://www.virtualbox.org/manual/ch08.html#idp55423424 VBoxManage import/export feature] but with [https://www.virtualbox.org/manual/ch14.html#KnownProblems known limitations].
 +
 
 +
* '''RAW''': This is the mode when the virtual disk is exposed directly to the disk without being contained in a specific file format container. VirtualBox supports this feature in several ways: converting RAW disk [https://www.virtualbox.org/manual/ch08.html#idp59139136 to a specific format], or by [https://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi cloning a disk to RAW], or by using directly a VMDK file [https://www.virtualbox.org/manual/ch09.html#idp57804112 which points to a physical disk or a simple file].
 +
 
 +
=== Disk image format conversion ===
 +
 
 +
[https://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi VBoxManage clonehd] can be used to convert between VDI, VMDK, VHD and RAW.
 +
 
 +
$ VBoxManage clonehd ''inputfile'' ''outputfile'' --format ''outputformat''
 +
 
 +
For example to convert VDI to VMDK:
 +
 
 +
$ VBoxManage clonehd ''source.vdi'' ''destination.vmdk'' --format VMDK
 +
 
 +
==== QCOW ====
 +
 
 +
VirtualBox does not support [[QEMU]]'s QCOW2 disk image format. To use a QCOW2 disk image with VirtualBox you therefore need to convert it, which you can do with {{Pkg|qemu}}'s {{ic|qemu-img}} command. {{ic|qemu-img}} can convert QCOW to / from VDI, VMDK, VHDX, RAW and various other formats (which you can see by running {{ic|qemu-img --help}}).
 +
 
 +
  $ qemu-img convert -O ''output_fmt'' ''inputfile'' ''outputfile''
 +
 
 +
For example to convert QCOW2 to VDI:
 +
 
 +
$ qemu-img convert -O vdi ''source.qcow2'' ''destination.vdi''
 +
 
 +
{{Tip|The {{ic|-p}} parameter is used to get the progression of the conversion task.}}
 +
 
 +
There are two revisions of QCOW2: 0.10 and 1.1. You can specify the revision to use with {{ic|1=-o compat=''revision''}}.
 +
 
 +
=== Mount virtual disks ===
 +
 
 +
==== VDI ====
 +
 
 +
Mounting VDI images only works with fixed size images (a.k.a. static images); dynamic (dynamically size allocating) images are not easily mountable.
  
===Install VirtualBox (OSE) on x86_64===
+
The offset of the partition (within the VDI) is needed, then add the value of {{ic|offData}} to {{ic|32256}} (e.g. 69632 + 32256 = 101888):
VirtualBox (OSE) can be installed on the x86_64 platform without downloading a version from the AUR. The current download of VirtualBox (OSE) from the VirtualBox website for *all distributions* under VirtualBox for Linux hosts installs properly after installing the kernel26-headers.
 
  
  # pacman -S kernel26-headers
+
  $ VBoxManage internalcommands dumphdinfo <storage.vdi> | grep "offData"
  
Once the kernel headers are downloaded and installed, you may run the VirtualBox OSE install downloaded from the VirtualBox website.
+
The can now be mounted with:
The current version as of 2010/15/06 is 3.2.4 and can be downloaded from this URL: [http://download.virtualbox.org/virtualbox/3.2.4/VirtualBox-3.2.4-62467-Linux_amd64.run] If you choose to download this file from the website yourself, make sure you are downloading the amd64 version for all distributions as mentioned above. After the file is successfully downloaded to your preferred location, run the installer as root (or with sudo) with the following command:
 
  
  # sh VirtualBox-3.2.4-62467-Linux_amd64.run
+
  # mount -t ext4 -o rw,noatime,noexec,loop,offset=101888 <storage.vdi> /mntpoint/
{{Note | Edit the file name to match the version (if applicable) of which you downloaded.}}
 
  
After a successful installation, you may run the program from your Applications menu, usually under system tools.
+
You can also use [https://github.com/pld-linux/VirtualBox/blob/master/mount.vdi mount.vdi] script that, which you can use as (install script itself to {{ic|/usr/bin/}}):
  
===Install VirtualBox PUEL (virtualbox_bin)===
+
# mount -t vdi -o fstype=ext4,rw,noatime,noexec ''vdi_file_location'' ''/mnt/''
VirtualBox PUEL is available from the [http://aur.archlinux.org/packages.php?ID=9753 AUR: virtualbox_bin].
 
  
Download the tarball from the above page. As a normal user, unpack, change directory, and {{Codeline|makepkg}}:
+
Alternately you can use {{Pkg|qemu}}'s kernel module that can do this [http://bethesignal.org/blog/2011/01/05/how-to-mount-virtualbox-vdi-image/ attrib]:
$ tar -xzf virtualbox_bin.tar.gz
 
$ cd virtualbox_bin
 
$ makepkg
 
This will create a .pkg.tar.gz file in the virtualbox_bin directory.
 
Then, as root:
 
# pacman -U PACKAGE-NAME.pkg.tar.gz
 
This will compile the vboxdrv kernel modules and install VirtualBox in {{Filename|/opt/VirtualBox}}, and add the vboxusers group.
 
  
Now, add the desired username to the '''vboxusers''' group:
+
# modprobe nbd max_part=16
  # gpasswd -a USERNAME vboxusers
+
# qemu-nbd -c /dev/nbd0 <storage.vdi>
 +
# mount /dev/nbd0p1 /mnt/dir/
 +
# # to unmount:
 +
  # umount /mnt/dir/
 +
# qemu-nbd -d /dev/nbd0
  
{{Note | You must logout/login in order for this change to take effect.}}
+
If the partition nodes are not propagated try using {{ic|partprobe /dev/nbd0}}; otherwise, a VDI partition can be mapped directly to a node by: {{ic|qemu-nbd -P 1 -c /dev/nbd0 <storage.vdi>}}.
  
Lastly, edit {{Filename|/etc/rc.conf}} as root and add '''vboxdrv''' to the MODULES array in order to load the VirtualBox drivers at startup. For example:
+
=== Compact virtual disks ===
MODULES=(loop '''vboxdrv''' fuse ...)
 
  
To load the module manually, run the following in a terminal as root:
+
Compacting virtual disks only works with ''.vdi'' files and basically consists of the following steps.
# modprobe vboxdrv
 
  
====Install required QT libraries====
+
Boot your virtual machine and remove all bloat manually or by using cleaning tools like {{Pkg|bleachbit}} which is [http://bleachbit.sourceforge.net/download/windows available for Windows systems too].
Currently, VirtualBox relies on QT4 for its graphical interface. If you require a GUI, ensure you have QT4 installed:
 
# pacman -S qt
 
  
==Configuration==
+
Wiping free space with zeroes can be achieved with several tools:
After having installed VirtualBox on your system and added yourself to the vboxusers group, you can start configuring your system in order to make all the features of VirtualBox available. Create a new virtual machine using the wizard provided by the GUI and then click settings in order to edit the virtual machine settings.
+
* If you were previously using Bleachbit, check the checkbox ''System > Free disk space'' in the GUI, or use {{ic|bleachbit -c system.free_disk_space}} in CLI;
 +
* On UNIX-based systems, by using {{ic|dd}} or preferably {{Pkg|dcfldd}} (see [http://superuser.com/a/355322 here] to learn the differences):
 +
:{{bc|1=# dcfldd if=/dev/zero of=''/fillfile'' bs=4M}}
 +
:When {{ic|fillfile}} reaches the limit of the partition, you will get a message like {{ic|1280 blocks (5120Mb) written.dcfldd:: No space left on device}}. This means that all of the user-space and non-reserved blocks of the partition will be filled with zeros. Using this command as root is important to make sure all free blocks have been overwritten. Indeed, by default, when using partitions with ext filesystem, a specified percentage of filesystem blocks is reserved for the super-user (see the {{ic|-m}} argument in the {{ic|mkfs.ext4}} man pages or use {{ic|tune2fs -l}} to see how much space is reserved for root applications).
 +
:When the aforementioned process has completed, you can remove the file {{ic|''fillfile''}} you created.
  
===Keyboard and mouse between the host and the guest===
+
* On Windows, there are two tools available:
*To capture the keyboard and mouse, click the mouse inside the Virtual Machine display.
+
:*{{ic|sdelete}} from the [http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx Sysinternals Suite], type {{ic|sdelete -s -z ''c:''}}, where you need to reexecute the command for each drive you have in your virtual machine;
*To uncapture, press the right Ctrl key, alone.
+
:* or, if you love scripts, there is a [http://blog.whatsupduck.net/2012/03/powershell-alternative-to-sdelete.html PowerShell solution], but which still needs to be repeated for all drives.
 +
::{{bc|PS> ./Write-ZeroesToFreeSpace.ps1 -Root ''c:\'' -PercentFree 0}}
 +
::{{Note|This script must be run in a PowerShell environment with administrator privileges. By default, scripts cannot be run, ensure the execution policy is at least on {{ic|RemoteSigned}} and not on {{ic|Restricted}}. This can be checked with {{ic|Get-ExecutionPolicy}} and the required policy can be set with {{ic|Set-ExecutionPolicy RemoteSigned}}.}}
  
To get seamless mouse integration between host and guest, you need to install the Virtualbox additions into the guest.
+
Once the free disk space have been wiped, shut down your virtual machine.
  
Also, mouse pointer integration does not work out of the box. To fix it, make sure you have the following sections in your guest's {{Filename|xorg.conf}}:
+
The next time you boot your virtual machine, it is recommended to do a filesystem check.
  Section "InputDevice"
+
* On UNIX-based systems, you can use {{ic|fsck}} manually;
    Identifier "Mouse0"
+
:* On GNU/Linux systems, and thus on Arch Linux, you can force a disk check at boot [[Fsck#Forcing the check|thanks to a kernel boot parameter]];
    Driver "vboxmouse"
+
* On Windows systems, you can use:
    Option        "Protocol" "auto"
+
:* either {{ic|chkdsk ''c:'' /F}} where {{ic|''c:''}} needs to be replaced by each disk you need to scan and fix errors;
    Option        "Device" "/dev/input/mice"
+
:* or {{ic|FsckDskAll}} [http://therightstuff.de/2009/02/14/ChkDskAll-ChkDsk-For-All-Drives.aspx from here] which is basically the same software as {{ic|chkdsk}}, but without the need to repeat the command for all drives;
    Option        "ZAxisMapping" "4 5 6 7"
 
EndSection
 
  
Section "ServerLayout"
+
Now, remove the zeros from the ''.vdi'' file with [https://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi VBoxManage modifyhd]:
    Identifier    "X.org Configured"
+
  $ VBoxManage modifyhd ''your_disk.vdi'' --compact
    Screen      0 "Screen0" 0 0
 
    InputDevice    "Mouse0" "CorePointer"
 
    InputDevice    "Keyboard0" "CoreKeyboard"
 
EndSection
 
  
When generating your {{Filename|xorg.conf}} with {{Codeline|"X -configure"}}, you will end up with an InputDevice section that uses the {{Codeline|mouse}} driver. After installing the Guest Additions, you should replace {{Codeline|mouse}} with {{Codeline|vboxmouse}} and then restart X or reboot your VM.
+
{{Note|If your virtual machine has snapshots, you need to apply the above command on each {{ic|.vdi}} files you have.}}
  
===Getting network in the guest machine to work===
+
=== Increase virtual disks ===
First, get network working in the guest machine. Click the network tab. The not attached option means you will have "Network cable unplugged" or similar error in the guest computer.
 
  
====Using NAT network====
+
==== General procedure ====
This is the simplest way to get network. Select NAT network and it should be ready to use. Then, the guest operating system can be automatically configured by using DHCP.
 
  
The NAT IP address on the first card is 10.0.2.0, 10.0.3.0 on the second and so on.
+
If you are running out of space due to the small hard drive size you selected when you created your virtual machine, the solution adviced by the VirtualBox manual is to use [https://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi VBoxManage modifyhd]. However this command only works for VDI and VHD disks and only for the dynamically allocated variants. If you want to resize a fixed size virtual disk disk too, read on this trick which works either for a Windows or UNIX-like virtual machine.
  
Also in VirtualBox 2.2.0+ NAT network DHCP clients will not configure your nameserver (DNS server for windows guests) you will have to manually configure the nameserver(DNS server)
+
First, create a new virtual disk next to the one you want to increase:
  
====Using host interface networking (the VirtualBox way)====
+
$ VBoxManage createhd -filename ''new.vdi'' --size ''10000''
Since VirtuaBox 2.1.0 it has a native support for host interface networking. Just add '''vboxnetflt''' to your MODULES section in {{Filename|[[rc.conf]]}} and choose ''Host Interface Networking'' (or ''Bridged adapter'' in [http://forums.virtualbox.org/viewtopic.php?f=1&t=16447 2.2]) in the virtual machine configuration.
 
  
'''Note''': DHCP broadcasting does not seem to work properly under this way. Set up your guest networking with static IP assignment.
+
where size is in MiB, in this example 10000MiB ~= 10GiB, and ''new.vdi'' is name of new hard drive to be created.
  
====Using host interface networking (the Arch way)====
+
{{Note|By default, this command uses the ''Standard'' (corresponding to dynamic allocated) file format variant and thus will not use the same file format variant as your source virtual disk. If your ''old.vdi'' has a fixed size and you want to keep this variant, add the parameter {{ic|--variant Fixed}}.}}
You are going to just edit these files and reboot:
 
  
* {{Filename|/etc/conf.d/bridges}}
+
Next, the old virtual disk needs to be cloned to the new one which this may take some time:
* {{Filename|/etc/rc.conf}}
 
* {{Filename|/etc/vbox/interfaces}}
 
  
Edit:
+
$ VBoxManage clonehd ''old.vdi'' ''new.vdi'' --existing
'''{{Filename|/etc/conf.d/bridges}}'''
 
bridge_br0="eth0 vbox0" # Put any interfaces you need.
 
BRIDGE_INTERFACES=(br0)
 
  
'''{{Filename|/etc/rc.conf}}'''
+
Detach the old hard drive and attach new one, replace all mandatory italic arguments by your own:
  
First add the bridge module to your MODULES line
+
$ VBoxManage storageattach ''VM_name'' --storagectl ''SATA'' --port ''0'' --medium none
  MODULES=( <your other modules> '''bridge''')
+
  $ VBoxManage storageattach ''VM_name'' --storagectl ''SATA'' --port ''0'' --medium ''new.vdi'' --type hdd
  
Then, in your NETWORKING section, make the following changes:
+
To get the storage controller name and the port number, you can use the command {{ic|VBoxManage showvminfo ''VM_name''}}. Among the output you will get such a result (what you are looking for is in italic):
eth0="eth0 up"
 
br0="dhcp" # Maybe you have some static configuration; change to fit
 
INTERFACES=(eth0 br0)
 
  
'''Note''' by gpan:
+
{{bc|
 +
[...]
 +
Storage Controller Name (0):            IDE
 +
Storage Controller Type (0):            PIIX4
 +
Storage Controller Instance Number (0): 0
 +
Storage Controller Max Port Count (0):  2
 +
Storage Controller Port Count (0):      2
 +
Storage Controller Bootable (0):        on
 +
Storage Controller Name (1):            SATA
 +
Storage Controller Type (1):            IntelAhci
 +
Storage Controller Instance Number (1): 0
 +
Storage Controller Max Port Count (1):  30
 +
Storage Controller Port Count (1):      1
 +
Storage Controller Bootable (1):        on
 +
IDE (1, 0): Empty
 +
''SATA'' (''0'', 0): /home/wget/IT/Virtual_machines/GNU_Linux_distributions/ArchLinux_x64_EFI/Snapshots/{6bb17af7-e8a2-4bbf-baac-fbba05ebd704}.vdi (UUID: 6bb17af7-e8a2-4bbf-baac-fbba05ebd704)
 +
[...]
 +
}}
  
'''{{Filename|/etc/rc.conf}}'''
+
Download [http://gparted.org/download.php GParted live image] and mount it as a virtual CD/DVD disk file, boot your virtual machine, increase/move your partitions, umount GParted live and reboot.
  
First add the vboxdrv (and vboxnetflt in case of 2.1.0 version) module to your MODULES line:
+
{{Note|On GPT disks, increasing the size of the disk will result in the backup GPT header not being at the end of the device. GParted will ask to fix this, click on ''Fix'' both times. On MBR disks, you do not have such a problem as this partition table as no trailer at the end of the disk.}}
MODULES=( <your other modules> vboxdrv vboxnetflt )
 
  
'''Note''' by vit:
+
Finally, unregister the virtual disk from VirtualBox and remove the file:
  
'''{{Filename|/etc/rc.conf}}'''
+
$ VBoxManage closemedium disk ''old.vdi''
 +
$ rm ''old.vdi''
  
In my case it did not work untill adding vboxnetadp to modules.
+
==== Increasing the size of VDI disks ====
  
Next, you should edit your {{Filename|/etc/udev/rules.d/60-vboxdrv.rules}} and type:
+
If your disk is a VDI one, run:
KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660"
 
  
Save it and exit.
+
$ VBoxManage modifyhd ''your_virtual_disk.vdi'' --resize ''the_new_size''
  
Then open terminal and type:
+
Then jump back to the Gparted step, to increase the size of the partition on the virtual disk.
# pacman -S bridge-utils uml_utilities
 
  
Create a new bridge with this command:
+
=== Replace a virtual disk manually from the .vbox file ===
# brctl addbr br0
 
  
'''{{Filename|/etc/vbox/interfaces}}'''
+
If you think that editing a simple ''XML'' file is more convenient than playing with the GUI or with {{ic|VBoxManage}} and you want to replace (or add) a virtual disk to your virtual machine, in the ''.vbox'' configuration file corresponding to your virtual machine, simply replace the GUID, the file location and the format to your needs:
  
(You can set up more interfaces if you want. Sky is the limit!):
+
{{hc|ArchLinux_vm.vbox|2=
vbox0 your_user br0 # Be sure that your user is in the vboxusers group.
+
<HardDisk uuid="''{670157e5-8bd4-4f7b-8b96-9ee412a712b5}''" location="''ArchLinux_vm.vdi''" format="''VDI''" type="Normal"/>
 +
}}
  
Reboot.
+
then in the {{ic|<AttachedDevice>}} sub-tag of {{ic|<StorageController>}}, replace the GUID by the new one.
  
{{Note | Remember to set up your virtual machine with proper network configuration. (Attach a "Bridged Adapter" and choose "br0") }}
+
{{hc|ArchLinux_vm.vbox|2=
{{Note | If you have any issue, make sure that you have the bridge-utils package installed and vboxnet daemon loaded.}}
+
<AttachedDevice type="HardDisk" port="0" device="0">
 +
  <Image uuid="''{670157e5-8bd4-4f7b-8b96-9ee412a712b5}''"/>
 +
</AttachedDevice>
 +
}}
  
====Using host interface networking (generic)====
+
{{Note|If you do not know the GUID of the drive you want to add, you can use the {{ic|VBoxManage showhdinfo ''file''}}. If you previously used {{ic|VBoxManage clonehd}} to copy/convert your virtual disk, this command should have outputted the GUID just after the copy/conversion completed. Using a random GUID does not work, as each [http://www.virtualbox.org/manual/ch05.html#cloningvdis UUID is stored inside each disk image].}}
This way is a bit harder, but it allows you to see the VirtualMachine as a "real" computer on your local network. You need to get bridge-utils
 
  
# pacman -S bridge-utils uml_utilities
+
==== Transfer between Linux host and other OS ====
  
'''Note''' by Sp1d3rmxn:
+
The information about path to harddisks and the snapshots is stored between {{ic|<HardDisks> .... </HardDisks>}} tags in the file with the ''.vbox'' extension. You can edit them manually or use this script where you will need change only the path or use defaults, assumed that ''.vbox'' is in the same directory with a virtual harddisk and the snapshots folder. It will print out new configuration to stdout.
:You also need to have the TUN module loaded... in {{Filename|[[rc.conf]]}} add {{Codeline|"tun"}} (without the quotes) to your MODULES section. For testing this out right now without rebooting you can load the module from the command line by {{Codeline|"modprobe tun"}}.
 
:
 
:Then you MUST set these permissions otherwise you will never get VBox to init the interface.  The command is {{Codeline|"chmod 666 /dev/net/tun"}} (without the quotes).
 
  
:Now proceed with the rest as it is written below.
+
{{bc|1=
 +
#!/bin/bash
 +
NewPath="${PWD}/"
 +
Snapshots="Snapshots/"
 +
Filename="$1"
  
'''Note'''
+
awk -v SetPath="$NewPath" -v SnapPath="$Snapshots" '{if(index($0,"<HardDisk uuid=") != 0){A=$3;split(A,B,"=");
:As said by Sp1d3rmxn, set these permissions, but, instead of using the command, set them in {{Filename|/etc/udev/rules.d/60-vboxdrv.rules}}, which will apply them on boot:
+
L=B[2];
KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660"
+
gsub(/\"/,"",L);
KERNEL=="tun", OWNER="root", GROUP="vboxusers", MODE="0660"
+
  sub(/^.*\//,"",L);
 +
  sub(/^.*\\/,"",L);
 +
if(index($3,"{") != 0){SnapS=SnapPath}else{SnapS=""};
 +
  print $1" "$2" location="\"SetPath SnapS L"\" "$4" "$5}
 +
else print $0}' "$Filename"
 +
}}
  
 +
{{Note|
 +
* If you will prepare virtual machine for use in Windows host then in the path name end you should use backslash \ instead of / .
 +
* The script detects snapshots by looking for {{ic|{}} in the file name.
 +
* To make it run on a new host you will need to add it first to the register by clicking on '''Machine -> Add...''' or use hotkeys Ctrl+A and then browse to ''.vbox'' file that contains configuration or use command line {{ic|VBoxManage registervm ''filename''.vbox}}
 +
}}
  
'''1.''' Create a new bridge with this command:
+
=== Clone a virtual disk and assigning a new UUID to it ===
# brctl addbr br0
 
  
'''2.''' If you are not using DHCP, run ifconfig and note down the network configuration of your existing network interface (e.g. eth0), which will need to be copied to the bridge.
+
UUIDs are widely used by VirtualBox. Each virtual machines and each virtual disk of a virtual machine must have a different UUID. When you launch a virtual machine in VirtualBox, VirtualBox will keep track of all UUIDs of your virtual machine instance. See the [http://www.virtualbox.org/manual/ch08.html#vboxmanage-list VBoxManage list] to list the items registered with VirtualBox.
  
{{Note|You will need this settings so make sure you do not lose them.}}
+
If you cloned a virtual disk manually by copying the virtual disk file, you will need to assign a new UUID to the cloned virtual drive if you want to use the disk in the same virtual machine or even in another (if that one has already been opened, and thus registered, with VirtualBox).
  
'''3.''' Switch your physical network adapter to "promiscuous" mode so that it will accept Ethernet frames for MAC addresses other than its own (replace {{Codeline|eth0}} with your network interface):
+
You can use this command to assign a new UUID to a virtual disk:
# ifconfig eth0 0.0.0.0 promisc
+
$ VBoxManage internalcommands sethduuid ''/path/to/disk.vdi''
  
{{Note | You will lose network connectivity on eth0 at this point.}}
+
{{Tip|To avoid copying the virtual disk and assigning a new UUID to your file manually you can use [http://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi VBoxManage clonehd].}}
  
'''4.''' Add your network adapter to the bridge:
+
{{Note|The commands above support all [[#Formats supported by VirtualBox|virtual disk formats supported by VirtualBox]].}}
# brctl addif br0 eth0
 
  
'''5.''' Transfer the network configuration previously used with your physical ethernet adapter to the new bridge. If you are using DHCP, this should work:
+
== Tips and tricks ==
# dhclient br0
 
  
'''Note''' by Sp1d3rmxn:
+
For advanced configuration, see [[VirtualBox/Tips and tricks]].
:Use {{Codeline|"dhcpcd -t 30 -h yourhostname br0 &"}} instead of the above
 
  
Otherwise, run {{Codeline|"ifconfig br0 x.x.x.x netmask x.x.x.x"}} and use the values that you noted down previously.
+
== Troubleshooting ==
  
'''6.''' To create a permanent host interface called vbox0 (all host interfaces created in this way must be called vbox followed by a number) and add it to the network bridge created above, use the following command:
+
=== Keyboard and mouse are locked into virtual machine ===
VBoxAddIF vbox0 vboxuser br0
 
  
Replace {{Codeline|vboxuser}} with the name of the user who is supposed to be able to use the new interface.
+
This means your virtual machine has captured the input of your keyboard and your mouse. Simply press the right {{ic|Ctrl}} key and your input should control your host again.
  
{{Note | VboxAddIF is located in /opt/VirtualBox-VERSION OF VIRTUALBOX/VBoxAddIF}}
+
To control transparently your virtual machine with your mouse going back and forth your host, without having to press any key, and thus have a seamless integration, install the guest additions inside the guest. Read from the [[#Install the Guest Additions]] step if you guest is Arch Linux, otherwise read the official VirtualBox help.
  
Alternatively, you can [http://mychael.gotdns.com/blog/2007/05/31/virtualbox-bridging/ setup VirtualBox networking] through your {{Filename|/etc/rc.conf}} to enable a bridged connection.
+
=== No 64-bit OS client options ===
  
====Using host interface networking with a wireless device====
+
When launching a VM client, and no 64-bit options are available, make sure your CPU virtualization capabilities (usually named {{ic|VT-x}}) are enabled in the BIOS.
Bridging as described above will not work with a wireless device. Using [http://aur.archlinux.org/packages.php?ID=16356 parprouted] however it can be accomplished.
 
  
# Install parprouted and iproute
+
If you are using a Windows host, you may need to disable Hyper-V, as it prevents VirtualBox from using VT-x. [https://www.virtualbox.org/ticket/12350]
# {{Codeline|# ln -s /usr/sbin/ip /sbin/ip}}
 
# Make sure IP fowarding is enabled: {{Codeline|# sysctl net.ipv4.ip_forward&#61;1}}, and/or edit {{Filename|/etc/sysctl.conf}}.
 
# {{Codeline|# VBoxTunctl -b -u <user>}}, to create the tap device
 
# {{Codeline|# ip link set tap0 up; ip addr add 192.168.0.X/24 dev tap0}}, needs to be a manually set IP on the same network your wireless device is.
 
# {{Codeline|# parprouted wlan0 tap0}}
 
  
===Getting USB to work in the guest machine===
+
=== VirtualBox GUI does not match host GTK theme ===
(Only available in the PUEL edition)
 
  
{{Note|As of VirtualBox>2.2.4 this is no longer necessary to mount a usb filesystem.}}
+
See [[Uniform look for Qt and GTK applications]] for information about theming Qt-based applications like VirtualBox.
  
First in order to make USB available for use to the virtual machine you must add this line to your {{Filename|/etc/fstab}}:
+
=== Cannot send Ctrl+Alt+Fn to guest ===
none /proc/bus/usb usbfs auto,busgid=108,busmode=0775,devgid=108,devmode=0664 0 0
 
  
Then tell mount to reread {{Filename|/etc/fstab}}:
+
Your guest operating system is a GNU/Linux distribution and you want to open a new TTY shell by hitting {{ic|Ctrl+Alt+F2}} or exit your current X session with {{ic|Ctrl+Alt+Backspace}}. If you type these keyboard shortcuts without any adaptation, the guest will not receive any input and the host (if it is a GNU/Linux distribution too) will intercept these shortcut keys. To send {{ic|Ctrl+Alt+F2}} to the guest for example, simply hit your ''Host Key'' (usually the right {{ic|Ctrl}} key) and press {{ic|F2}} simultaneously.
# mount -a
 
  
{{Codeline|108}} is is the id of the group which should be allowed to access USB-devices. Change it to the id of your vboxusers group. You can get the id by running:
+
=== USB subsystem not working ===
$ grep vboxusers /etc/group
 
  
Restart Virtualbox and click the USB tab in the settings of the virtual machine and select which devices are available to your pc on boot. If you wish your virtual machine to use device that you have just plugged in (assuming the virtual machine has booted already), go to the VirtualMachine screen go to ''Devices &rarr; USB Devices'' and select the device you wish to plug in the virtual PC.
+
Your user must be in the {{ic|vboxusers}} group and you need to install the [[#Extension pack|extension pack]] if you want USB 2 support. Then you will be able to enable USB 2 in the VM settings and add one or several filters for the devices you want to access from the guest OS.
  
'''Note''' by bjimba:
+
If {{ic|VBoxManage list usbhost}} does not show any USB devices even if run as root, make sure that there is no old udev rules (from VirtualBox 4.x) in {{ic|/etc/udev/rules.d/}}. VirtualBox 5.0 installs udev rules to {{ic|/usr/lib/udev/rules.d/}}. You can use command like {{ic|pacman -Qo /usr/lib/udev/rules.d/60-vboxdrv.rules}} to determine if the udev rule file is outdated.
  
Recent versions of VirtualBox, as noted above, do not require usbfs, however you will need the HAL daemon running if you do not use usbfs.  See the [[HAL]] wiki page for details.
+
Sometimes, on old Linux hosts, the USB subsystem is not auto-detected resulting in an error {{ic|Could not load the Host USB Proxy service: VERR_NOT_FOUND}} or in a not visible USB drive on the host, [https://bbs.archlinux.org/viewtopic.php?id=121377 even when the user is in the '''vboxusers''' group]. This problem is due to the fact that VirtualBox switched from ''usbfs'' to ''sysfs'' in version 3.0.8. If the host does not understand this change, you can revert to the old behaviour by defining the following environment variable in any file that is sourced by your shell (e.g. your {{ic|~/.bashrc}} if you are using ''bash''):
  
===Installing Guest Additions===
+
{{hc|~/.bashrc|2=
The Guest Additions make the shared folders feature available, as well as better video (3D available in version 2.1+) and mouse drivers. You will have mouse integration, thus no need to release the mouse after using it in the guest and one can also enable a bidirectional clipboard.
+
VBOX_USB=usbfs
 +
}}
  
{{Note | The instructions immediately below are for an Archlinux guest on an Archlinux host.}}
+
Then make sure, the environment has been made aware of this change (reconnect, source the file manually, launch a new shell instance or reboot).
  
After you booted the virtual machine, go to menu ''Devices &rarr; Install Guest Additions...''  Once you have clicked it, VirtualBox loads an ISO into the current CD-ROM, so you will not see anything happen yet.
+
Also make sure that your user is a member of the {{ic|storage}} group.
  
You will require gcc and make if you do not already have them so install them typing the following as root:
+
=== USB modem not working on host ===
# pacman -S gcc make
 
  
If you are running arch in VirtualBox install the kernel headers
+
If you have a USB modem which is being used by the guest OS, killing the guest OS can cause the modem to become unusable by the host system. Killing and restarting {{ic|VBoxSVC}} should fix this problem.
# pacman -S kernel26-headers
 
  
Then do the following as root:
+
=== Access serial port from guest ===
# mount /media/cdrom
 
for i686 systems (32 bit):
 
# sh /media/cdrom/VBoxLinuxAdditions-x86.run
 
for x86-64 systems (64 bit):
 
# sh /media/cdrom/VBoxLinuxAdditions-amd64.run
 
  
It will build and install the kernel modules, install the Xorg drivers and create init scripts. It will most probably print out errors about init scripts and run levels and what not. Ignore them. You will find {{Filename|rc.vboxadd}} in /etc/rc.d which will load them on demand. To have the Guest Additions loaded at boot time, just add those to the DAEMONS array in {{Filename|/etc/rc.conf}} eg.:
+
Check you permission for the serial port:
  DAEMONS=(syslog-ng network netfs crond alsa '''rc.vboxadd''')
+
{{hc|$ ls -l /dev/ttyS*|
 +
crw-rw---- 1 root uucp 4, 64 Feb  3 09:12 /dev/ttyS0
 +
crw-rw---- 1 root uucp 4, 65 Feb  3 09:12 /dev/ttyS1
 +
crw-rw---- 1 root uucp 4, 66 Feb 3 09:12 /dev/ttyS2
 +
crw-rw---- 1 root uucp 4, 67 Feb  3 09:12 /dev/ttyS3
 +
}}
  
Another option is to install one of these packages:
+
Add your user to the {{ic|uucp}} [[group]].
# pacman -S virtualbox-additions
 
or
 
# pacman -S virtualbox-ose-additions
 
  
You will then have an ISO to mount as a loop device. Remember to load the loop kernel module before:
+
=== Guest freezes after starting Xorg ===
# modprobe loop
 
# mount /usr/lib/virtualbox/additions/VBoxGuestAdditions.iso /media/cdrom -o loop
 
  
Then execute {{Filename|VBoxLinuxAdditions.run}} as before. Before adding {{Filename|rc.vboxadd}} to DAEMONS check {{Filename|/etc/rc.local}} for commands to load the vboxadd daemons put by the installation script.
+
Faulty or missing drivers may cause the guest to freeze after starting Xorg, see for example [https://bbs.archlinux.org/viewtopic.php?pid=1167838] and [https://bbs.archlinux.org/viewtopic.php?id=156079]. Try disabling 3D acceleration in ''Settings > Display'', and check if all [[Xorg]] drivers are installed.
  
'''Using full resolution of the host system in the guest'''
+
=== Fullscreen mode shows blank screen ===
  
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.
+
On some window managers ([[i3]], [[awesome]]), VirtualBox has issues with fullscreen mode properly due to the overlay bar. To work around this issue, disable "Show in Full-screen/Seamless" option in "Guest Settings > User Interface > Mini ToolBar"See the [https://www.virtualbox.org/ticket/14323 upstream bug report] for more information.
For a resolution of 1280x1024, this would e.g. look like
 
  # kernel /vmlinuz26 root=/dev/disk/by-uuid/7bdc5dee-8fb0-4260-bc43-60ac6e4e4a54 ro vga=795
 
Add the resolution to {{Filename|/etc/X11/xorg.conf}}, e.g.
 
  
# Section "Screen"
+
=== Host freezes on virtual machine start ===
# ...
 
# SubSection "Display"
 
# Viewport  0 0
 
# Depth    24
 
# Modes "1280x1024" "1024x768"
 
# EndSubSection
 
# ...
 
# EndSection
 
  
 +
{{Expansion|Needs a link to a bug report.}}
  
'''Windows Guests'''
+
Possible causes/solutions:
  
After installing Windows (XP etc.) on your virtual machine, simply select ''Devices &rarr; Install Guest Additions...''
+
* SMAP
 +
This is a known incompatiblity with SMAP enabled kernels affecting (mostly) Intel Broadwell chipsets. A solution to this problem is disabling SMAP support in your kernel by appending the {{ic|nosmap}} option to your [[kernel parameters]].
 +
* Hardware Virtualisation
 +
Disabling hardware virtualisation (VT-x/AMD-V) may solve the problem.
 +
* Various Kernel bugs
 +
** Fuse mounted partitions (like ntfs) [https://bbs.archlinux.org/viewtopic.php?id=185841], [https://bugzilla.kernel.org/show_bug.cgi?id=82951#c12]
  
This will mount the iso image and windows should then automatically launch the guest additions installer. Follow the instructions to the end.
+
Generally, such issues are observed after upgrading VirtualBox or linux kernel. Downgrading them to the previous versions of theirs might solve the problem.
  
===Sharing folders between the host and the guest===
+
=== Linux guests have slow/distorted audio ===
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.
+
The AC97 audio driver within the Linux kernel occasionally guesses the wrong clock settings when running inside Virtual Box, leading to audio that is either too slow or too fast. To fix this, create a file in {{ic|/etc/modprobe.d/}} with the following line:
In a Linux host, ''Devices &rarr; Install Guest Additions''
 
Yes (when asked to download the CD image)
 
Mount (when asked to register and mount)
 
  
In a Linux host, create one folder for sharing files.
+
options snd-intel8x0 ac97_clock=48000
  
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 &rarr; Entire Network &rarr; VirtualBox Shared Folders''.
+
=== Analog microphone not working ===
  
Alternatively, on the Windows command line, you can also use the following:
+
If the audio input from an analog microphone is working correctly on the host, but no sound seems to get through to the guest, despite the microphone device apparently being detected normally, installing a [[Sound system#Sound servers|sound server]] such as [[PulseAudio]] on the host might fix the problem.
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.
+
If after installing [[PulseAudio]] the microphone still refuses to work, setting ''Host Audio Driver'' (under ''VirtualBox > Machine > Settings > Audio'') to ''ALSA Audio Driver'' might help.
  
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:
+
=== Microphone not working after upgrade ===
127.0.0.1 localhost vboxsvr
 
  
In a Linux guest, use the following command:
+
There have been issues reported around sound input in 5.1.x versions. [https://forums.virtualbox.org/viewtopic.php?f=7&t=78797]
# mount -t vboxsf [-o OPTIONS] sharename mountpoint
 
  
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.
+
[[Downgrading]] may solve the problem. You can use {{aur|virtualbox-bin-5.0}} to ease downgrading.
  
Beyond the standard options supplied by the mount command, the following are available:
+
=== Problems with images converted to ISO ===
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).
 
  
===Getting audio to work in the guest machine===
+
Some image formats cannot be reliably converted to ISO. For instance, {{Pkg|ccd2iso}} ignores .ccd and .sub files, which can result in disk images with broken files.
  
In the machine settings, go to the audio tab and select the correct driver according to your sound system (ALSA, OSS or PulseAudio).
+
In this case, you will either have to use [[CDemu]] for Linux inside VirtualBox or any other utility used to mount disk images.
  
===Setting up the RAM and Video Memory for the virtual PC===
+
=== Failed to create the host-only network interface ===
  
You can change the default values by going to ''Settings &rarr; General''.
+
Make sure all required kernel modules are loaded. See [[#Load the VirtualBox kernel modules]].
  
===Setting up CD-ROM for the Virtual PC===
+
=== Failed to insert module ===
  
You can change the default values by going to ''Settings &rarr; CD/DVD-ROM''.
+
When you get the following error when trying to load modules:
  
Check mount CD/DVD drive and select one of the following options.
+
Failed to insert 'vboxdrv': Required key not available
  
'''Note:''' If no CD-ROM drive is detected, make sure the HAL daemon is running.  To start it, run the following command as root:
+
[[#Sign modules|Sign]] your modules or disable {{ic|CONFIG_MODULE_SIG_FORCE}} in your kernel config.
# /etc/rc.d/hal start
 
  
===Enabling OpenGL acceleration in Arch Linux guests===
+
=== VBOX_E_INVALID_OBJECT_STATE (0x80BB0007) ===
Due to a bug in the VirtualBox guest addition setup scripts (as of VBox 3.1.2), simply ticking the "3D acceleration" checkbox in the virtual machine settings and installing the guest additions won't enable 3D acceleration for OpenGL applications under X for Arch Linux guests (and possibly others). In order to still get OpenGL acceleration, a bit of manual intervention is necessary after installing the guest additions.
 
As root, run:
 
ln -s /usr/lib/VBoxOGL.so /usr/lib/xorg/modules/dri/vboxvideo_dri.so
 
ln -s /usr/lib/xorg/modules/dri /usr/lib/dri
 
Also make sure the user starting X in the guest is in the '''video''' group.
 
  
{{Note | Don't compare before-after performance using glxgears! You may get a lot less FPS due to now-working vsync support. Compare performance using a real, heavy 3D application (like a game).}}
+
This can occur if a VM is exited ungracefully. Run the following command:
  
===Enabling D3D acceleration in Windows guests===
+
  $ VBoxManage controlvm ''virtual_machine_name'' poweroff
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.
+
=== NS_ERROR_FAILURE and missing menu items ===
  
{{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.}}
+
This happens sometimes when selecting ''QCOW''/''QCOW2''/''QED'' disk format when creating a new virtual disk.
{{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.}}
 
  
==Start VirtualBox==
+
If you encounter this message the first time you start the virtual machine:
To start Virtualbox, run the following command in a terminal:
 
$ VirtualBox
 
  
Or in KDE menu, select: <System><Sun Virtualbox>
+
{{bc|Failed to open a session for the virtual machine debian.
 +
Could not open the medium '/home/.../VirtualBox VMs/debian/debian.qcow'.
 +
QCow: Reading the L1 table for image '/home/.../VirtualBox VMs/debian/debian.qcow' failed (VERR_EOF).
 +
VD: error VERR_EOF opening image file '/home/.../VirtualBox VMs/debian/debian.qcow' (VERR_EOF).
  
==Virtualized OS Setup==
+
Result Code:
Virtualbox needs to be setup to virtualize another operating system.
+
NS_ERROR_FAILURE (0x80004005)
 +
Component:
 +
Medium
 +
}}
  
===Test a LiveCD/DVD===
+
Exit VirtualBox, delete all files of the new machine and from virtualbox config file remove the last line in {{ic|MachineRegistry}} menu (or the offending machine you are creating):
Click the 'New' button to create a new virtual environment.  Name it appropriately and select Operating System type and version.  Select base memory size (note: most operating systems will need at least 512MB to function properly).  Create a new hard disk image (a hard disk image is a file that will contain the operating system's filesystem and files).
 
  
When the new image has been created, click 'Settings', then CD/DVD-ROM, check 'Mount CD/DVD Drive' then select an ISO image.
+
{{hc|~/.config/VirtualBox/VirtualBox.xml|2=
 +
...
 +
<MachineRegistry>
 +
  <MachineEntry uuid="{00000000-0000-0000-0000-000000000000}" src="/home/void/VirtualBox VMs/debian/debian.vbox"/>
 +
  <MachineEntry uuid="{00000000-0000-0000-0000-000000000000}" src="/home/void/VirtualBox VMs/ubuntu/ubuntu.vbox"/>
 +
  <strike><MachineEntry uuid="{00000000-0000-0000-0000-000000000000}" src="/home/void/VirtualBox VMs/lastvmcausingproblems/lastvmcausingproblems.qcow"/></strike>
 +
</MachineRegistry>
 +
...
 +
}}
  
==Maintenance==
+
=== Arch: pacstrap script fails ===
  
===Rebuild the vboxdrv Module===
+
If you used ''pacstrap'' in the [[#Installation steps for Arch Linux guests]] to also [[#Install the Guest Additions]] '''before''' performing a first boot into the new guest, you will need to {{ic|umount -l /mnt/dev}} as root before using ''pacstrap'' again; a failure to do this will render it unusable.
Note that any time your kernel version changes (due to an upgrade, recompile, etc.) you must also rebuild the VirtualBox kernel modules.
 
  
Ensure that ''kernel26-headers'' is still installed, and run the following command:
+
=== OpenBSD unusable when virtualisation instructions unavailable ===
# /etc/rc.d/vboxdrv setup
 
This will build the VirtualBox kernel modules for the ''currently running kernel''; if you have just upgraded your kernel package, reboot before trying to rebuild your kernel modules.
 
  
After rebuilding the module, do not forget to load it with
+
While OpenBSD is reported to work fine on other hypervisors without virtualisation instructions (VT-x AMD-V) enabled, an OpenBSD virtual machine running on VirtualBox without these instructions will be unusable,  manifesting with a bunch of segmentation faults. Starting VirtualBox with the ''-norawr0'' argument [https://www.virtualbox.org/ticket/3947 may solve the problem]. You can do it like this:
  # modprobe vboxdrv
+
  $ VBoxSDL -norawr0 -vm ''name_of_OpenBSD_VM''
  
''vboxdrv'' and ''vboxnetflt'' should be in the MODULES=() section of your /etc/rc.conf
+
=== Windows host: VERR_ACCESS_DENIED ===
  
If you are using an old virtualbox_bin package built from AUR, run the following command to rebuild your kernel modules:
+
To access the raw VMDK image on a Windows host, run the VirtualBox GUI as administrator.
# vbox_build_module
 
In the current virtualbox_bin PKGBUILD, this command has been replaced with the vboxdrv script specified above.
 
  
===Compact a Disk Image===
+
=== Windows: "The specified path does not exist. Check the path and then try again." ===
See [http://my.opera.com/locksley90/blog/2008/06/01/how-to-compact-a-virtualbox-virtual-disk-image-vdi How to compact a VirtualBox virtual disk image (VDI)]
 
  
===Windows Xp and Nokia phones===
+
This error message may appear when running an {{ic|.exe}} file which requires administrator privileges from a shared folder in windows guests. [https://www.virtualbox.org/ticket/5732#comment:39]
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}}:
+
As a workaround, copy the file to the virtual drive or use [[w:Uniform Naming Convention|UNC paths]] ({{ic|\\vboxsvr}}). See [https://support.microsoft.com/de-de/help/2019185/copying-files-from-a-mapped-drive-to-a-local-directory-fails-with-erro] for more information.
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
+
=== Windows 8.x error code 0x000000C4===
$ sudo groupadd usbfs
 
$ sudo usermod -a -G usbfs $USER
 
  
After a logout, connect a Nokia phone with PC Suite mode and start Windows XP to test new rule.
+
If you get this error code while booting, even if you choose OS Type Win 8, try to enable the {{ic|CMPXCHG16B}} CPU instruction:
  
==Migrating From Another VM==
+
$ vboxmanage setextradata ''virtual_machine_name'' VBoxInternal/CPUM/CMPXCHG16B 1
The <code>qemu-img</code> program can be used to convert images from one format to another, or add compression or encryption to an image.
 
  # pacman -S qemu
 
  
===Converting from QEMU images===
+
=== Windows 8, 8.1 or 10 fails to install, boot or has error "ERR_DISK_FULL" ===
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.
 
  $ qemu-img convert -O raw test.qcow2 test.raw
 
  $ VBoxManage modifyvdi /full/path/to/test.vdi compact
 
  
===Converting from VMware images ===
+
Update the VM's settings by going to ''Settings > Storage > Controller:SATA'' and check "Use Host I/O Cache".
Do
 
  $ VBoxManage clonehd source.vmdk target.vdi --format VDI
 
  
This may not be needed anymore with recent virtualbox versions (to be confirmed)
+
=== WinXP: Bit-depth cannot be greater than 16 ===
  
==Tips and Tricks==
+
If you are running at 16-bit color depth, then the icons may appear fuzzy/choppy. However, upon attempting to change the color depth to a higher level, the system may restrict you to a lower resolution or simply not enable you to change the depth at all. To fix this, run {{ic|regedit}} in Windows and add the following key to the Windows XP VM's registry:
  
===Sending a CTRL+ALT+F1 to the Guest===
+
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services]
If your guest O/S is a Linux distro, and you want to open a new tty text shell or exit X via typing {{Keypress|Ctrl}}+{{Keypress|Alt}}+{{Keypress|F1}}, you can easily send this command to the guest O/S simply by hitting your 'Host Key' (usually the {{Keypress|Ctrl}} in the Right side of your keyboard) + {{Keypress|F1}} or {{Keypress|F2}}, etc.
+
"ColorDepth"=dword:00000004
  
===Speeding up HDD Access for the Guest===
+
Then update the color depth in the "desktop properties" window. If nothing happens, force the screen to redraw through some method (i.e. {{ic|Host+f}} to redraw/enter full screen).
Enabling the SATA(AHCI) controller within Virtualbox can speed up Host disk operations.  This is available though Settings>Hard Disks in current versions of Virtual Box.
 
  
===Starting VMs at System Boot on Headless Servers===
+
=== Windows: Screen flicker if 3D acceleration enabled ===
Add this line to /etc/rc.local
 
exec /bin/su PREFERRED_USER -l -c "/bin/bash --login -c \"VBoxHeadless -startvm {UUID}\" >/dev/null 2>&1" &
 
Where PREFERRED_USER is the user profile that contains the VM definitions and .vdi files. This will start the VM with a RDP server running on port 3389.
 
To determine the available VMs for a user:
 
su PREFERRED_USER -c "VBoxManage list vms"
 
To suspend the VM:
 
su PREFERRED_USER -c "VBoxManage controlvm {UUID} savestate"
 
  
===Accessing Server on VM from Host===
+
VirtualBox > 4.3.14 has a regression in which Windows guests with 3D acceleration flicker. Since r120678 a patch has been implemented to recognize an [[environment variable]] setting, launch VirtualBox like this:
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"
+
$ CR_RENDER_FORCE_PRESENT_MAIN_THREAD=0 VirtualBox
  
*from [http://mydebian.blogdns.org/?p=111 ]
+
Make sure no VirtualBox services are still running. See [https://www.virtualbox.org/ticket/13653 VirtualBox bug 13653].
  
It might also be necessary to allow connections from the outside to the server in your VM. E.g. if the guest OS is Arch, you may want to add the line
+
=== Cannot mount shared folder from fstab ===
httpd: ALL
 
to your /etc/hosts.allow file.
 
  
===Daemon Tools===
+
The {{ic|/usr/bin/mount.vboxsf}} binary shipped in {{Pkg|virtualbox-guest-utils}} cannot be used with kernels 4.16 or newer.
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.
 
  
Recent Daemon Tools versions won't install, so use this old one: [http://www.disc-tools.com/download/daemon347+hashcalc]
+
The existence of {{ic|/usr/bin/mount.vboxsf}} will prevent mounting shared folders from [[#Mount at boot|fstab]]. A workaround is to declare {{ic|usr/bin/mount.vboxsf}} as [[pacman#Skip files from being installed to system|NoExtract]] in {{ic|/etc/pacman.conf}}. See {{Bug|58272}} for more information.
  
==Running Arch Linux as a guest==
+
== See also ==
To install guest additions with support for Xorg follow these steps:
 
{{Note|Run the following steps as root}}
 
* install entire xorg group: (is everything actually required?) <pre># pacman -S xorg</pre>
 
* install dependencies needed to build the guest additions: <pre># pacman -S kernel26-headers gcc make</pre>
 
* mount and install VirtualBox guest additions
 
* create <tt>/etc/X11/xorg.conf</tt> with the following contents:
 
Section "InputDevice"
 
        Identifier  "Mouse0"
 
        Driver      "vboxmouse"
 
        Option      "Device" "/dev/vboxguest"
 
        Option      "CorePointer" "yes"
 
EndSection
 
 
Section "Device"
 
        Identifier  "Card0"
 
        Driver      "vboxvideo"
 
EndSection
 
* add <tt>hal</tt> to <tt>DAEMONS</tt> in <tt>rc.conf</tt> (not needed if you use X.org Server >= 1.8)
 
{{Note|It is not required to add rc.vboxadd to DAEMONS because it is added to /etc/rc.local automatically}}
 
{{Note|Run the following steps while logged into your user account}}
 
* add <tt>/usr/bin/VBoxClient-all &</tt> to the top of <tt>~/.xinitrc</tt> (even if <tt>~/.xinitrc</tt> does not exist)
 
  
==External Links==
+
* [https://www.virtualbox.org/manual/UserManual.html VirtualBox User Manual]
* [http://www.virtualbox.org/manual/UserManual.html VirtualBox User Manual]
+
* [[Wikipedia:VirtualBox]]

Latest revision as of 01:16, 19 May 2018

VirtualBox is a hypervisor used to run operating systems in a special environment, called a virtual machine, on top of the existing operating system. VirtualBox is in constant development and new features are implemented continuously. It comes with a Qt GUI interface, as well as headless and SDL command-line tools for managing and running virtual machines.

In order to integrate functions of the host system to the guests, including shared folders and clipboard, video acceleration and a seamless window integration mode, guest additions are provided for some guest operating systems.

Contents

Installation steps for Arch Linux hosts

In order to launch VirtualBox virtual machines on your Arch Linux box, follow these installation steps.

Install the core packages

Install the virtualbox package. You will need to choose a package to provide host modules:

Sign modules

When using a custom kernel with CONFIG_MODULE_SIG_FORCE option enabled, you must sign your modules with a key generated during kernel compilation.

Navigate to your kernel tree folder and execute the following command:

# for module in `ls /lib/modules/$(uname -r)/kernel/misc/{vboxdrv.ko,vboxnetadp.ko,vboxnetflt.ko,vboxpci.ko}` ; do ./scripts/sign-file sha1 certs/signing_key.pem certs/signing_key.x509 $module ; done
Note: Hashing algorithm does not have to match the one configured, but it must be built into the kernel.

Load the VirtualBox kernel modules

virtualbox-host-modules-arch and virtualbox-host-dkms use systemd-modules-load.service to load all four VirtualBox modules automatically at boot time. For the modules to be loaded after installation, either reboot or load the modules once manually.

Note: If you do not want the VirtualBox modules to be automatically loaded at boot time, you have to mask the default /usr/lib/modules-load.d/virtualbox-host-modules-arch.conf (or /usr/lib/modules-load.d/virtualbox-host-dkms.conf) by creating an empty file (or symlink to /dev/null) with the same name in /etc/modules-load.d/.

Among the kernel modules VirtualBox uses, there is a mandatory module named vboxdrv, which must be loaded before any virtual machines can run.

To load the module manually, run:

# modprobe vboxdrv

The following modules are optional but are recommended if you do not want to be bothered in some advanced configurations (precised here after): vboxnetadp, vboxnetflt and vboxpci.

  • vboxnetadp and vboxnetflt are both needed when you intend to use the bridged or host-only networking feature. More precisely, vboxnetadp is needed to create the host interface in the VirtualBox global preferences, and vboxnetflt is needed to launch a virtual machine using that network interface.
  • vboxpci is needed when your virtual machine needs to pass through a PCI device on your host.
Note: If the VirtualBox kernel modules were loaded in the kernel while you updated the modules, you need to reload them manually to use the new updated version. To do it, run vboxreload as root.

Accessing host USB devices in guest

To use the USB ports of your host machine in your virtual machines, add users that will be authorized to use this feature to the vboxusers group.

Guest additions disc

It is also recommended to install the virtualbox-guest-iso package on the host running VirtualBox. This package will act as a disc image that can be used to install the guest additions onto guest systems other than Arch Linux. The .iso file will be located at /usr/lib/virtualbox/additions/VBoxGuestAdditions.iso, and may have to be mounted manually inside the virtual machine. Once mounted, you can run the guest additions installer inside the guest.

Extension pack

The Oracle Extension Pack provides additional features and is released under a non-free license only available for personal use. To install it, the virtualbox-ext-oracleAUR package is available, and a prebuilt version can be found in the seblu repository.

If you prefer to use the traditional and manual way: download the extension manually and install it via the GUI (File > Preferences > Extensions) or via VBoxManage extpack install <.vbox-extpack>, make sure you have a toolkit like Polkit to grant privileged access to VirtualBox. The installation of this extension requires root access.

Front-ends

VirtualBox comes with three front-ends:

  • If you want to use VirtualBox with the regular GUI, use VirtualBox.
  • If you want to launch and manage your virtual machines from the command-line, use the VBoxSDL command, which only provides a plain window for the virtual machine without any overlays.
  • If you want to use VirtualBox without running any GUI (e.g. on a server), use the VBoxHeadless command. With the VRDP extension you can still remotely access the displays of your virtual machines.

Finally, you can also use phpVirtualBox to administrate your virtual machines via a web interface.

Refer to the VirtualBox manual to learn how to create virtual machines.

Warning: If you intend to store virtual disk images on a Btrfs file system, before creating any images, you should consider disabling copy-on-write for the destination directory of these images.

Installation steps for Arch Linux guests

Boot the Arch installation media through one of the virtual machine's virtual drives. Then, complete the installation of a basic Arch system as explained in the Installation guide.

Installation in EFI mode

If you want to install Arch Linux in EFI mode inside VirtualBox, in the settings of the virtual machine, choose System item from the panel on the left and Motherboard tab from the right panel, and check the checkbox Enable EFI (special OSes only). After selecting the kernel from the Arch Linux installation media's menu, the media will hang for a minute or two and will continue to boot the kernel normally afterwards. Be patient.

Once the system and the boot loader are installed, VirtualBox will first attempt to run /EFI/BOOT/BOOTX64.EFI from the ESP. If that first option fails, VirtualBox will then try the EFI shell script startup.nsh from the root of the ESP. This means that in order to boot the system you have the following options:

  • Launch the bootloader manually from the EFI shell every time;
  • Move the bootloader to the default /EFI/BOOT/BOOTX64.EFI path;
  • Create a script named startup.nsh at the ESP root containing the path to the boot loader application, e.g. \EFI\grub\grubx64.efi.
  • Boot directly from the ESP partition using a startup.nsh script.

Do not bother with the VirtualBox Boot Manager (accessible with F2 at boot), as it is buggy and incomplete. It does not store efivars set interactively. Therefore, EFI entries added to it manually in the firmware (accessed with F12 at boot time) or with efibootmgr will persist after a reboot but are lost when the VM is shut down.

See also UEFI VirtualBox installation boot problems.

Install the Guest Additions

VirtualBox Guest Additions provides drivers and applications that optimize the guest operating system including improved image resolution and better control of the mouse. Within the installed guest system, install:

Both packages will make you choose a package to provide guest modules:

To compile the virtualbox modules provided by virtualbox-guest-dkms, it will also be necessary to install the appropriate headers package(s) for your installed kernel(s) (e.g. linux-lts-headers for linux-lts). [2] When either VirtualBox or the kernel is updated, the kernel modules will be automatically recompiled thanks to the DKMS Pacman hook.

Note:
  • You can alternatively install the Guest Additions with the ISO from the virtualbox-guest-iso package, provided you installed this on the host system. To do this, go to the device menu click Insert Guest Additions CD Image.
  • To recompile the vbox kernel modules, run rcvboxdrv as root.

The guest additions running on your guest, and the VirtualBox application running on your host must have matching versions, otherwise the guest additions (like shared clipboard) may stop working. If you upgrade your guest (e.g. pacman -Syu), make sure your VirtualBox application on this host is also the latest version. "Check for updates" in the VirtualBox GUI is sometimes not sufficient; check the VirtualBox.org website.

Set optimal framebuffer resolution

Tango-go-next.pngThis article or section is a candidate for moving to VirtualBox/Tips and tricks.Tango-go-next.png

Notes: please use the second argument of the template to provide more detailed indications. (Discuss in Talk:VirtualBox#)

Typically after installing Guest Additions, a fullscreen Arch guest running X will be set to the optimal resolution for your display; however, the virtual console's framebuffer will be set to a standard, often smaller, resolution detected from VirtualBox's custom VESA driver.

To use the virtual consoles at optimal resolution, Arch needs to recognize that resolution as valid, which in turn requires VirtualBox to pass this information along to the guest OS.

First, check if your desired resolution is not already recognized by running the command:

hwinfo --framebuffer

If the optimal resolution does not show up, then you will need to run the VBoxManage tool on the host machine and add "extra resolutions" to your virtual machine (on a Windows host, go to the VirtualBox installation directory to find VBoxManage.exe). For example:

$ VBoxManage setextradata "Arch Linux" "CustomVideoMode1" "1360x768x24"

The parameters "Arch Linux" and "1360x768x24" in the example above should be replaced with your VM name and the desired framebuffer resolution. Incidentally, this command allows for defining up to 16 extra resolutions ("CustomVideoMode1" through "CustomVideoMode16").

Afterwards, restart the virtual machine and run hwinfo --framebuffer once more to verify that the new resolutions have been recognized by your guest system (which does not guarantee they will all work, depending on your hardware limitations).

Note: As of VirtualBox 5.2, hwinfo --framebuffer might not show any output, but you should still be able to set a custom resolution following this procedure.

Finally, add a video=resolution kernel parameter to set the framebuffer to the new resolution, for example:

video=1360x768

Additionally you may want to configure your bootloader to use the same resolution. If you use GRUB, see GRUB/Tips and tricks#Setting the framebuffer resolution.

Note: Neither the kernel parameter vga nor the bootloader's resolution settings (e.g. GRUB's GRUB_GFXPAYLOAD_LINUX) will fix the framebuffer, since they are overriden by virtue of Kernel Mode Setting. The framebuffer resolution must be set by the kernel parameter video as described above.

Load the VirtualBox kernel modules

To load the modules automatically, enable vboxservice.service which loads the modules and synchronizes the guest's system time with the host.

To load the modules manually, type:

# modprobe -a vboxguest vboxsf vboxvideo

virtualbox-guest-dkms uses systemd-modules-load.service to load its modules at boot time.

Note: If you do not want the VirtualBox modules to be loaded at boot time, you have to mask the default /usr/lib/modules-load.d/virtualbox-guest-dkms.conf by creating an empty file (or symlink to /dev/null) with the same name in /etc/modules-load.d/.

Launch the VirtualBox guest services

After the rather big installation step dealing with VirtualBox kernel modules, now you need to start the guest services. The guest services are actually just a binary executable called VBoxClient which will interact with your X Window System. VBoxClient manages the following features:

  • shared clipboard and drag and drop between the host and the guest;
  • seamless window mode;
  • the guest display is automatically resized according to the size of the guest window;
  • checking the VirtualBox host version

All of these features can be enabled independently with their dedicated flags:

$ VBoxClient --clipboard --draganddrop --seamless --display --checkhostversion

As a shortcut, the VBoxClient-all bash script enables all of these features.

virtualbox-guest-utils installs /etc/xdg/autostart/vboxclient.desktop that launches VBoxClient-all on logon. If your desktop environment or window manager does not support XDG Autostart, you will need to set up autostarting yourself, see Autostarting#On desktop environment startup and Autostarting#On window manager startup for more details.

VirtualBox can also synchronize the time between the host and the guest, to do this, start/enable the vboxservice.service.

Now, you should have a working Arch Linux guest. Note that features like clipboard sharing are disabled by default in VirtualBox, and you will need to turn them on in the per-VM settings if you actually want to use them (e.g. Settings > General > Advanced > Shared Clipboard).

Hardware acceleration

Hardware acceleration can be activated in the VirtualBox options. The GDM display manager 3.16+ is known to break hardware acceleration support. [3] So if you get issues with hardware acceleration, try out another display manager (lightdm seems to work fine). [4] [5]

Enable shared folders

Shared folders are managed on the host, in the settings of the Virtual Machine accessible via the GUI of VirtualBox, in the Shared Folders tab. There, Folder Path, the name of the mount point identified by Folder name, and options like Read-only, Auto-mount and Make permanent can be specified. These parameters can be defined with the VBoxManage command line utility. See there for more details.

No matter which method you will use to mount your folder, all methods require some steps first.

To avoid this issue /sbin/mount.vboxsf: mounting failed with the error: No such device, make sure the vboxsf kernel module is properly loaded. It should be, since we enabled all guest kernel modules previously.

Two additional steps are needed in order for the mount point to be accessible from users other than root:

Manual mounting

Use the following command to mount your folder in your Arch Linux guest:

# mount -cit vboxsf shared_folder_name mount_point_on_guest_system

The vboxsf filesystem offers other options which can be displayed with this command:

# mount.vboxsf

For example if the user was not in the vboxsf group, we could have used this command to give access our mountpoint to him:

# mount -cit vboxsf -o uid=1000,gid=1000 home /mnt

Where uid and gid are values corresponding to the users we want to give access to. These values are obtained from the id command run against this user.

Automounting

Note: Automounting requires the vboxservice.service to be enabled/started.

In order for the automounting feature to work you must have checked the auto-mount checkbox in the GUI or used the optional --automount argument with the command VBoxManage sharedfolder.

The shared folder should now appear in /media/sf_shared_folder_name. If users in media cannot access the shared folders, check that media has permissions 755 or has group ownership vboxsf if using permission 750. This is currently not the default if media is created by installing virtualbox-guest-utils.

You can use symlinks if you want to have a more convenient access and avoid to browse in that directory, e.g.:

$ ln -s /media/sf_shared_folder_name ~/my_documents

Mount at boot

Note: mount.vboxsf will not mount shared folders from /etc/fstab on kernels 4.16 or newer. See #Cannot mount shared folder from fstab for a workaround.

You can mount your directory with fstab. However, to prevent startup problems with systemd, noauto,x-systemd.automount should be added to /etc/fstab. This way, the shared folders are mounted only when those mount points are accessed and not during startup. This can avoid some problems, especially if the guest additions are not loaded yet when systemd reads fstab and mounts the partitions.

sharedFolderName  /path/to/mntPtOnGuestMachine  vboxsf  uid=user,gid=group,rw,dmode=700,fmode=600,noauto,x-systemd.automount 
  • sharedFolderName: the value from the VirtualMachine's Settings > SharedFolders > Edit > FolderName menu. This value can be different from the name of the real folder name on the host machine. To see the VirtualMachine's Settings go to the host OS VirtualBox application, select the corresponding virtual machine and click on Settings.
  • /path/to/mntPtOnGuestMachine: if not existing, this directory should be created manually (for example by using mkdir)
  • dmode/fmode are directory/file permissions for directories/files inside /path/to/mntPtOnGuestMachine.

As of 2012-08-02, mount.vboxsf does not support the nofail option:

desktop  /media/desktop  vboxsf  uid=user,gid=group,rw,dmode=700,fmode=600,nofail  0  0

SSH from host to guest

The network tab of the virtual machine settings contains, in "Advanced", a tool to create port forwarding. It is possible to use it to forward the Guest ssh port 22 to a Host port, e.g. 3022 :

user@host$ ssh -p 3022 $USER@localhost

will establish a connection from Host to Guest.

SSHFS as alternative to the shared folder

Using this port forwarding and sshfs, it is straightforward to mount the Guest filesystem onto the Host one:

user@host$ sshfs -p 3022 $USER@localhost:$HOME ~/shared_folder

and then transfer files between both.

Virtual disks management

See also VirtualBox/Tips and tricks#Import/export VirtualBox virtual machines from/to other hypervisors.

Formats supported by VirtualBox

VirtualBox supports the following virtual disk formats:

  • VDI: The Virtual Disk Image is the VirtualBox own open container used by default when you create a virtual machine with VirtualBox.
  • VMDK: The Virtual Machine Disk has been initially developed by VMware for their products. The specification was initially closed source, but it became now an open format which is fully supported by VirtualBox. This format offers the ability to be split into several 2GB files. This feature is especially useful if you want to store the virtual machine on machines which do not support very large files. Other formats, excluding the HDD format from Parallels, do not provide such an equivalent feature.
  • VHD: The Virtual Hard Disk is the format used by Microsoft in Windows Virtual PC and Hyper-V. If you intend to use any of these Microsoft products, you will have to choose this format.
Tip: Since Windows 7, this format can be mounted directly without any additional application.
  • VHDX (read only): This is the eXtended version of the Virtual Hard Disk format developed by Microsoft, which has been released on 2012-09-04 with Hyper-V 3.0 coming with Windows Server 2012. This new version of the disk format does offer enhanced performance (better block alignment), larger blocks size, and journal support which brings power failure resiliency. VirtualBox should support this format in read only.
  • HDD (version 2): The HDD format is developed by Parallels Inc and used in their hypervisor solutions like Parallels Desktop for Mac. Newer versions of this format (i.e. 3 and 4) are not supported due to the lack of documentation for this proprietary format.
    Note: There is currently a controversy regarding the support of the version 2 of the format. While the official VirtualBox manual only reports the second version of the HDD file format as supported, Wikipedia's contributors are reporting the first version may work too. Help is welcome if you can perform some tests with the first version of the HDD format.
  • QED: The QEMU Enhanced Disk format is an old file format for QEMU, another free and open source hypervisor. This format was designed from 2010 in a way to provide a superior alternative to QCOW2 and others. This format features a fully asynchronous I/O path, strong data integrity, backing files, and sparse files. QED format is supported only for compatibility with virtual machines created with old versions of QEMU.
  • QCOW: The QEMU Copy On Write format is the current format for QEMU. The QCOW format does support zlib-based transparent compression and encryption (the latter is flawed and is not recommended). QCOW is available in two versions: QCOW and QCOW2. QCOW2 tends to supersede the first one. QCOW is currently fully supported by VirtualBox. QCOW2 comes in two revisions: QCOW2 0.10 and QCOW2 1.1 (which is the default when you create a virtual disk with QEMU). VirtualBox does not support QCOW2.
  • OVF: The Open Virtualization Format is an open format which has been designed for interoperability and distributions of virtual machines between different hypervisors. VirtualBox supports all revisions of this format via the VBoxManage import/export feature but with known limitations.

Disk image format conversion

VBoxManage clonehd can be used to convert between VDI, VMDK, VHD and RAW.

$ VBoxManage clonehd inputfile outputfile --format outputformat

For example to convert VDI to VMDK:

$ VBoxManage clonehd source.vdi destination.vmdk --format VMDK

QCOW

VirtualBox does not support QEMU's QCOW2 disk image format. To use a QCOW2 disk image with VirtualBox you therefore need to convert it, which you can do with qemu's qemu-img command. qemu-img can convert QCOW to / from VDI, VMDK, VHDX, RAW and various other formats (which you can see by running qemu-img --help).

$ qemu-img convert -O output_fmt inputfile outputfile

For example to convert QCOW2 to VDI:

$ qemu-img convert -O vdi source.qcow2 destination.vdi
Tip: The -p parameter is used to get the progression of the conversion task.

There are two revisions of QCOW2: 0.10 and 1.1. You can specify the revision to use with -o compat=revision.

Mount virtual disks

VDI

Mounting VDI images only works with fixed size images (a.k.a. static images); dynamic (dynamically size allocating) images are not easily mountable.

The offset of the partition (within the VDI) is needed, then add the value of offData to 32256 (e.g. 69632 + 32256 = 101888):

$ VBoxManage internalcommands dumphdinfo <storage.vdi> | grep "offData"

The can now be mounted with:

# mount -t ext4 -o rw,noatime,noexec,loop,offset=101888 <storage.vdi> /mntpoint/

You can also use mount.vdi script that, which you can use as (install script itself to /usr/bin/):

# mount -t vdi -o fstype=ext4,rw,noatime,noexec vdi_file_location /mnt/

Alternately you can use qemu's kernel module that can do this attrib:

# modprobe nbd max_part=16
# qemu-nbd -c /dev/nbd0 <storage.vdi>
# mount /dev/nbd0p1 /mnt/dir/
# # to unmount:
# umount /mnt/dir/
# qemu-nbd -d /dev/nbd0

If the partition nodes are not propagated try using partprobe /dev/nbd0; otherwise, a VDI partition can be mapped directly to a node by: qemu-nbd -P 1 -c /dev/nbd0 <storage.vdi>.

Compact virtual disks

Compacting virtual disks only works with .vdi files and basically consists of the following steps.

Boot your virtual machine and remove all bloat manually or by using cleaning tools like bleachbit which is available for Windows systems too.

Wiping free space with zeroes can be achieved with several tools:

  • If you were previously using Bleachbit, check the checkbox System > Free disk space in the GUI, or use bleachbit -c system.free_disk_space in CLI;
  • On UNIX-based systems, by using dd or preferably dcfldd (see here to learn the differences):
# dcfldd if=/dev/zero of=/fillfile bs=4M
When fillfile reaches the limit of the partition, you will get a message like 1280 blocks (5120Mb) written.dcfldd:: No space left on device. This means that all of the user-space and non-reserved blocks of the partition will be filled with zeros. Using this command as root is important to make sure all free blocks have been overwritten. Indeed, by default, when using partitions with ext filesystem, a specified percentage of filesystem blocks is reserved for the super-user (see the -m argument in the mkfs.ext4 man pages or use tune2fs -l to see how much space is reserved for root applications).
When the aforementioned process has completed, you can remove the file fillfile you created.
  • On Windows, there are two tools available:
  • sdelete from the Sysinternals Suite, type sdelete -s -z c:, where you need to reexecute the command for each drive you have in your virtual machine;
  • or, if you love scripts, there is a PowerShell solution, but which still needs to be repeated for all drives.
PS> ./Write-ZeroesToFreeSpace.ps1 -Root c:\ -PercentFree 0
Note: This script must be run in a PowerShell environment with administrator privileges. By default, scripts cannot be run, ensure the execution policy is at least on RemoteSigned and not on Restricted. This can be checked with Get-ExecutionPolicy and the required policy can be set with Set-ExecutionPolicy RemoteSigned.

Once the free disk space have been wiped, shut down your virtual machine.

The next time you boot your virtual machine, it is recommended to do a filesystem check.

  • On UNIX-based systems, you can use fsck manually;
  • On Windows systems, you can use:
  • either chkdsk c: /F where c: needs to be replaced by each disk you need to scan and fix errors;
  • or FsckDskAll from here which is basically the same software as chkdsk, but without the need to repeat the command for all drives;

Now, remove the zeros from the .vdi file with VBoxManage modifyhd:

$ VBoxManage modifyhd your_disk.vdi --compact
Note: If your virtual machine has snapshots, you need to apply the above command on each .vdi files you have.

Increase virtual disks

General procedure

If you are running out of space due to the small hard drive size you selected when you created your virtual machine, the solution adviced by the VirtualBox manual is to use VBoxManage modifyhd. However this command only works for VDI and VHD disks and only for the dynamically allocated variants. If you want to resize a fixed size virtual disk disk too, read on this trick which works either for a Windows or UNIX-like virtual machine.

First, create a new virtual disk next to the one you want to increase:

$ VBoxManage createhd -filename new.vdi --size 10000

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

Note: By default, this command uses the Standard (corresponding to dynamic allocated) file format variant and thus will not use the same file format variant as your source virtual disk. If your old.vdi has a fixed size and you want to keep this variant, add the parameter --variant Fixed.

Next, the old virtual disk needs to be cloned to the new one which this may take some time:

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

Detach the old hard drive and attach new one, replace all mandatory italic arguments by your own:

$ VBoxManage storageattach VM_name --storagectl SATA --port 0 --medium none
$ VBoxManage storageattach VM_name --storagectl SATA --port 0 --medium new.vdi --type hdd

To get the storage controller name and the port number, you can use the command VBoxManage showvminfo VM_name. Among the output you will get such a result (what you are looking for is in italic):

[...]
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SATA
Storage Controller Type (1):            IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  30
Storage Controller Port Count (1):      1
Storage Controller Bootable (1):        on
IDE (1, 0): Empty
SATA (0, 0): /home/wget/IT/Virtual_machines/GNU_Linux_distributions/ArchLinux_x64_EFI/Snapshots/{6bb17af7-e8a2-4bbf-baac-fbba05ebd704}.vdi (UUID: 6bb17af7-e8a2-4bbf-baac-fbba05ebd704)
[...]

Download GParted live image and mount it as a virtual CD/DVD disk file, boot your virtual machine, increase/move your partitions, umount GParted live and reboot.

Note: On GPT disks, increasing the size of the disk will result in the backup GPT header not being at the end of the device. GParted will ask to fix this, click on Fix both times. On MBR disks, you do not have such a problem as this partition table as no trailer at the end of the disk.

Finally, unregister the virtual disk from VirtualBox and remove the file:

$ VBoxManage closemedium disk old.vdi
$ rm old.vdi

Increasing the size of VDI disks

If your disk is a VDI one, run:

$ VBoxManage modifyhd your_virtual_disk.vdi --resize the_new_size

Then jump back to the Gparted step, to increase the size of the partition on the virtual disk.

Replace a virtual disk manually from the .vbox file

If you think that editing a simple XML file is more convenient than playing with the GUI or with VBoxManage and you want to replace (or add) a virtual disk to your virtual machine, in the .vbox configuration file corresponding to your virtual machine, simply replace the GUID, the file location and the format to your needs:

ArchLinux_vm.vbox
<HardDisk uuid="{670157e5-8bd4-4f7b-8b96-9ee412a712b5}" location="ArchLinux_vm.vdi" format="VDI" type="Normal"/>

then in the <AttachedDevice> sub-tag of <StorageController>, replace the GUID by the new one.

ArchLinux_vm.vbox
<AttachedDevice type="HardDisk" port="0" device="0">
  <Image uuid="{670157e5-8bd4-4f7b-8b96-9ee412a712b5}"/>
</AttachedDevice>
Note: If you do not know the GUID of the drive you want to add, you can use the VBoxManage showhdinfo file. If you previously used VBoxManage clonehd to copy/convert your virtual disk, this command should have outputted the GUID just after the copy/conversion completed. Using a random GUID does not work, as each UUID is stored inside each disk image.

Transfer between Linux host and other OS

The information about path to harddisks and the snapshots is stored between <HardDisks> .... </HardDisks> tags in the file with the .vbox extension. You can edit them manually or use this script where you will need change only the path or use defaults, assumed that .vbox is in the same directory with a virtual harddisk and the snapshots folder. It will print out new configuration to stdout.

#!/bin/bash
NewPath="${PWD}/"
Snapshots="Snapshots/"
Filename="$1"

 awk -v SetPath="$NewPath" -v SnapPath="$Snapshots" '{if(index($0,"<HardDisk uuid=") != 0){A=$3;split(A,B,"=");
L=B[2];
 gsub(/\"/,"",L);
  sub(/^.*\//,"",L);
  sub(/^.*\\/,"",L);
 if(index($3,"{") != 0){SnapS=SnapPath}else{SnapS=""};
  print $1" "$2" location="\"SetPath SnapS L"\" "$4" "$5}
else print $0}' "$Filename"
Note:
  • If you will prepare virtual machine for use in Windows host then in the path name end you should use backslash \ instead of / .
  • The script detects snapshots by looking for { in the file name.
  • To make it run on a new host you will need to add it first to the register by clicking on Machine -> Add... or use hotkeys Ctrl+A and then browse to .vbox file that contains configuration or use command line VBoxManage registervm filename.vbox

Clone a virtual disk and assigning a new UUID to it

UUIDs are widely used by VirtualBox. Each virtual machines and each virtual disk of a virtual machine must have a different UUID. When you launch a virtual machine in VirtualBox, VirtualBox will keep track of all UUIDs of your virtual machine instance. See the VBoxManage list to list the items registered with VirtualBox.

If you cloned a virtual disk manually by copying the virtual disk file, you will need to assign a new UUID to the cloned virtual drive if you want to use the disk in the same virtual machine or even in another (if that one has already been opened, and thus registered, with VirtualBox).

You can use this command to assign a new UUID to a virtual disk:

$ VBoxManage internalcommands sethduuid /path/to/disk.vdi
Tip: To avoid copying the virtual disk and assigning a new UUID to your file manually you can use VBoxManage clonehd.
Note: The commands above support all virtual disk formats supported by VirtualBox.

Tips and tricks

For advanced configuration, see VirtualBox/Tips and tricks.

Troubleshooting

Keyboard and mouse are locked into virtual machine

This means your virtual machine has captured the input of your keyboard and your mouse. Simply press the right Ctrl key and your input should control your host again.

To control transparently your virtual machine with your mouse going back and forth your host, without having to press any key, and thus have a seamless integration, install the guest additions inside the guest. Read from the #Install the Guest Additions step if you guest is Arch Linux, otherwise read the official VirtualBox help.

No 64-bit OS client options

When launching a VM client, and no 64-bit options are available, make sure your CPU virtualization capabilities (usually named VT-x) are enabled in the BIOS.

If you are using a Windows host, you may need to disable Hyper-V, as it prevents VirtualBox from using VT-x. [6]

VirtualBox GUI does not match host GTK theme

See Uniform look for Qt and GTK applications for information about theming Qt-based applications like VirtualBox.

Cannot send Ctrl+Alt+Fn to guest

Your guest operating system is a GNU/Linux distribution and you want to open a new TTY shell by hitting Ctrl+Alt+F2 or exit your current X session with Ctrl+Alt+Backspace. If you type these keyboard shortcuts without any adaptation, the guest will not receive any input and the host (if it is a GNU/Linux distribution too) will intercept these shortcut keys. To send Ctrl+Alt+F2 to the guest for example, simply hit your Host Key (usually the right Ctrl key) and press F2 simultaneously.

USB subsystem not working

Your user must be in the vboxusers group and you need to install the extension pack if you want USB 2 support. Then you will be able to enable USB 2 in the VM settings and add one or several filters for the devices you want to access from the guest OS.

If VBoxManage list usbhost does not show any USB devices even if run as root, make sure that there is no old udev rules (from VirtualBox 4.x) in /etc/udev/rules.d/. VirtualBox 5.0 installs udev rules to /usr/lib/udev/rules.d/. You can use command like pacman -Qo /usr/lib/udev/rules.d/60-vboxdrv.rules to determine if the udev rule file is outdated.

Sometimes, on old Linux hosts, the USB subsystem is not auto-detected resulting in an error Could not load the Host USB Proxy service: VERR_NOT_FOUND or in a not visible USB drive on the host, even when the user is in the vboxusers group. This problem is due to the fact that VirtualBox switched from usbfs to sysfs in version 3.0.8. If the host does not understand this change, you can revert to the old behaviour by defining the following environment variable in any file that is sourced by your shell (e.g. your ~/.bashrc if you are using bash):

~/.bashrc
VBOX_USB=usbfs

Then make sure, the environment has been made aware of this change (reconnect, source the file manually, launch a new shell instance or reboot).

Also make sure that your user is a member of the storage group.

USB modem not working on host

If you have a USB modem which is being used by the guest OS, killing the guest OS can cause the modem to become unusable by the host system. Killing and restarting VBoxSVC should fix this problem.

Access serial port from guest

Check you permission for the serial port:

$ ls -l /dev/ttyS*
crw-rw---- 1 root uucp 4, 64 Feb  3 09:12 /dev/ttyS0
crw-rw---- 1 root uucp 4, 65 Feb  3 09:12 /dev/ttyS1
crw-rw---- 1 root uucp 4, 66 Feb  3 09:12 /dev/ttyS2
crw-rw---- 1 root uucp 4, 67 Feb  3 09:12 /dev/ttyS3

Add your user to the uucp group.

Guest freezes after starting Xorg

Faulty or missing drivers may cause the guest to freeze after starting Xorg, see for example [7] and [8]. Try disabling 3D acceleration in Settings > Display, and check if all Xorg drivers are installed.

Fullscreen mode shows blank screen

On some window managers (i3, awesome), VirtualBox has issues with fullscreen mode properly due to the overlay bar. To work around this issue, disable "Show in Full-screen/Seamless" option in "Guest Settings > User Interface > Mini ToolBar". See the upstream bug report for more information.

Host freezes on virtual machine start

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Needs a link to a bug report. (Discuss in Talk:VirtualBox#)

Possible causes/solutions:

  • SMAP

This is a known incompatiblity with SMAP enabled kernels affecting (mostly) Intel Broadwell chipsets. A solution to this problem is disabling SMAP support in your kernel by appending the nosmap option to your kernel parameters.

  • Hardware Virtualisation

Disabling hardware virtualisation (VT-x/AMD-V) may solve the problem.

  • Various Kernel bugs
    • Fuse mounted partitions (like ntfs) [9], [10]

Generally, such issues are observed after upgrading VirtualBox or linux kernel. Downgrading them to the previous versions of theirs might solve the problem.

Linux guests have slow/distorted audio

The AC97 audio driver within the Linux kernel occasionally guesses the wrong clock settings when running inside Virtual Box, leading to audio that is either too slow or too fast. To fix this, create a file in /etc/modprobe.d/ with the following line:

options snd-intel8x0 ac97_clock=48000

Analog microphone not working

If the audio input from an analog microphone is working correctly on the host, but no sound seems to get through to the guest, despite the microphone device apparently being detected normally, installing a sound server such as PulseAudio on the host might fix the problem.

If after installing PulseAudio the microphone still refuses to work, setting Host Audio Driver (under VirtualBox > Machine > Settings > Audio) to ALSA Audio Driver might help.

Microphone not working after upgrade

There have been issues reported around sound input in 5.1.x versions. [11]

Downgrading may solve the problem. You can use virtualbox-bin-5.0AUR to ease downgrading.

Problems with images converted to ISO

Some image formats cannot be reliably converted to ISO. For instance, ccd2iso ignores .ccd and .sub files, which can result in disk images with broken files.

In this case, you will either have to use CDemu for Linux inside VirtualBox or any other utility used to mount disk images.

Failed to create the host-only network interface

Make sure all required kernel modules are loaded. See #Load the VirtualBox kernel modules.

Failed to insert module

When you get the following error when trying to load modules:

Failed to insert 'vboxdrv': Required key not available

Sign your modules or disable CONFIG_MODULE_SIG_FORCE in your kernel config.

VBOX_E_INVALID_OBJECT_STATE (0x80BB0007)

This can occur if a VM is exited ungracefully. Run the following command:

$ VBoxManage controlvm virtual_machine_name poweroff

NS_ERROR_FAILURE and missing menu items

This happens sometimes when selecting QCOW/QCOW2/QED disk format when creating a new virtual disk.

If you encounter this message the first time you start the virtual machine:

Failed to open a session for the virtual machine debian.
Could not open the medium '/home/.../VirtualBox VMs/debian/debian.qcow'.
QCow: Reading the L1 table for image '/home/.../VirtualBox VMs/debian/debian.qcow' failed (VERR_EOF).
VD: error VERR_EOF opening image file '/home/.../VirtualBox VMs/debian/debian.qcow' (VERR_EOF).

Result Code: 
NS_ERROR_FAILURE (0x80004005)
Component: 
Medium

Exit VirtualBox, delete all files of the new machine and from virtualbox config file remove the last line in MachineRegistry menu (or the offending machine you are creating):

~/.config/VirtualBox/VirtualBox.xml
...
<MachineRegistry>
  <MachineEntry uuid="{00000000-0000-0000-0000-000000000000}" src="/home/void/VirtualBox VMs/debian/debian.vbox"/>
  <MachineEntry uuid="{00000000-0000-0000-0000-000000000000}" src="/home/void/VirtualBox VMs/ubuntu/ubuntu.vbox"/>
  <MachineEntry uuid="{00000000-0000-0000-0000-000000000000}" src="/home/void/VirtualBox VMs/lastvmcausingproblems/lastvmcausingproblems.qcow"/>
</MachineRegistry>
...

Arch: pacstrap script fails

If you used pacstrap in the #Installation steps for Arch Linux guests to also #Install the Guest Additions before performing a first boot into the new guest, you will need to umount -l /mnt/dev as root before using pacstrap again; a failure to do this will render it unusable.

OpenBSD unusable when virtualisation instructions unavailable

While OpenBSD is reported to work fine on other hypervisors without virtualisation instructions (VT-x AMD-V) enabled, an OpenBSD virtual machine running on VirtualBox without these instructions will be unusable, manifesting with a bunch of segmentation faults. Starting VirtualBox with the -norawr0 argument may solve the problem. You can do it like this:

$ VBoxSDL -norawr0 -vm name_of_OpenBSD_VM

Windows host: VERR_ACCESS_DENIED

To access the raw VMDK image on a Windows host, run the VirtualBox GUI as administrator.

Windows: "The specified path does not exist. Check the path and then try again."

This error message may appear when running an .exe file which requires administrator privileges from a shared folder in windows guests. [12]

As a workaround, copy the file to the virtual drive or use UNC paths (\\vboxsvr). See [13] for more information.

Windows 8.x error code 0x000000C4

If you get this error code while booting, even if you choose OS Type Win 8, try to enable the CMPXCHG16B CPU instruction:

$ vboxmanage setextradata virtual_machine_name VBoxInternal/CPUM/CMPXCHG16B 1

Windows 8, 8.1 or 10 fails to install, boot or has error "ERR_DISK_FULL"

Update the VM's settings by going to Settings > Storage > Controller:SATA and check "Use Host I/O Cache".

WinXP: Bit-depth cannot be greater than 16

If you are running at 16-bit color depth, then the icons may appear fuzzy/choppy. However, upon attempting to change the color depth to a higher level, the system may restrict you to a lower resolution or simply not enable you to change the depth at all. To fix this, run regedit in Windows and add the following key to the Windows XP VM's registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services]
"ColorDepth"=dword:00000004

Then update the color depth in the "desktop properties" window. If nothing happens, force the screen to redraw through some method (i.e. Host+f to redraw/enter full screen).

Windows: Screen flicker if 3D acceleration enabled

VirtualBox > 4.3.14 has a regression in which Windows guests with 3D acceleration flicker. Since r120678 a patch has been implemented to recognize an environment variable setting, launch VirtualBox like this:

$ CR_RENDER_FORCE_PRESENT_MAIN_THREAD=0 VirtualBox

Make sure no VirtualBox services are still running. See VirtualBox bug 13653.

Cannot mount shared folder from fstab

The /usr/bin/mount.vboxsf binary shipped in virtualbox-guest-utils cannot be used with kernels 4.16 or newer.

The existence of /usr/bin/mount.vboxsf will prevent mounting shared folders from fstab. A workaround is to declare usr/bin/mount.vboxsf as NoExtract in /etc/pacman.conf. See FS#58272 for more information.

See also