Sharing a virtual machine with another user of the computer.

I have done a lot of reading about “linux sharing folders with other local users” this evening, but haven’t figured out yet which suits me.

I would like to share the virtual machine created by virtualbox with another user. The VB files are under /home/[my user name]/vm machines. I manually set the permission of the folder to “read/write”. But after the other user uses virutualbox to boot up the guest machine, the owner of those vm files is changed to him. I don’t have access to the virtual machine anymore.

Should I follow this one?

Your example shows how to setup a shared folder with users on the same PC, but not between two different running copies of openSUSE Linux when you add in the VM copy. For sharing between PC’s (including a VM) have a look at this:

Chapter 18. Sharing File Systems with NFS: openSUSE 12.2: Chapter 18. Sharing File Systems with NFS

And With Samba:

SWAT - Samba Web Administration Tool - Setup & Creation Script - 1.04: https://forums.opensuse.org/blogs/jdmcdaniel3/swat-samba-web-administration-tool-setup-creation-script-1-03-105/

Setting up a folder, usable by all works with NFS or Samba, but you need to go between computers some how. When using VirtualBox, it is possible to map in a shared folder on the host as a mapped drive on the VM as well, which works only between a host & client on the very same PC. So imagine that on the host PC you created a folder called SHARED_FOLDER that is setup just as your link has suggested. You could then add the following code to the /etc/init.d/boot.local file that mounts this folder for the VM to use, on the same PC.

if  ! -d /SHARED_FOLDER ] ; then
  mkdir /SHARED_FOLDER
fi
mount -t vboxsf SHARED_FOLDER /SHARED_FOLDER -o defaults

There are all sort of schemes, but you need to specify where the folder is to be shared and where you want to use the folder and if it is between two copies of openSUSE on the same PC, as in VirtualBox Host/Client or just where you are going with the shared folder.

Thank You,

On Wed, 20 Feb 2013 23:06:06 +0000, jdmcdaniel3 wrote:

> Your example shows how to setup a shared folder with users on the same
> PC,
> but not between two different running copies of openSUSE Linux when you
> add in the VM copy. For sharing between PC’s (including a VM) have a
> look at this:

I didn’t get from OP’s post that he’s using multiple machines, but that
he wants to share the VM between different local users. Maybe the OP can
clarify this?

I have generally found that running VMs over a remote filesystem is not
advised for performance reasons, though IMHO it’s clearly dependent on
the network technology that’s used. It’s not uncommon, for example, to
use an iSCSI target as an inexpensive shared cluster storage for a
private cloud (indeed, I may set something like that up myself), but over
NFS or SAMBA, I don’t know that I’d do that.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

So there are three solutions there, shared folder on Host to VM Client if all on a single PC as well as NFS and Samba solutions when more than one PC is involved. What other solution might you suggest?

Thank You,

I put all the virtual machines related files (.vid, .xml files and logs) in a directory outside from any user’s home, owned by root and group vboxusers (with mode 775). Every time after another user accesses a virtual machine (and snaps the owership of the files and logs), I run an alias as root that I called “vboxperm”. I made it an alias in root’s environment, but it could be a script as well.


# alias vboxperm
alias vboxperm='find /srv/vbox -type d -exec chmod 775 "{}" ";" -exec chown "root:vboxusers" "{}" ";" ; find /srv/vbox -type f -exec chmod 664 "{}" ";" -exec chown "root:vboxusers" "{}" ";"'

All you need to do is to run “vboxperm” - whether it is an alias or a script - as root, everytime a user closes a virtual machine.

  • You just have to replace /srv/vbox in the example above with the directory where you put your vms .

