“How do I share a single Virtual Machne (VM) guest among users on a single host?” I have seen this question asked before and found a need to make it happen myself for a customer.
In this case I wanted to set up three users to be able to use a single VM. They would each have separate logins on both the Linux host and the Windows XP guest. This proved to be fairly easy.
The default configuration for VirtualBox is to have the VMs and their disks located in the ~/Virtual/.VirtualBox directory. Therefore each user would have a separate set of VMs including configuration and disks.
To change this I created the directory /Virtual/.VirtualBox, which you can name anything you wish. However it must be located such that all users have access to it. It cannot be in any user’s home directory because it would not be accessible to other users and it would create a security hazard for that user if it were made accessible to others. Another, some would say better location for this directory would be in /var. I wanted a separate filesystem so that backup and restore of /var would be separate and distinct from my VirtualBox VMs and so I could easily add more space to the logical volume which contains that filesystem.
Each user must configure the default folder locations in the General section of the VirtualBox Settings menu in order to access the VMs.
|Default Hard Disk folder||/Virtual/.VirtualBox/VDI|
|Default Machine folder||/Virtual/.VirtualBox/Machines|
One user should create the VM to be used and shared by all. Then the file permissions and group ownership need to be modified by root.
File Permissions and Ownership
After creating the VM to be shared, root or another user with appropriate access, should modify the permissions and group ownership of certain files. The installation for VirtualBox creates a group named vboxusers. All users who will use VirtualBox should be made members of this group.
In addition, the VDI file for the shared virtual machine disk in the /Virtual/.VirtualBox/VDI directory should be set with group ownership of vboxusers and group permissions should be RW. By default the group permissions are empty (_ _ _). The final permissions of the vdi file should be RW_ RW_ _ _ _. This allows all users who are members of the vboxusers group to run a VM using this disk.
The machine definitions in the /Virtual/.VirtualBox/Machines will be owned by the individuals who create them. It is not necessary for them to have group ownership of vboxusers.
Adding the Virtual Hard Disk
After the above steps have been taken and XP has been installed as a guest in the virtual machine, other users can use that existing disk when they create their own XP guest VM.
First, use the Virtual Media Manager (File => Virtual Media Manager) to add the virtual hard drive to the list of existing virtual disks that can be selected for use in a VM. On the Hard Disks tab select Add. Do not use New as that would create a new virtual hard drive. This opens a file management window that you can use to navigate to the location of the VDI file, if it is not in the default location. Since the VDI should be in the default location as specified in Table 1, above, simply select the desired VDI file and click on the Open button.
You should now be back in the main Virtual Media Manager window and the virtual hard drive you selected should be highlighted. If it is not, be sure to highlight it now. Click the OK button and the new VM disk is added to the list of available disks.
Creating the VM
Each user will add a guest VM using this disk by clicking on the New button, then click Next to get to the VMName and OS Type window. Enter a name and select the appropriate OS type, such as Linux and Fedora. Then click Next to set the VM memory size, then click Next again.
At this point you should be in the window with the title, “Virtual Hard Disk.” Click on the Use existing hard disk radio button and select the desired disk from the list. Now click Next and then Finish and you are done; the new VM is listed in the VirtualBox console and it will use the shared virtual disk when launched.