Wednesday, October 7, 2009

How to share a VirtualBox virtual machine with multiple users on Linux/Ubuntu

Have you ever wanted to share your virtual machine with other users? Doing so will save a lot of space (since you only need one virtual machine) and keep you more in line with the EULA of the distribution you are running virtual (assuming that's Windows or Mac).

There are many tutorials online (for example) that will help you to install VirtualBox on your linux machine. A couple things to note:
  1. You probably want to use the package from the VirtualBox download site (and not the open source one that you can get with apt-get) since it has many of the features that are important for a good virtual machine (like USB support and OpenGL acceleration etc).

  2. Make sure a vboxusers group was created and that everyone who would want to use the virtual machine is part of that group.
Prerequisite: right now the only way I can get this to work is if everyone wanting to share the virtual machine has sudo privileges. I'd be interested if anyone can suggest a way to do this without them. OK, we're ready to start:
  1. Make a shared directory for your virtual machines:
    sudo mkdir /var/local/VirtualBox
  2. Create a soft link from the home directory of each user sharing:
    ln -s /var/local/VirtualBox $HOME/.VirtualBox
  3. Now create a custom application launcher for your panel:
    sh -c "gksudo 'chown -R $USER:$USER /var/local/VirtualBox'; VirtualBox"
    (that command [or similar] could be wrapped up in a .bashrc function, a script placed in your $HOME/bin directory or whatever).
Also, remember when you buy your next computer to think about getting one with virtualization capabilities (for instance, an intel chart of core 2 duo desktop processors which support virtualization)


Anonymous said...

Thanks for the symlink idea; just what I was looking for.

You can avoid the sudo wrapper stuff by making sure everything under /var/local/VirtualBox is in a suitable group (e.g., vboxusers in Ubuntu) and has suitable group permissions.

Lollo said...

that's not correct. The last user which launch the machine set the .vbox owner and group to himself automatically.
So the "sudo wrapper" is indeed necessary