On 2013-02-21 02:06, please try again wrote:
>> Should I follow ‘this one’ (http://tinyurl.com/bb979ok)?
> I put all the virtual machines related files (.vid, .xml files and
> logs) in a directory outside from any user’s home, owned by root and
> group vboxusers (with mode 775). Every time after another user accesses
> a virtual machine (and snaps the owership of the files and logs), I run
> an alias as root that I called “vboxperm”. I made it an alias in root’s
> environment, but it could be a script as well.

Would not making the files stickies work?


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On Wed, 20 Feb 2013 23:46:02 +0000, jdmcdaniel3 wrote:

> So there are three solutions there, shared folder on Host to VM Client
> if all on a single PC as well as NFS and Samba solutions when more than
> one PC is involved. What other solution might you suggest?

My understanding of the issue was “I have a VM that I want to be able to
be started by more than one local Linux user. How do I set things up so
both users have sufficient permissions to start the VM?”

To the OP - is this an accurate read of the issue you’re trying to solve?

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

First, thanks for all the replies. Will try your suggestions. And yes, this is what I intend to do…

This is how it’s done on my server:

  • The VM’s folders are outside the homedirs of the users, even on a separate partition, symlinks are made from each user’s home folder
  • Users needing access to the VM, have to be members of the group vboxusers

That’s about it.

I made a folder under home /home/virtualmachines, and made it the default folder for all vbox files.

chgrp -R vboxusers virtualmachines

. I added user1(me) and user2 to the vboxusers group in YAST.

However, still it doesn’t change the fact that after I use the vm, the other user can’t access the vm anymore.

Believe you’re going to run into many issues if you attempt what you describe.

There is a big difference between running a VM then granting multiple User access vs allowing multiple Users to run the same VM files. Linux might permit this due to its lack of enforcing file locks but the application might recognise the extreme danger and prevent this.

It’s perfectly viable to setup virtual sharing of many resources like CPU and RAM, but you need to be careful and wary of possible contention if more than one User attempts to make changes simultaneously on a shared resource, the Linux kernel can safely manage and arbitrate access to CP and RAM but nothing similar is available for a shared file system.

So, don’t. Don’t attempt to run the same VM by different Users simultaneously. Identify <why> you want to grant simultaneous access and either dupe/clone the VM so a copy can be used or implement file shares or remote access to the same VM, but in all cases any VM is run by only one User.

IMO,
TSU

On Thu, 21 Feb 2013 15:36:01 +0000, bonedriven wrote:

> Knurpht;2529030 Wrote:
>> This is how it’s done on my server:
>> - The VM’s folders are outside the homedirs of the users, even on a
>> separate partition, symlinks are made from each user’s home folder -
>> Users needing access to the VM, have to be members of the group
>> vboxusers
>>
>> That’s about it.
> I made a folder under home /home/virtualmachines, and made it the
> default folder for all vbox files.
> Code:
> --------------------
> chgrp -R vboxusers virtualmachines
> --------------------
> . I added user1(me) and user2 to the vboxusers group in YAST.
>
> However, still it doesn’t change the fact that after I use the vm, the
> other user can’t access the vm anymore.

Assuming you are running it one user at a time (sharing it wouldn’t be
supported), try changing the directory permissions to:

chmod g+rw .

(Run from the CLI in the directory where the files reside)

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

On 02/21/2013 10:29 AM, Jim Henderson wrote:
> On Thu, 21 Feb 2013 15:36:01 +0000, bonedriven wrote:
>
>> Knurpht;2529030 Wrote:
>>> This is how it’s done on my server:
>>> - The VM’s folders are outside the homedirs of the users, even on a
>>> separate partition, symlinks are made from each user’s home folder -
>>> Users needing access to the VM, have to be members of the group
>>> vboxusers
>>>
>>> That’s about it.
>> I made a folder under home /home/virtualmachines, and made it the
>> default folder for all vbox files.
>> Code:
>> --------------------
>> chgrp -R vboxusers virtualmachines
>> --------------------
>> . I added user1(me) and user2 to the vboxusers group in YAST.
>>
>> However, still it doesn’t change the fact that after I use the vm, the
>> other user can’t access the vm anymore.
>
> Assuming you are running it one user at a time (sharing it wouldn’t be
> supported), try changing the directory permissions to:
>
> chmod g+rw .
>
> (Run from the CLI in the directory where the files reside)

For multiple users to run the VM at the same time, you will need to add multiple
users to the VM, just like you would for a physical computer. Only one person
can use the VM console at a time, thus you need to run sshd on the VM. That way,
users can ‘ssh -X <vm IP address>’ to log into the VM. To avoid any confusion as
to which user can access from the console, I would run it headless so that noone
can use the console. The following script will start/stop the VM. Make sure it
is executable.


#! /bin/sh
# /etc/init.d/StartVM
#

#Edit these variables!
VMUSER=<name of user to start VM>
VMNAME="<name of VM"
case "$1" in
start)
echo "Starting VirtualBox VM..."
sudo -u $VMUSER /usr/bin/VBoxManage  startvm "$VMNAME" --type headless
;;
stop)
echo "Saving state of Virtualbox VM..."
sudo -u  $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0

To complete the setup, create links named S99StartVM and K01StartVM in
/etc/init.d/rc5.d/ that point to /etc/init.d/StartVM. That way the VM will start
when the host is booted, and stop when the host is shut down.

To be able to access the VM from any real machine on your network, including the
host, use the bridged mode of networking, and assign it a fixed IP address, then
add the name you want to use for the machine and the IP address to /etc/hosts.
My setup has a 32-bit version of openSUSE with name vm32 running as a guest on a
64-bit host. To access it, I use ‘ssh -X vm32’.

