VirtualBox is “a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use.” meaning that it emulates a computer graphically within your installed OS, allowing you to use different operating systems and applications virtually without the need to install on “real metal”
Whichever OS you use out of Windows/Linux/*BSD there is a version available for you to use.
For the sake of this blog post I will assume that you are using a *BSD or Linux Operating system (sorry windows user , I don’t use windows at all , I am sure with some research you may get the second part working within windows, the first part should work ok). My second assumption is that you have already downloaded and installed VirtualBox, set up a virtual machine with an operating system in place and ready to use. if you have not then read this blog post and decide if this is something you would like to try and install VirtualBox from ports or your distribution’s repository (or the VirtualBox site.)
The first part of this article is to show the terminal command-line version to launch your virtual machine directly into a window (or tile if using a tiling window manager), the second part will show you how to launch your VirtualBox image into a separate Xserver, the third part explains a couple of great practical applications of using this within your desktop environment or current window manager
Starting a VirtualBox image from the command-line, this is actually remarkably simple. start up a terminal and type:
VBoxManage startvm <Virtualbox Image Name>
for example if I have created a virtualbox machine called “vbrowser”
VBoxManage startvm vbrowser
this would launch the virtual image directly into its own window.
how simple is that?
Ok moving on… in order to launch your chosen virtualbox within its own (second or higher) Xserver we need to set up a file called .vboximage you can do this by using a text editor and add the following lines:
VBoxManage startvm <Virtualbox Image Name> &
or without a editor you can use the following directly from a terminal
echo “VBoxManage startvm <Virtualbox Image Name> &” >> .vboximage
echo “exec <windowmanager>” >> .vboximage
be careful to use >> and not > as the former appends to the file the latter will over write the file
the <windowmanger entry will be the one to host the virtual image, its best for it to be as small and light as possible I have chosen “tinywm” although “matchbox”, “ratpoison”, “dwm” or similar would do just as well install one on your realworld install
so my .vboximage file looks like
VBoxManage startvm vbrowser &
If you think this looks like a .xinitrc file it is, but one for a dedicated virtual machine running in a seperate Xserver.
once you have your .vboximage file written we can move to the cli command to launch it again this is surprisingly simple:
startx /home/user-name/.vboximage — :1
so to launch my Virtualbox image I would use
startx /home/mrmysteryguest/.vboximage — :1
this tells the xserver to start up in the next tty (so if your X is currently in “alt+ctl F8″ it will start in “alt+ctl+F9″, leaving your current Xsession untouched.
OK so now you know how to launch VirtualBox from the terminal, why would you want to?
one reason is Keybindings, you could add either of the terminal commands to your main DE or WM keybindings configuration file allowing you to launch your virtual machine seamlessly without having to launch the full VirtualBox control center to launch it.
I use SpectrWM so to set up the keybindings I just add the following to my .spectrwm.conf and restart the windowmanger using MOD+Q
program[vbrowse] = VBoxManage startvm vbrowser #starts in a window
bind[vbrowse] = MOD+F4
program[newxvbox] = startx /home/mrmysteryguest/.vboximage — :1 #starts in new X
bind[newxvbox] = MOD+F5
this means that to launch the vbrowser virtual machine within a seperate “window/tile”
and whichever virtual machine (windows even) is stipulated in .vboximage in a different Xserver.
I use these methods within freebsd to launch a cut down linux iso I remastered just to have Firefox & browser-plugins launch at starting ratpoison ad a browser appliance, essentially serving as an alternative to adding the linux-binary-compatibility layer (which causes my machine to overheat somewhat).
Please let me know if you have any other tips and tricks of this type, sign up to the forum and share.