Page 1 of 1

Multiple users able to access 1 VM?

Posted: 3. Jan 2009, 01:51
by sadohert
I'm hoping I can somehow setup a single VirtualBox Windows XP VM that multiple users on my Linux system can access. For example, anyone in the "XP_VM" group would be able to start up and use the VM. In the event that one of the other users has already started the VM then the 2nd person would be locked out, or possibly the VM could be shutdown and restarted for the new user.

This way I only have to maintain a single VM (and all the iTunes/etc. data), but my wife and I still have our own separate environments within Ubuntu.

I'm about to dive in and start trying things, but I have a few questions:

1. Has anyone else done this setup, and how did you go about it?
2. Are there any obvious snags that will prevent me from doing this?

I'm not really worried about this being a rock solid, robust solution. Just something that works.

Thanks in advance.

Posted: 4. Jan 2009, 14:30
by TerryE
The VM opens its VDIs read/write by default so you can only open one copy at one time. However there is nothing to stop multiple Ubuntu users opening the same VM. (i) You need to ensure that all Ubuntu users have r/w access to the .VirtualBox directoy and VDIs. This is a matter of Ubuntu config; e.g. make sure that you all belong to a common group, and set their group ownership to this. (ii) read up on VBOX_USER_HOME. IIRC, you can use this by putting this command in each .bashrc
  • alias VBox="VBOX_USER_HOME=/home/fred/.VirtualBox VirtualBox &"
if the "default" user is fred.

Posted: 4. Jan 2009, 17:36
by sadohert
Thanks a lot Terry! I suspected this might be the case but I'm always leary of things when I'm not QUITE sure how they all work. I think I can get this sorted out permissions-wise, I'll probably use the CLI command to have some custom scripts do the setup and take down.

Stu

Posted: 4. Jan 2009, 17:50
by Sasquatch
You can make a check to see if the VM is already running, and if it is, give a message that it's running and need to use the VRDP option to stop the VM or use it (depends on the need of USB). With VRDP, you can gracefully stop the VM and start it for the other user.

Posted: 5. Jan 2009, 23:59
by chronoboy
The easiest methods I can think of doing for this would be to:

a) Place the shared VDI image in a directory which all users can access. My personal favorite is /opt/VMs. Feel free to choose your own location. Next make the image read-only by everyone. Next, add this VDI as immutable to each user who needs access to it. The immutable property in the new VB 2.1.0 puts the VDI in a template mode, and forces a differencing VDI to be created. Even when the VM is shutdown, changes are saved, unlike the effect in past VBox immutable images. This way, both you and your wife can have completely seperate XP desktops with your own set of preferences and applications, or a base set of applications in the VDI template in /opt/VMs. If you have enough system RAM, both you and your wife can have the VM running at the same time. I would recommend using the Savestate feature when not using the VM however.

b) One user owns the VM and the VDI in their HOME directory, they would start it using the VBoxHeadless command and both access it using RDP only.

Both methods are fairly simple to implement. In order to set a VDI to immutable for the first example, first install XP as usual and add all the applications which will be shared between you and your wife. Then, detach the VDI from the VM and remove the VDI from VirtualBox, do not delete the VDI of course. Next, at the ubuntu command line, move the VDI to a public directory:

Code: Select all

sudo mv ~/.VirtualBox/VDI/WinXP.vdi /opt/VMs
You will need to create /opt/VMs before moving it there. Next in the command-line type in:

Code: Select all

sudo chmod go+r /opt/VMs/WinXP.vdi
This will make the VDI readable by all parties who use the Linux desktop. Now, type in the command line for all users who need access to the template:

Code: Select all

VBoxManage openmedium /opt/VMs/WinXP.vdi -type immutable
After issuing this command for each user, it will appear as a disk in their VirtualBox Disk Manager. Next, for each user, add a new VM and choose WinXP.vdi as the template, and a differencing disk will be created for them and all changes will be placed into it.

I hope this information helps, good luck with whichever choice you make on this.