On Thu, 21 Feb 2013 18:44:08 +0000, Larry Finger wrote:

> For multiple users to run the VM at the same time, you will need to add
> multiple users to the VM, just like you would for a physical computer.

I think that’s perhaps a different thing than the OP is asking.

I think what the OP is asking (and he seems to have confirmed) is that on
the local machine, he’s got two users - let’s call them “user1” and
“user2”.

Those are the users on the bare metal OS installed.

He wants each of those users to be able to launch the VM separately; only
one of them uses the machine at a time.

Once the VM is running, it sounds like the intention is either they use
the same user login to do what they need to in the VM. For example,
maybe it’s a Windows VM with the necessary software to watch Netflix on
(which would mean a remote desktop wouldn’t be viable).

Jim

Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

This is where I thought the OP was very clear he didn’t want, he actually wanted to have both Users run the VM at the same time (which would invite catastrophe).

As everyone else seems to be recommending, the proper method would be for only one User to run the VM but also provide access to the VM to any number of other people. For that reason, unless it was very clear that only one User should run the VM at any time, placing the VMs themselves on a Network Share or similar should be considered carefully. The VM doesn’t necessarily have to be run by any human being, just configure the VM to autostart on bootup so it’s available to anyone always.

TSU

On 02/21/2013 02:56 PM, tsu2 wrote:
>
> hendersj;2529146 Wrote:
>>
>>
>> He wants each of those users to be able to launch the VM separately;
>> only
>> one of them uses the machine at a time.
>>
>
> This is where I thought the OP was very clear he didn’t want, he
> actually wanted to have both Users run the VM at the same time (which
> would invite catastrophe).
>
> As everyone else seems to be recommending, the proper method would be
> for only one User to run the VM but also provide access to the VM to any

Did you mean “start” in the previous line, rather than “run”?

> number of other people. For that reason, unless it was very clear that
> only one User should run the VM at any time, placing the VMs themselves
> on a Network Share or similar should be considered carefully. The VM
> doesn’t necessarily have to be run by any human being, just configure
> the VM to autostart on bootup so it’s available to anyone always.

If the guest is a multi-user system, then any number of users might be logged in
at a time. If it is single user, obviously only 1 at a time.

No, not that complicated. I just simply want each of us has access to the vm, not in the same time.

On Thu, 21 Feb 2013 20:56:01 +0000, tsu2 wrote:

> hendersj;2529146 Wrote:
>>
>>
>> He wants each of those users to be able to launch the VM separately;
>> only one of them uses the machine at a time.
>>
>>
> This is where I thought the OP was very clear he didn’t want, he
> actually wanted to have both Users run the VM at the same time (which
> would invite catastrophe).

Agreed that would be a problem, unless he did something like used a
linked clone and each user ran their own clone.

But from my question/OP’s answer:

>> My understanding of the issue was “I have a VM that I want to be able
>> to be started by more than one local Linux user. How do I set things
>> up so both users have sufficient permissions to start the VM?”
> …]
> First, thanks for all the replies. Will try your suggestions. And yes,
> this is what I intend to do…

So that seems to indicate that that’s the goal - same VM, able to be
started by more than one local user.

Maybe a clarification on “one user /at a time/” would be helpful. When I
said “local user”, I meant “at the console”, but admittedly that could be
interpreted in multiple ways.

Jim

Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

On Thu, 21 Feb 2013 22:15:29 +0000, Jim Henderson wrote:

> Maybe a clarification on “one user /at a time/” would be helpful. When
> I said “local user”, I meant “at the console”, but admittedly that could
> be interpreted in multiple ways.

And I see that we have that now. :slight_smile:

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Just use the following command as root instead (and make it an alias or a script to save you time):


find /home/virtualmachines -type d -exec chmod 775 "{}" ";" -exec chown "root:vboxusers" "{}" ";" ; find /home/virtualmachines -type f -exec chmod 664 "{}" ";" -exec chown "root:vboxusers" "{}" ";"'

Running this command every time after another user closed a vm will do exactly what you’re trying to achieve: allowing several local users to use a virtual machine, not at the same time. If you forget to run this command, the virtual machine will be marked as “inaccessible” in VirtualBox GUI. In this case, just close VirtualBox, execute vboxperm (or whatever you call the script or the alias) as root, ans start VirtualBox again. This time, any member of the vboxusers group (!) will be able to start and use the vm. It is really uncomplicated. Whether other users will be able to log in in the operating system running in the virtual machine is another problem, but that one is not specific to virtual machines.