logo
Published on Input Jam (http://www.kleinfelter.com)

Somewhat Portable VirtualBox

By Kevin Kleinfelter
Created 2008-06-01 22:25

I'd like to have a zero-install, Windows, virtual machine environment.  In theory, this would let me run my OS and desktop environment on any Windows computer, without installing the VM software.

There is a fundamental reason why this can't happen 100%.  The VM has to be able to handle the situation when the virtual computer attempts to execute ring-0 (privileged mode) instructions.  You have to install a device driver or a Windows service in order to be able to handle the interrupt/trap.  There is also the issue of getting your network to work.  Many VMs handle this by creating a TUN/TAP virtual adapter in the host.

You can get close to zero-install with VirtualBox.  For starters, you don't have to create the TAP virtual adapter in the host.  For a VirtualBox NAT adapter, VirtualBox does not provide the full TCP/IP stack to the VM.  Essentially, it provides a TCP (only) proxy.  While this breaks things like 'ping', it means you don't need a virtual host adapter in order to do networking from the guest.

Here's a Windows batch file to run a non-installed VirtualBox.  It assumes you have copied the contents of the C:\Program Files\Sun\xVM VirtualBox directory to C:\kevin\pvm\app. It also assumes that you have a utility program called 'sleep' that can sleep for the given number of seconds.

SET pvbroot=C:\kevin\pvb
SET datadir=C:\kevin\pvb-data

SET VBOX_USER_HOME=%datadir%\.VirtualBox


REM This service *has* to be loaded.  It manages the client's attempts to go to ring 0 (supervisor mode).
sc create pvbdrv binpath= %pvbroot%\app\vboxdrv.sys type= kernel start= auto error= normal displayname= pvbdrv


REM The VirtualBox COM service, i.e. all COM objects that live outside the VM process. 
%pvbroot%\app\VBoxSVC.exe /reregserver


REM Client-side COM library. All COM (or XPCOM) objects that live on the client side (i.e. inside the VM execution process) are contained in this file. So IConsole and friends go there. 
regsvr32.exe /S %pvbroot%\app\VBoxC.dll

REM Load the "VirtualBox Portable Runtime (IPRT)"
rundll32 %pvbroot%\app\VBoxRT.dll,RTR3Init

REM Start the ring-0 driver
sc start pvbdrv


REM Start the GUI
%pvbroot%\app\VirtualBox.exe


REM Count off seconds before you let it continue.  If you don't, you'll find that you have to reboot before you can run again.
sleep 2
REM Stop the ring-0 service
sc stop pvbdrv

REM Remove the VirtualBox COM service, i.e. all COM objects that live outside the VM process.
%pvbroot%\app\VBoxSVC.exe /unregserver


REM Remove Client-side COM library. All COM (or XPCOM) objects that live on the client side (i.e. inside the VM execution process) are contained in this file. So IConsole and friends go there. 
%pvbroot%\regsvr32.exe /S /U app\VBoxC.dll


REM Make sure it is really stopped
sc query pvbdrv


sleep 3
sc delete pvbdrv


Source URL:
http://www.kleinfelter.com/node/118