Posted: 6. Jan 2009, 00:51
by TerryE
chronoboy,
This is an extremely useful summary, but I think that you should start by emphasising that your approach in effect creates two personal copies of the same system that do not share the same data, so they won't able to share emails, calendars, iPlayer other media libraries.
chronoboy wrote:The immutable property in the new VB 2.1.0 puts the VDI in a template mode, and forces a differencing VDI to be created.
Humm, this reminds me that my rework of my tutorial All about VDIs is now really overdue as I need to reflect the new 2.1 features. My problem is that most of my "production" VMs use NAT so I have not really hammered this release yet. I am waiting for 2.1.2 to do this.

Posted: 6. Jan 2009, 02:23
by sadohert
WOW! Thanks chronoboy. That information was very helpful. It just so happens that today I upgraded my VBox version to 2.1 (in Ubuntu Gutsy.... to solve some unreliable USB behaviour I was having with iTunes) so I guess I have this immutable option available to me now (incidentally, I seem to be having no problems syncing to iTunes now!)

The main goal here is to have iTunes available for both my wifes and my iPod, where purchases and playlist additions, and Music Collection modifications are all available to either of us**. So, I think I want to stick with a single instance of a VM that can be kicked off by either of us, strictly to use iTunes and sync with it (which isn't that often).

Would this work?:
-Create some VBOX_HOME common directory for both of us where I store the vdi and vm related files.
-Create the Vbox alias described above:
alias VBox="VBOX_USER_HOME=/home/<common spot>/.VirtualBox VirtualBox &"
-Instead of the "VirtualBox &" part, do some handling along the lines of:
VBoxManage list runningvms
If return value contains UUID of sharedXP
- Warn that VM is already running and ask if a forced shutdown is okay?
- If Forced shutdown okay call
-- VBoxManage controlvm acpipowerbutton (or something)
Else if UUID not in list of running VMS
- VBoxManage startvm UUID

Do I need to do this with the vrdp option?

Thanks in advance

Stu

** I did my best over the last 8 months to work with Linux alternatives to iTunes (gtkpod, Amarok+gtkpod) but I just couldn't make things work the way iTunes does for me, not to mention in Canada we don't really have a great non-DRM music download option.... basically, I didn't change the contents of my iPod since fully switching to Linux last April.

Posted: 6. Jan 2009, 21:14
by chronoboy
What I personally do is store my music library on my Linux host and share them with the guest(s) via the shared folders feature. For example, your base template image can contain all your applications including iTunes which points to a network drive(M:) which contains the music library. Each user who uses this template should have the shared folder assigned. This way, you can easily share your music collection with your Linux media players and utilities, as well as all your Windows guests.

As for your questions, I have not yet attempted to share a single VM among many users, besides using RDP. If you have the memory, concider creating an init-script which can savestate the VM on host shutdown, and resume it on host start-up. Since the applications you need to use are not very graphically intensive, connecting via RDP should not be an issue. The guest will still respond to the USB filters, such as your iPod.

Another neat idea, which I use personally for my friends Linux accounts, is create a special Xsession which they log into. This Xsession basically restores a VM fullscreen via VBoxSDL. The only thing running on their session is Windows XP and nothing more.

Since you use Ubuntu, this could work quite well. For example, create an new user called SharedXP, log into this user as normal, create the VM. After the user has been created, change it's default Xsession to just VBoxSDL loading the VM fullscreen. With Ubuntu, you and your wife would have up to 3 different ways to boot and use XP. The first being from the initial login screen right after boot-up. Second being a full screen new user session. The third being, an Xnested user session.

After you are done using SharedXP, just hit Ctrl-S on your keyboard and it will nicely save the state of the VM and log off the SharedXP user. The next time you log into this user, it will appear almost instantly on the screen with no waiting for XP to boot.

If you are quite new to Linux and shellscripts are not your high points, the last options here would be the easiest way to create a SharedXP environment. If you need information on how to create Xsession files for GDM(Gnome Display Manager) the default login screen for Ubuntu, just ask and I will provide the directory and example script for you to place there.

If you still wish to go through with your script, concider using Zenity for your shellscript interace, it is fairly straight foreward to use in shellscripts. You would be using "grep" or something similar to check the output for the UUID. Instead of shuting down the OS, just connect to the existing session using RDP. Enable RDP access in the VMs settings. This will speed up access to the VM, and prevent any work from possibly being lost. However, unless you and your wife are not signed in at the exact same time, the VM should not be started when the other user starts it up.

Kevin.