Difference between revisions of "VirtualBox"

From ArchWiki
Jump to: navigation, search
(Hosts running a custom kernel)
(note about "Check for updates" is sometimes not pointing to the latest version)
 
(475 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
 
[[Category:Emulators]]
 
[[Category:Emulators]]
[[Category:Virtualization]]
+
[[Category:Hypervisors]]
 
[[cs:VirtualBox]]
 
[[cs:VirtualBox]]
 
[[de:VirtualBox]]
 
[[de:VirtualBox]]
 +
[[el:VirtualBox]]
 
[[es:VirtualBox]]
 
[[es:VirtualBox]]
 
[[fr:VirtualBox]]
 
[[fr:VirtualBox]]
Line 11: Line 12:
 
[[ru:VirtualBox]]
 
[[ru:VirtualBox]]
 
[[zh-CN:VirtualBox]]
 
[[zh-CN:VirtualBox]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|This article is about basic usage of VirtualBox, including running the VirtualBox software within an Arch ''host'', and running an Arch ''guest'' inside a VirtualBox virtual machine.}}
+
{{Related|VirtualBox/Tips and tricks}}
{{Article summary heading|Required software}}
+
{{Related|:Category:Hypervisors}}
{{Article summary link|VirtualBox|https://www.virtualbox.org}}
+
{{Related|PhpVirtualBox}}
{{Article summary heading|Related}}
+
{{Related|Moving an existing install into (or out of) a virtual machine}}
{{Article summary wiki|VirtualBox Extras}}
+
{{Related articles end}}
{{Article summary wiki|PhpVirtualBox}}
+
{{Article summary wiki|VirtualBox Arch Linux Guest On Physical Drive}}
+
{{Article summary wiki|Advanced VirtualBox Networking}}
+
{{Article summary wiki|Installing Arch Linux from VirtualBox}}
+
{{Article summary wiki|Moving an existing install into (or out of) a virtual machine}}
+
{{Article summary end}}
+
  
'''VirtualBox''' is a virtual PC emulator like [[VMware]]. It is in constant development and new features are implemented all the time. e.g. version 2.2 introduced OpenGL 3D acceleration support for Linux and Solaris guests. It has a [[Qt]] GUI interface, as well as headless and [[Wikipedia:SDL|SDL]] command line tools for managing and running virtual machines. It includes ''guest additions'' for some guest operating systems, which integrate functions of the guest and host systems, including sharing files, the clipboard, video acceleration and a “seamless” window integration mode.
+
[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.
  
{{Wikipedia|VirtualBox}}
+
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.
  
== Installation on host ==
+
== Installation steps for Arch Linux hosts ==
  
The basic GPL-licensed VirtualBox suite can be [[pacman|installed]] with the {{Pkg|virtualbox}} package, found in the [[official repositories]]. You will need to install {{pkg|virtualbox-host-modules}} separately, if it is not installed with the the {{Pkg|virtualbox}} package, which contains the precompiled modules for the stock archlinux kernel. For custom kernels, read [[#Hosts running a custom kernel|the section below]].
+
In order to launch VirtualBox virtual machines on your Arch Linux box, follow these installation steps.
  
In order to use the graphical interface, based on [[Qt]] ({{ic|VirtualBox}} command), you will also need to install the {{Pkg|qt4}} package. This is not required for the simpler SDL-only GUI ({{ic|VBoxSDL}} command) nor for the {{ic|VBoxHeadless}} command.
+
=== Install the core packages ===
  
If you are using the {{pkg|linux-lts}} kernel you should install also the {{pkg|virtualbox-host-modules-lts}} package.
+
[[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}}
  
=== Hosts running a custom kernel ===
+
To compile the virtualbox modules provided by {{Pkg|virtualbox-host-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.
  
VirtualBox works just fine with custom kernels such as [[Linux-ck]] ''without'' the need to keep any of the official ARCH kernel packages on the system. The trick to keeping pacman from bringing down the ARCH kernel packages is to install virtualbox with the {{Pkg|virtualbox-host-dkms}} package, which contains the source for the virtualbox kernel modules. See {{Bug|26721}} for further explanations.
+
You can also install the {{Pkg|qt5-x11extras}} optional dependency in order to use the graphical interface which is based on [[Qt]]. This is not required if you intend to use VirtualBox in command-line only. [[#Use the right front-end|See below to learn the differences]].
  
Once {{Pkg|virtualbox-host-dkms}} is installed, simply generate the kernel modules for your custom kernel by running:
+
=== Sign modules ===
  
# dkms install vboxhost/<virtualbox-host-source version> -k <your custom kernel's version>/<your architecture>
+
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.
  
Which for the lazy is the command:
+
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
  
# dkms install vboxhost/$(pacman -Q virtualbox|awk {'print $2'}|sed 's/\-.\+//') -k $(uname -rm|sed 's/\ /\//')
+
{{Note|Hashing algorithm does not have to match the one configured, but it must be built into the kernel.}}
  
and load it:
+
=== Load the VirtualBox kernel modules ===
  
# modprobe vboxdrv
+
Since version 5.0.16, {{Pkg|virtualbox-host-modules-arch}} and {{Pkg|virtualbox-host-dkms}} use {{ic|systemd-modules-load.service}} to load all four VirtualBox modules at boot time.
  
{{Note|To load/compile virtualbox modules automatically at startup you can enable dkms.service.}}
+
{{Note|If you don't want the VirtualBox modules to be loaded at boot time, you have to mask the default {{ic|/usr/lib/modules-load.d/virtualbox-host-modules-arch.conf}} (or {{ic|-dkms.conf}}) by creating an empty file (or symlink to {{ic|/dev/null}}) with the same name in {{ic|/etc/modules-load.d}}.}}
  
==== Automatic re-compilation of the virtualbox host modules with every update of any kernel====
+
Among the [[kernel modules]] VirtualBox uses, there is a mandatory module named {{ic|vboxdrv}}, which must be loaded before any virtual machines can run.
  
This is possible thanks to {{AUR|vboxhost-hook}} from the [[AUR]]. In '''vboxhost-hook''', the 'automatic re-compilation' functionality is done by a '''vboxhost hook''' on [[mkinitcpio]] after forcing to update the '''linux-headers''' package. You will need to add 'vboxhost' to the HOOKS array in /etc/mkinitcpio.conf, as well as 'linux-headers' and your custom kernel(s) headers to the SyncFirst array in /etc/pacman.conf for this to work.
+
To load the module manually, run:
 +
# modprobe vboxdrv
  
The hook will call the '''dkms''' command to update the virtualbox host modules for the version of your new kernel.
+
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}}.
  
{{Note|If you are using this functionality it's '''important''' to look at the installation process of the linux (or any other kernel) package. vboxhost hook will tell you if anything goes wrong.}}
+
* {{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.
  
== Setup ==
+
* {{ic|vboxpci}} is needed when your virtual machine needs to pass through a PCI device on your host.
  
Add the desired username to the '''vboxusers''' [[group]]. Everything may work fine without this step but shared folders and possibly some other optional stuff require it to work. The new group does not automatically apply to existing sessions; the user has to log in again or start a new environment with a command like {{Ic|newgrp}} or {{Ic|sudo -u ''username'' -s}}.
+
{{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.}}
  
# gpasswd -a ''username'' vboxusers
+
Finally, if you use the aforementioned "Host-only" or "bridge networking" feature, make sure {{pkg|net-tools}} is installed. VirtualBox actually uses {{ic|ifconfig}} and {{ic|route}} to assign the IP and route to the host interface configured with {{ic|VBoxManage hostonlyif}} or via the GUI in ''Settings > Network > Host-only Networks > Edit host-only network (space) > Adapter''.
  
=== Loading Kernel Modules ===
+
=== Accessing host USB devices in guest ===
VirtualBox running on Linux uses its own [[kernel modules]], including a mandatory module named '''vboxdrv''', which must be loaded before virtual machines can run. It can be automatically loaded when Arch Linux starts up, or it can be loaded manually when necessary.
+
  
To load the VirtualBox driver at startup, add a file with the {{ic|*.conf}} suffix in the {{ic|/etc/[[Kernel_modules#Loading|modules-load.d]]}} directory (e.g. ''virtualbox.conf'') that reads "vboxdrv":
+
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]].
  
# tee /etc/modules-load.d/virtualbox.conf <<< "vboxdrv"
+
=== Guest additions disc ===
  
{{Note|You may need to update the kernel modules db in order to avoid 'no such file or directory' error when loading vboxdrv. Run: {{ic|depmod -a}}.}}
+
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.
  
To load the module manually:
+
=== Extension pack ===
  
# modprobe vboxdrv
+
The Oracle Extension Pack which provides [https://www.virtualbox.org/manual/ch01.html#intro-installing additional features], is released under a non-free license and '''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.
  
To start the VirtualBox graphical manager:
+
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]], gksu, etc.) to grant privileged access to VirtualBox. The installation of this extension [https://www.virtualbox.org/ticket/8473 requires root access].
  
$ VirtualBox
+
=== Use the right front-end ===
  
To ensure full functionality of bridged networking, ensure that the following [[Kernel modules|kernel modules]] are loaded:
+
Now, you are ready to use VirtualBox. Congratulations!
  
vboxnetadp vboxnetflt vboxpci
+
Multiple front-ends are available to you of which two are available by default:
 +
* If you want to use VirtualBox in command-line only (only launch and change settings of existing virtual machines), you can use the {{ic|VBoxSDL}} command. VBoxSDL does only provide a simple window that contains only the ''pure'' virtual machine, without menus or other controls.
 +
* If you want to use VirtualBox in command-line without any GUI running (e.g. on a server) to create, launch and configure virtual machines, use the {{ic|VBoxHeadless}} which produces no visible output on the host at all, but instead only delivers VRDP data (note: VRDP is only enabled if the extension pack is installed).
  
=== Guest additions disc ===
+
If you installed the {{Pkg|qt5-x11extras}} optional dependency, you can run {{ic|VirtualBox}} and have a nice-looking GUI interface with menus usable via the mouse.
  
The {{ic|virtualbox}} package also suggests installing {{Pkg|virtualbox-guest-iso}} on the host (Arch Linux) running VirtualBox. It is a disc image that can be used to install the guest additions onto guest systems. Make it available to the (running) guest by going to Devices and clicking "Install Guest Additions... Host+D". Then run the guest additions installation from inside the guest.
+
Finally, you can use [[PhpVirtualBox]] to administrate your virtual machines via a web interface.
  
=== Booting a live disc ===
+
Refer to the [https://www.virtualbox.org/manual VirtualBox manual] to learn how to create virtual machines.
  
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 512&nbsp;MB 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).
+
{{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_.28CoW.29|Copy-on-Write]] for the destination directory of these images.}}
  
When the new image has been created, click 'Settings', then CD/DVD-ROM, check 'Mount CD/DVD Drive' then select an ISO image.
+
== Installation steps for Arch Linux guests ==
  
=== Starting virtual machines with a service ===
+
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 [[Beginners' guide]] or the [[Installation guide]].
  
See [[Systemd/Services#VirtualBox_virtual_machines]] for details on how to setup a systemd service for each virtual machine.
+
==== Installation in EFI mode ====
  
=== Advanced setup ===
+
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.
  
See [[VirtualBox Extras]] for advanced configuration.
+
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:
  
== Arch Linux guests ==
+
* [[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 the {{ic|startup.nsh}} script at the ESP root containing the path to the boot loader application, e.g. {{ic|\EFI\grub\grubx64.efi}}.
  
Installing Arch under VirtualBox is straightforward, and additions should be installed through pacman (not through "Install Guest Additions" in VirtualBox, or from a mounted ISO image).
+
Do not bother with the VirtualBox Boot Manager (accessible with {{ic|F2}} at boot): EFI entries added to it manually at boot 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 ===
 
=== Install the Guest Additions ===
  
Install the {{Pkg|virtualbox-guest-utils}} package:
+
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 {{Pkg|linux}} kernel choose {{Pkg|virtualbox-guest-modules-arch}}
 +
* for other 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 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).
 +
 
 +
Finally, add a {{ic|1=video=''resolution''}} kernel parameter (https://wiki.archlinux.org/index.php/Kernel_parameters) to set the framebuffer to the new resolution, for example {{ic|1=video=1360x768}}.
 +
 
 +
{{Merge|GRUB/Tips_and_tricks#Setting_the_framebuffer_resolution}}
 +
 
 +
If you use GRUB as your bootloader, you can edit {{ic|/etc/default/grub}} to include this kernel parameter in the {{ic|GRUB_CMDLINE_LINUX_DEFAULT}} list, like so:
 +
 
 +
GRUB_CMDLINE_LINUX_DEFAULT="quiet video=1360x768"
 +
 
 +
The GRUB menu itself may also be easily set to optimal resolution, by editing
 +
the {{ic|GRUB_GFXMODE}} option on the same configuration file:
 +
 
 +
GRUB_GFXMODE="1360x768x24"
 +
 
 +
On a standard Arch setup, you would then run {{ic|grub-mkconfig -o /boot/grub/grub.cfg}} to commit these changes to the bootloader.
 +
 
 +
After these steps, the framebuffer resolution should be optimized for the GRUB menu and all virtual consoles.
 +
 
 +
{{Note|The GRUB settings {{ic|GRUB_GFXPAYLOAD_LINUX}} and {{ic|vga}} will not fix the framebuffer, since they are overriden by virtue of Kernel Mode Setting, which is mandatory for using X under VirtualBox and only allows for setting the framebuffer resolution by setting the kernel parameter described above.}}
 +
 
 +
=== Load the Virtualbox kernel modules ===
  
# pacman -S virtualbox-guest-utils
+
To load the modules automatically, [[enable]] the {{ic|vboxservice}} service which loads the modules and synchronizes the guest's system time with the host.
Manually load the modules with:
+
  
 +
To load the modules manually, type:
 
  # modprobe -a vboxguest vboxsf vboxvideo
 
  # modprobe -a vboxguest vboxsf vboxvideo
  
Create a {{ic|*.conf}} file (e.g. {{ic|virtualbox.conf}}) in {{ic|/etc/modules-load.d/}} with these lines:
+
Since version 5.0.16, {{Pkg|virtualbox-guest-modules-arch}} and {{Pkg|virtualbox-guest-dkms}} use '''systemd-modules-load''' service to load their modules at boot time.
  
{{hc|/etc/modules-load.d/virtualbox.conf|
+
{{Note|If you don't want the VirtualBox modules to be loaded at boot time, you have to mask the default {{ic|/usr/lib/modules-load.d/virtualbox-guest-modules-arch.conf}} (or {{ic|-dkms.conf}}) by creating an empty file (or symlink to {{ic|/dev/null}}) with the same name in {{ic|/etc/modules-load.d}}.}}
vboxguest
+
vboxsf
+
vboxvideo}}
+
  
=== Automatic re-compilation of the virtualbox guest modules with every update of any kernel ===
+
=== Launch the VirtualBox guest services ===
  
This is possible thanks to {{AUR|vboxguest-hook}} from the [[AUR]]. In '''vboxguest-hook''', the 'automatic re-compilation' functionality is done by a '''vboxguest hook''' on [[mkinitcpio]] after forcing to update the '''linux-headers''' package. You will need to add 'vboxguest' to the HOOKS array in /etc/mkinitcpio.conf, as well as 'linux-headers' and your custom kernel(s) headers to the SyncFirst array in /etc/pacman.conf for this to work.
+
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
  
The hook will call the '''dkms''' command to update the virtualbox guest modules for the version of your new kernel.
+
All of these features can be enabled independently with their dedicated flags:
 +
$ VBoxClient --clipboard --draganddrop --seamless --display --checkhostversion
  
{{Note|If you are using this functionality it's '''important''' to look at the installation process of the linux (or any other kernel) package. vboxguest hook will tell you if anything goes wrong.}}
+
As a shortcut, the {{ic|VBoxClient-all}} bash script enables all of these features.
  
=== Start the sharing services ===
+
{{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 this scheme, you will need to set up autostarting yourself, see [[Autostarting#Graphical]] for more details.
After installing {{Pkg|virtualbox-guest-utils}} above, you should start {{ic|VBoxClient-all}} to start services for sharing the clipboard, resizing the screen, etc.
+
* If you are running something that launches {{Ic|/etc/xdg/autostart/vboxclient.desktop}}, such as GNOME or KDE, then nothing needs to be done.
+
* If you use {{Ic|.xinitrc}} to launch things instead, you must add the following to your {{Ic|.xinitrc}} before launching your WM.
+
  
# VBoxClient-all &
+
VirtualBox can also synchronize the time between the host and the guest, to do this, [[start/enable]] the {{ic|vboxservice.service}}.
  
=== Using USB webcam / microphone ===
+
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'').
  
{{Note|You will need to have VirtualBox extension pack installed before following the steps below. See [[VirtualBox_Extras#Extension_pack]] for details.}}
+
=== Hardware acceleration ===
  
# Make sure the virtual machine is not running and your webcam / microphone is not being used.
+
Hardware acceleration can be activated from the VirtualBox options on the host computer. Note the [[GDM]] display manager 3.16+ is known to [https://bugzilla.gnome.org/show_bug.cgi?id=749390 break] hardware acceleration support. 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]
# Bring up the main VirtualBox window and go to settings for Arch machine. Go to USB section.
+
# Make sure "Enable USB Controller" is selected. Also make sure that "Enable USB 2.0 (EHCI) Controller" is selected too.
+
# Click the "Add filter from device" button (the cable with the '+' icon).
+
# Select your USB webcam/microphone device from the list.
+
# Now click OK and start your VM.
+
  
=== Using Arch under Virtualbox EFI mode ===
+
If you want to share folders between your host and your Arch Linux guest, read on.
  
My experience with this configuration was pretty terrible, but it does work.
+
=== Enable shared folders ===
  
''UPD. Using efibootmgr has the same effect as using VirtualBox boot menu (see the note below): settings [https://www.virtualbox.org/ticket/11177 disappear] after VM shutdown.'' First, {{ic|efibootmgr}} does *not* work. It will appear to work, but all changes it makes appear to be overwritten on reboot. After performing a standard UEFI/GPT installation, reboot and you should get dumped to the EFI shell. Type exit and you will get a menu. Select the Boot Management Manager, Boot Options, Add Boot Option. Use the file browser to find the grub efi file and select it. Add a label if you want. Afterwards, select Change Boot Order from the menu, use arrow keys to select your Arch option, and + to move it up to the top. GRUB should boot by default now.
+
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].
  
Other options are: 1) move your loader to \EFI\boot\bootx64.efi, 2) create \startup.nsh script, which executes desirable loader, like this:
+
No matter which method you will use to mount your folder, all methods require some steps first.
  
{{hc|\startup.nsh|
+
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.
HD16a0a1:\EFI\refind\refindx64.efi}}
+
  
Here I'm using consistent mapping name (HD16a0a1). It's probably a good idea, because they do survive configuration changes.
+
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]].
  
{{Note|Another useful way to get back to the EFI menu after autobooting is working is to press the {{Keypress|C}} key inside GRUB and type {{ic|exit}}. Obviously, this will only work with {{ic|grub-efi}}, not {{ic|grub-bios}}.<br>
+
==== Manual mounting ====
Regenerating the {{ic|grub.cfg}} file may also be required to fix broken UUIDs. Check with the {{ic|lsblk -f}} command that they match.<br>
+
Yet another useful way to get to VirtualBox boot menu is pressing F12 right after starting virtual machine. It comes in handy when using rEFInd + EFISTUB, for example.}}
+
  
== Shared Folders as Arch Linux Guest ==
+
Use the following command to mount your folder in your Arch Linux guest:
 +
# mount -t vboxsf ''shared_folder_name'' ''mount_point_on_guest_system''
  
Shared folders are managed via the VirtualBox program on the host. They may be added, auto-mounted and made read-only from there. Creating a shared folder from the VirtualBox program in the host locates that folder in {{Ic|/media/sf_''SHAREDFOLDERNAME''}}. At this time an additional step is needed to have that folder created in the Arch Guest because Arch use a package for Guest Additions. To create and access this shared folder from the Arch Guest, this must also be done at the command line after installing the Guest Additions package(s) from pacman:
+
The vboxsf filesystem offers other options which can be displayed with this command:
 +
# mount.vboxsf
  
# groupadd 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:
  # gpasswd -a $USER vboxsf
+
  # mount -t vboxsf -o uid=1000,gid=1000 home /mnt/
  
If you wish, a symbolic link may be made to another folder in your home directory for easy access. As an example, if a shared folder named "Dropbox" was created in the VirtualBox program on the host machine, then /media/sf_Dropbox is automatically created in the guest so this could be done:
+
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.
  
$ ln -s /media/sf_Dropbox/* ~/dropbox
+
==== Automounting ====
  
The .run script provided in the Guest Additions iso does this for you, however, Arch does not recommend using that script so this step must be done manually. The instructions for it were found here: (pastebin: [http://pastebin.com/6cUE3kjF]) .
+
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}}.
  
If shared folders are not auto-mounted, try [https://bbs.archlinux.org/viewtopic.php?id=70780 manually mount] or read the next section.
+
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 755 or has group ownership {{ic|vboxsf}} if using permission 750. This is currently not the default if media is created by installing the {{ic|virtualbox-guest-utils}}.
  
To prevent startup problems when you're using [[systemd]], you should add {{ic|1=comment=systemd.automount}} to your {{ic|/etc/fstab}}. This way, they are mounted only when you access those mountpoints and not during startup. Otherwise your system might become unusable after a kernel upgrade (if you install your guest additions manually).
+
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''
  
desktop  /media/desktop    vboxsf  uid=user,gid=group,rw,dmode=700,fmode=600,comment=systemd.automount 0 0
+
==== Mount at boot ====
  
Don't waste your time to test the {{ic|nofail}} option. {{ic|mount.vboxsf}} is not able to handle this (2012-08-20).
+
You can mount your directory with [[fstab]]. However, to prevent startup problems with systemd, {{ic|1=comment=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 read fstab and mount the partitions.
 +
''sharedFolderName''  ''/path/to/mntPtOnGuestMachine''  vboxsf  uid=''user'',gid=''group'',rw,dmode=700,fmode=600,comment=systemd.automount  0  0
  
desktop  /media/desktop    vboxsf  uid=user,gid=group,rw,dmode=700,fmode=600,nofail 0 0
+
* {{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''}}.}}
  
=== Synchronise guest date with host ===
+
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
  
To keep sync date and time, make sure you have {{Pkg|virtualbox-guest-utils}} installed in your host (see [[#Install the Guest Additions|previous section]]). Then run
+
== Virtual disks management ==
# systemctl enable vboxservice.service
+
  
To enable the service for next boot. To start immediately, run
+
See also [[VirtualBox/Tips and tricks#Import/export VirtualBox virtual machines from/to other hypervisors]].
# systemctl start vboxservice.service
+
  
You also need run this daemon in order to use auto-mounting feature of shared folders that are mentioned above.
+
=== Formats supported by VirtualBox ===
  
== Troubleshooting ==
+
VirtualBox supports the following virtual disk formats:
=== VBOX_E_INVALID_OBJECT_STATE (0x80BB0007) ===
+
This can occur if a VM is exited ungracefully.  The solution to unlock the VM is trivial:
+
VBoxManage controlvm nArch poweroff
+
  
=== USB subsystem is not working on the host or guest ===
+
* VDI: The Virtual Disk Image is the VirtualBox own open container used by default when you create a virtual machine with VirtualBox.
  
Sometimes the USB subsystem is not auto-detected resulting in an error or in a not visible USB drive on the host, even when the user is in the '''vboxusers''' group. See this topic [https://bbs.archlinux.org/viewtopic.php?id=125785] for details.
+
* 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 specially 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.
  
{{Note|In {{Pkg|linux}} 3.5 and later, usbfs was dropped. The {{ic|/etc/fstab}} method is no longer working. Please use the USB subsystem method}}
+
* 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.}}  
  
====fstab method====
+
* 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].
Adding an entry in {{Ic|/etc/fstab}} should resolve this issue:
+
  
  none  /proc/bus/usb  usbfs  auto,busgid=108,busmode=0775,devgid=108,devmode=664  0  0
+
* Version 2 of the HDD: 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.}}
  
====USB subsystem method====
+
* 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.
USB subsystem will work if you add
+
  
VBOX_USB=usbfs
+
* 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 has flaw and is not recommended). QCOW is available in two versions: QCOW and QCOW2. The latter 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 this QCOW2 format (both revisions have been tried).
  
to {{Ic|~/.bashrc}} and reboot your system or open a new bash instance.
+
* 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].
  
=== Failed to create the host-only network interface ===
+
* 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].
  
To be able to create a Host-Only Network Adapter or a Bridged Network Adapter the kernel modules {{ic|vboxnetadp}} and {{ic|vboxnetflt}} need to be loaded. It's possible to load these kernel modules manually with
+
=== Disk image format conversion ===
  
# modprobe -a vboxnetadp vboxnetflt
+
==== VMDK to VDI and VDI to VMDK ====
  
To load them automatically at boot, add a new line for each module to {{ic|/etc/modules-load.d/virtualbox.conf}}:
+
VirtualBox can handle back and forth conversion between VDI and VMDK by itself with [https://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi VBoxManage clonehd].
  
vboxdrv
+
VMDK to VDI:
vboxnetadp
+
vboxnetflt
+
  
{{Note|These used to be added to the {{ic|MODULES}} array in {{ic|/etc/rc.conf}}. This is now deprecated.}}
+
$ VBoxManage clonehd ''source.vmdk'' ''destination.vdi'' --format VDI
  
More information in [https://bbs.archlinux.org/viewtopic.php?id=130581 this] topic.
+
VDI to VMDK:
  
=== WinXP: Bit-depth cannot be greater than 16 ===
+
$ VBoxManage clonehd ''source.vdi'' ''destination.vmdk'' --format VMDK
  
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}} add the following key to the Virtual Windows XP registry:
+
==== VHD to VDI and VDI to VHD ====
  
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services]
+
VirtualBox can handle conversion back and forth this format with [https://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi VBoxManage clonehd] too.
"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. {{Keypress|Host+F}} to redraw/enter full screen).
+
VHD to VDI:
  
=== Mounting .vdi Images ===
+
$ VBoxManage clonehd ''source.vhd'' ''destination.vdi'' --format VDI
  
This just work with '''static''' size vdi images! '''Dynamic size won't''' be easy mountable! First we need one information from your .vdi image:
+
VDI to VHD:
  
  $ VBoxManage internalcommands dumphdinfo Arch_64min.vdi |grep offData
+
  $ VBoxManage clonehd ''source.vdi'' ''destination.vhd'' --format VHD
Header: offBlocks=4096 offData=69632
+
  
Now, '''add to your''' {{ic|offData}} 32256. e.g. 32256 + 69632 = 101888
+
==== QCOW2 to VDI and VDI to QCOW2 ====
  
Now you can mount your vdi image:
+
[https://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi VBoxManage clonehd] cannot handle the QEMU format conversion; we will thus rely on another tool. The {{ic|qemu-img}} command from {{Pkg|qemu}} can be used to convert images back and forth from VDI to QCOW2. {{Note|{{ic|qemu-img}} can handle a bunch of other formats too. According to the {{ic|qemu-img --help}}, here are the supported formats this tool supports: "''vvfat vpc vmdk vhdx vdi ssh sheepdog sheepdog sheepdog raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd nbd nbd iscsi dmg tftp ftps ftp https http cow cloop bochs blkverify blkdebug'".}}
  
# mount -t ext4 -o rw,noatime,noexec,loop,offset=101888 Arch_64min.vdi /mnt/
+
QCOW2 to VDI:
  
=== Startup problems because of mount failures ===
+
$ qemu-img convert -pO vdi ''source.qcow2'' ''destination.vdi''
  
If you experience problems in a [[systemd]] setup after a kernel upgrade, you should start the system with {{ic|1=init=/bin/bash}} (if the emergency shell does not work for you).
+
VDI to QCOW2:
  
  root=/dev/mapper/vg_main-lv_root ro vga=792 resume=/dev/mapper/vg_main-lv_swap init=/bin/bash
+
  $ qemu-img convert -pO qcow2 ''source.vdi'' ''destination.qcow2''
  
Then mount the ''root''-filesystem with write access:
+
As QCOW2 comes in two revisions (see [[#Formats supported by VirtualBox]], use the flag {{ic|1=-o compat=}} to specify the revision.
  
  # mount / -o remount,rw
+
  $ qemu-img convert -pO qcow2 ''source.vdi'' ''destination.qcow2'' -o compat=0.10
 +
or
 +
$ qemu-img convert -pO qcow2 ''source.vdi'' ''destination.qcow2'' -o compat=1.1
  
Change {{ic|/etc/fstab}} according to [[VirtualBox#Shared Folders as Arch Linux Guest]]. Then exec systemd within the Bash shell:
+
{{Tip|The {{ic|-p}} parameter is used to get the progression of the conversion task.}}
  
# exec /bin/systemd
+
=== Mount virtual disks ===
  
=== Copy&Paste not working on Arch Linux Guest ===
+
==== VDI ====
  
Since updating {{ic|virtualbox-guest-additions}} to version {{ic|4.2.0-2}} copy&paste from Host OS to Arch Linux Guest stopped working. It seems to be due to {{ic|VBoxClient-all}} requiring ''root'' access. In previous versions adding ''VBoxClient-all &'' to ''~/.xinitrc'' was sufficient to make copy&paste work. Update ''~/.xinitrc'' to match {{ic|sudo VBoxClient-all &}} and add the line {{ic|, NOPASSWD: /usr/bin/VBoxClient-all}} to your username in the sudoers file and restart X. It should all work again. The line in the sudoers file should look similar to this:
+
Mounting vdi images only works with fixed size images (a.k.a. static images); dynamic (dynamically size allocating) images are not easily mountable.
  
  # Allow sudo for user 'you' and let him run VBoxClient-all without requiring a password
+
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):
  you ALL = PASSWD: ALL, NOPASSWD: /usr/bin/VBoxClient-all
+
  
{{Note|Use {{ic|visudo}} to edit the sudoers file. This will check for syntax errors when saving.}}
+
$ VBoxManage internalcommands dumphdinfo <storage.vdi> | grep "offData"
  
=== Mouse is resetting to (0,0) randomly and frequently ===
+
The can now be mounted with:
  
Due to xorg [https://bugs.freedesktop.org/show_bug.cgi?id=54353 bug 54353] (and related bug reports discussed within), the VirtualBox mouse device will frequently reset to the upper left corner of the screen.
+
# mount -t ext4 -o rw,noatime,noexec,loop,offset=101888 <storage.vdi> /mntpoint/
  
The workaround suggested in the bug discussion can be applied by adding a script to {{ic|/etc/X11/xinit/xinitrc.d}} with:
+
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/}}):
  
  for Z in $(xinput list | sed '/\(master\|slave \) \<pointer\>/!d;s/.*id=\([0-9]\+\).*/\1/'); do
+
# mount -t vdi -o fstype=ext4,rw,noatime,noexec ''vdi_file_location'' ''/mnt/''
    xinput set-prop $Z "Coordinate Transformation Matrix" 0.500000, 0.000000, 0.000000, 0.000000, 0.500000, 0.000000, 0.000000, 0.000000, 0.500000
+
    xinput set-prop $Z "Coordinate Transformation Matrix" 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
+
  done
+
  
By changing the matrix's value and changing it back to its original value, the internal condition that triggers this bug is avoided.
+
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]:
  
=== Use Serial port in guest OS ===
+
# modprobe nbd max_part=16
Check you permission in Serial port
+
# 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 {{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>}}.
 +
 
 +
=== Compact virtual disks ===
 +
 
 +
Compacting virtual disks only works with {{ic|.vdi}} files and basically consists in the following steps.
 +
 
 +
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].
 +
 
 +
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 {{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.
 +
 
 +
* On Windows, there are two tools available:
 +
:*{{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;
 +
:* 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}}.}}
 +
 
 +
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 {{ic|fsck}} manually;
 +
:* 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]];
 +
* On Windows systems, you can use:
 +
:* either {{ic|chkdsk ''c:'' /F}} where  {{ic|''c:''}} needs to be replaced by each disk you need to scan and fix errors;
 +
:* 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;
 +
 
 +
Now, remove the zeros from the {{ic|vdi}} file with [https://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi VBoxManage modifyhd]:
 +
$ VBoxManage modifyhd ''your_disk.vdi'' --compact
 +
 
 +
{{Note|If your virtual machine has snapshots, you need to apply the above command on each {{ic|.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 [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.
 +
 
 +
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.
 +
 
 +
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
 +
 
 +
{{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}}.}}
 +
 
 +
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 {{ic|VBoxManage showvminfo ''VM_name''}}. Among the output you will get such a result (what you are looking for is in italic):
 +
 
 +
{{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)
 +
[...]}}
 +
 
 +
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.
 +
 
 +
{{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''
 +
 
 +
==== Increase size for VDI disks ====
 +
If your disk is a vdi one, simply 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 {{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:
 +
 
 +
{{hc|ArchLinux_vm.vbox|2=
 +
<HardDisk uuid="''{670157e5-8bd4-4f7b-8b96-9ee412a712b5}''" location="''ArchLinux_vm.vdi''" format="''VDI''" type="Normal"/>
 +
}}
 +
 
 +
then in the {{ic|<AttachedDevice>}} sub-tag of {{ic|<StorageController>}}, replace the GUID by the new one.
 +
 
 +
{{hc|ArchLinux_vm.vbox|2=
 +
<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 {{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].}}
 +
 
 +
==== Transfer between Linux host and other OS ====
 +
 
 +
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.
 +
 
 +
{{bc|1=
 +
#!/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 {{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}}}}
 +
 
 +
=== 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, the latter will keep track of all UUID 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.
 +
 
 +
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 your virtual disk:
 +
$ VBoxManage internalcommands sethduuid ''/path/to/disk.vdi''
 +
 
 +
{{Tip|In the future, to avoid copying the virtual disk and assigning a new UUID to your file manually, use [http://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi VBoxManage clonehd] instead.}}
 +
 
 +
{{Note|The commands above supports [[#Formats supported by VirtualBox|all virtual disk formats supported by VirtualBox]].}}
 +
 
 +
== Tips and tricks ==
 +
 
 +
For advanced configuration, see [[VirtualBox/Tips and tricks]].
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== VERR_ACCESS_DENIED ===
 +
 
 +
To access the raw vmdk image on a windows host, run the VirtualBox GUI as administrator.
 +
 
 +
=== 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 {{ic|umount -l /mnt/dev}} as root before using ''pacstrap'' again; a failure to do this will render it unusable.
 +
 
 +
=== Keyboard and mouse are blocked in my virtual machine ===
 +
 
 +
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.
 +
 
 +
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.
 +
 
 +
=== Cannot send CTRL+ALT+Fn key to my virtual machine ===
 +
 
 +
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.
 +
 
 +
=== Fix ISO images problems ===
 +
 
 +
While VirtualBox can mount ISO images without 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.
 +
 
 +
In this case, you will either have to use [[CDEmu]] for Linux inside VirtualBox or any other utility used to mount disk images.
 +
 
 +
=== VirtualBox GUI does not match my GTK Theme ===
 +
 
 +
See [[Uniform Look for Qt and GTK Applications]] for information about theming Qt based applications like Virtualbox.
 +
 
 +
=== 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 [https://www.virtualbox.org/ticket/3947 may solve the problem]. You can do it like this:
 +
$ VBoxSDL -norawr0 -vm ''name_of_OpenBSD_VM''
 +
 
 +
=== VBOX_E_INVALID_OBJECT_STATE (0x80BB0007) ===
 +
 
 +
This can occur if a VM is exited ungracefully. The solution to unlock the VM is trivial:
 +
$ VBoxManage controlvm ''virtual_machine_name'' poweroff
 +
 
 +
=== USB subsystem is not working on the host or guest ===
 +
 
 +
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.
 +
 
 +
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 ''/etc/udev/rules.d/''. VirtualBox 5.0 installs udev rules to ''/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.
 +
 
 +
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''):
 +
 
 +
{{hc|~/.bashrc|VBOX_USB<nowiki>=</nowiki>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 {{ic|storage}} group.
 +
 
 +
=== Failed to create the host-only network interface ===
 +
 
 +
Make sure all required kernel modules are loaded. See [[#Load the VirtualBox kernel modules]].
 +
 
 +
=== 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 {{ic|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. {{ic|Host+f}} to redraw/enter full screen).
 +
 
 +
=== Use serial port in guest OS ===
 +
 
 +
Check you permission for the serial port:
 
  $ /bin/ls -l /dev/ttyS*
 
  $ /bin/ls -l /dev/ttyS*
 
  crw-rw---- 1 root uucp 4, 64 Feb  3 09:12 /dev/ttyS0
 
  crw-rw---- 1 root uucp 4, 64 Feb  3 09:12 /dev/ttyS0
Line 308: Line 577:
 
  crw-rw---- 1 root uucp 4, 67 Feb  3 09:12 /dev/ttyS3
 
  crw-rw---- 1 root uucp 4, 67 Feb  3 09:12 /dev/ttyS3
  
Add you user in '''uucp''' group.
+
Add your user to the {{ic|uucp}} [[group]].
  # gpasswd -a YOURUSER uucp
+
 
and relogon.
+
=== 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 {{ic|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".
 +
 
 +
=== 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 {{ic|/etc/modprobe.d}} with the following line:
 +
 
 +
options snd-intel8x0 ac97_clock=48000
 +
 
 +
=== Guest freezes after starting Xorg ===
 +
 
 +
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.
 +
 
 +
=== "NS_ERROR_FAILURE" and missing menu items ===
 +
 
 +
If you encounter this message when first time starting the virtual machine:
 +
 
 +
{{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).
 +
 
 +
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 {{ic|MachineRegistry}} menu (or the offending machine you are creating):
 +
 
 +
{{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>
 +
...
 +
}}
 +
 
 +
This happens sometimes when selecting ''QCOW''/''QCOW2''/''QED'' disk format when creating a new virutal disk.
 +
 
 +
=== USB modem ===
 +
 
 +
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.
 +
 
 +
=== "The specified path does not exist. Check the path and then try again." error in Windows guests ===
 +
 
 +
This error message often appears when running an .exe file which requires administrator priviliges from a shared folder in windows guests. See [https://www.virtualbox.org/ticket/5732 the bug report] for details.
 +
 
 +
There are two workarounds:
 +
 
 +
# Disable UAC from Control Panel -> Action Center -> "Change User Account Control settings" from left side pane -> set slider to "Never notify" -> OK and reboot
 +
# Copy the file from the shared folder to the guest and run from there
 +
 
 +
Other threads on the internet suggest to add VBOXSVR to the list of trusted sites, but this doesn't work with Windows 7 or newer.
 +
 
 +
=== 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 {{ic|VT-x}}) are enabled in the BIOS.
 +
 
 +
If you're 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]
 +
 
 +
=== Host OS freezes on Virtual Machine start ===
 +
 
 +
{{Expansion|Needs a link to a bug report; vague expressions like "currently" and "at the moment of writing" are of no help.}}
 +
 
 +
Possible causes/solutions :
 +
* SMAP
 +
This is a known incompatiblity with SMAP enabled kernels affecting (mostly) Intel Broadwell chipsets. The matter is currently being investigated, with a wide variety of WIP vboxhost module patches out in the wild that are meant to solve the issue. At the moment of writing though, the only 100% guaranteed solution to this problem is disabling SMAP support in your kernel by appending the "nosmap" option to your kernel boot command line.
 +
* 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]
 +
 
 +
Generally, such issues are observed after upgrading VirtualBox or linux kernel. Downgrading them to the previous versions of theirs might solve the problem.
 +
 
 +
=== The virtual machine has terminated unexpectedly during startup with exit code 1 (0x1) ===
 +
 
 +
When trying to launch a virtual machine, an error message like the following appears:
 +
 
 +
{{bc|The virtual machine has terminated unexpectedly during startup with exit code 1 (0x1)
 +
NS_ERROR_FAILURE 0x80004005
 +
Component: MachineWrap
 +
Interface: IMachine}}
 +
 
 +
This may occur after upgrading the {{Pkg|virtualbox}} or {{Pkg|virtualbox-host-modules}} package. Try reloading the {{ic|vboxdrv}} module:
 +
 
 +
{{bc|# modprobe -r vboxdrv
 +
# modprobe vboxdrv
 +
}}
 +
 
 +
=== Analog microphone not working in guest ===
 +
 
 +
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.
 +
 
 +
=== Fullscreen mode shows blank guest screen ===
 +
On some window managers ([[i3]]), VirtualBox has issues with fullscreen mode properly due to the overlay bar.  To workaround this issue, disable "Show in Full-screen/Seamless" option in "Guest Settings --> User Interface --> Mini ToolBar".  See [https://www.virtualbox.org/ticket/14323 the upstream bug report] for more information.
 +
 
 +
=== Failed to insert module ===
  
=== Abort on resume ===
+
If you encounter problem when loading modules as follow:
There is a known bug that causes abort on resume: https://www.virtualbox.org/ticket/11289. The workaround is simple: always use Host+q or the menu to close the VM.
+
Failed to insert 'vboxdrv': Required key not available
 +
Make sure you signed your modules or disable {{ic|CONFIG_MODULE_SIG_FORCE}} in your kernel config.
  
== External links ==
+
== See also ==
  
* [http://www.virtualbox.org/manual/UserManual.html VirtualBox User Manual]
+
* [https://www.virtualbox.org/manual/UserManual.html VirtualBox User Manual]
 +
* [[Wikipedia:VirtualBox]]

Latest revision as of 17:00, 22 July 2016

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:

To compile the virtualbox modules provided by virtualbox-host-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). [1] When either VirtualBox or the kernel is updated, the kernel modules will be automatically recompiled thanks to the DKMS Pacman hook.

You can also install the qt5-x11extras optional dependency in order to use the graphical interface which is based on Qt. This is not required if you intend to use VirtualBox in command-line only. See below to learn the differences.

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

Since version 5.0.16, virtualbox-host-modules-arch and virtualbox-host-dkms use systemd-modules-load.service to load all four VirtualBox modules at boot time.

Note: If you don't want the VirtualBox modules to be loaded at boot time, you have to mask the default /usr/lib/modules-load.d/virtualbox-host-modules-arch.conf (or -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.

Finally, if you use the aforementioned "Host-only" or "bridge networking" feature, make sure net-tools is installed. VirtualBox actually uses ifconfig and route to assign the IP and route to the host interface configured with VBoxManage hostonlyif or via the GUI in Settings > Network > Host-only Networks > Edit host-only network (space) > Adapter.

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 which provides additional features, is released under a non-free license and 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, gksu, etc.) to grant privileged access to VirtualBox. The installation of this extension requires root access.

Use the right front-end

Now, you are ready to use VirtualBox. Congratulations!

Multiple front-ends are available to you of which two are available by default:

  • If you want to use VirtualBox in command-line only (only launch and change settings of existing virtual machines), you can use the VBoxSDL command. VBoxSDL does only provide a simple window that contains only the pure virtual machine, without menus or other controls.
  • If you want to use VirtualBox in command-line without any GUI running (e.g. on a server) to create, launch and configure virtual machines, use the VBoxHeadless which produces no visible output on the host at all, but instead only delivers VRDP data (note: VRDP is only enabled if the extension pack is installed).

If you installed the qt5-x11extras optional dependency, you can run VirtualBox and have a nice-looking GUI interface with menus usable via the mouse.

Finally, you can 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 Beginners' guide or 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 the startup.nsh script at the ESP root containing the path to the boot loader application, e.g. \EFI\grub\grubx64.efi.

Do not bother with the VirtualBox Boot Manager (accessible with F2 at boot): EFI entries added to it manually at boot 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).

Finally, add a video=resolution kernel parameter (https://wiki.archlinux.org/index.php/Kernel_parameters) to set the framebuffer to the new resolution, for example video=1360x768.

Merge-arrows-2.pngThis article or section is a candidate for merging with GRUB/Tips_and_tricks#Setting_the_framebuffer_resolution.Merge-arrows-2.png

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

If you use GRUB as your bootloader, you can edit /etc/default/grub to include this kernel parameter in the GRUB_CMDLINE_LINUX_DEFAULT list, like so:

GRUB_CMDLINE_LINUX_DEFAULT="quiet video=1360x768"

The GRUB menu itself may also be easily set to optimal resolution, by editing the GRUB_GFXMODE option on the same configuration file:

GRUB_GFXMODE="1360x768x24"

On a standard Arch setup, you would then run grub-mkconfig -o /boot/grub/grub.cfg to commit these changes to the bootloader.

After these steps, the framebuffer resolution should be optimized for the GRUB menu and all virtual consoles.

Note: The GRUB settings GRUB_GFXPAYLOAD_LINUX and vga will not fix the framebuffer, since they are overriden by virtue of Kernel Mode Setting, which is mandatory for using X under VirtualBox and only allows for setting the framebuffer resolution by setting the kernel parameter described above.

Load the Virtualbox kernel modules

To load the modules automatically, enable the 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

Since version 5.0.16, virtualbox-guest-modules-arch and virtualbox-guest-dkms use systemd-modules-load service to load their modules at boot time.

Note: If you don't want the VirtualBox modules to be loaded at boot time, you have to mask the default /usr/lib/modules-load.d/virtualbox-guest-modules-arch.conf (or -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 this scheme, you will need to set up autostarting yourself, see Autostarting#Graphical 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 from the VirtualBox options on the host computer. Note the GDM display manager 3.16+ is known to break hardware acceleration support. So if you get issues with hardware acceleration, try out another display manager (lightdm seems to work fine).[3] [4]

If you want to share folders between your host and your Arch Linux guest, read on.

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 -t 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 -t 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

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 the 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

You can mount your directory with fstab. However, to prevent startup problems with systemd, comment=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 read fstab and mount the partitions.

sharedFolderName  /path/to/mntPtOnGuestMachine  vboxsf  uid=user,gid=group,rw,dmode=700,fmode=600,comment=systemd.automount  0  0
  • 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

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 specially 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.
  • Version 2 of the HDD: 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 has flaw and is not recommended). QCOW is available in two versions: QCOW and QCOW2. The latter 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 this QCOW2 format (both revisions have been tried).
  • 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

VMDK to VDI and VDI to VMDK

VirtualBox can handle back and forth conversion between VDI and VMDK by itself with VBoxManage clonehd.

VMDK to VDI:

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

VDI to VMDK:

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

VHD to VDI and VDI to VHD

VirtualBox can handle conversion back and forth this format with VBoxManage clonehd too.

VHD to VDI:

$ VBoxManage clonehd source.vhd destination.vdi --format VDI

VDI to VHD:

$ VBoxManage clonehd source.vdi destination.vhd --format VHD

QCOW2 to VDI and VDI to QCOW2

VBoxManage clonehd cannot handle the QEMU format conversion; we will thus rely on another tool. The qemu-img command from qemu can be used to convert images back and forth from VDI to QCOW2.
Note: qemu-img can handle a bunch of other formats too. According to the qemu-img --help, here are the supported formats this tool supports: "vvfat vpc vmdk vhdx vdi ssh sheepdog sheepdog sheepdog raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd nbd nbd iscsi dmg tftp ftps ftp https http cow cloop bochs blkverify blkdebug'".

QCOW2 to VDI:

$ qemu-img convert -pO vdi source.qcow2 destination.vdi

VDI to QCOW2:

$ qemu-img convert -pO qcow2 source.vdi destination.qcow2

As QCOW2 comes in two revisions (see #Formats supported by VirtualBox, use the flag -o compat= to specify the revision.

$ qemu-img convert -pO qcow2 source.vdi destination.qcow2 -o compat=0.10

or

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

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 in 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.

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
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.

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

Increase size for VDI disks

If your disk is a vdi one, simply 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, the latter will keep track of all UUID 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 your virtual disk:

$ VBoxManage internalcommands sethduuid /path/to/disk.vdi
Tip: In the future, to avoid copying the virtual disk and assigning a new UUID to your file manually, use VBoxManage clonehd instead.
Note: The commands above supports all virtual disk formats supported by VirtualBox.

Tips and tricks

For advanced configuration, see VirtualBox/Tips and tricks.

Troubleshooting

VERR_ACCESS_DENIED

To access the raw vmdk image on a windows host, run the VirtualBox GUI as administrator.

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.

Keyboard and mouse are blocked in my 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.

Cannot send CTRL+ALT+Fn key to my virtual machine

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.

Fix ISO images problems

While VirtualBox can mount ISO images without 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.

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

VirtualBox GUI does not match my GTK Theme

See Uniform Look for Qt and GTK Applications for information about theming Qt based applications like Virtualbox.

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

VBOX_E_INVALID_OBJECT_STATE (0x80BB0007)

This can occur if a VM is exited ungracefully. The solution to unlock the VM is trivial:

$ VBoxManage controlvm virtual_machine_name poweroff

USB subsystem is not working on the host or guest

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.

Failed to create the host-only network interface

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

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).

Use serial port in guest OS

Check you permission for the serial port:

$ /bin/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.

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".

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

Guest freezes after starting Xorg

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

"NS_ERROR_FAILURE" and missing menu items

If you encounter this message when first time starting 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>
...

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

USB modem

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.

"The specified path does not exist. Check the path and then try again." error in Windows guests

This error message often appears when running an .exe file which requires administrator priviliges from a shared folder in windows guests. See the bug report for details.

There are two workarounds:

  1. Disable UAC from Control Panel -> Action Center -> "Change User Account Control settings" from left side pane -> set slider to "Never notify" -> OK and reboot
  2. Copy the file from the shared folder to the guest and run from there

Other threads on the internet suggest to add VBOXSVR to the list of trusted sites, but this doesn't work with Windows 7 or newer.

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're using a Windows host, you may need to disable Hyper-V, as it prevents VirtualBox from using VT-x. [7]

Host OS 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; vague expressions like "currently" and "at the moment of writing" are of no help. (Discuss in Talk:VirtualBox#)

Possible causes/solutions :

  • SMAP

This is a known incompatiblity with SMAP enabled kernels affecting (mostly) Intel Broadwell chipsets. The matter is currently being investigated, with a wide variety of WIP vboxhost module patches out in the wild that are meant to solve the issue. At the moment of writing though, the only 100% guaranteed solution to this problem is disabling SMAP support in your kernel by appending the "nosmap" option to your kernel boot command line.

  • Hardware Virtualisation

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

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

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

The virtual machine has terminated unexpectedly during startup with exit code 1 (0x1)

When trying to launch a virtual machine, an error message like the following appears:

The virtual machine has terminated unexpectedly during startup with exit code 1 (0x1)
NS_ERROR_FAILURE 0x80004005
Component: MachineWrap
Interface: IMachine

This may occur after upgrading the virtualbox or virtualbox-host-modules package. Try reloading the vboxdrv module:

# modprobe -r vboxdrv
# modprobe vboxdrv

Analog microphone not working in guest

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.

Fullscreen mode shows blank guest screen

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

Failed to insert module

If you encounter problem when loading modules as follow:

Failed to insert 'vboxdrv': Required key not available

Make sure you signed your modules or disable CONFIG_MODULE_SIG_FORCE in your kernel config.

See also