Difference between revisions of "Share a directory among multiple guests"

From Linux-VServer

Jump to: navigation, search
(expanded info about sharing partitions/directories)
(catspec)
 
(2 intermediate revisions by one user not shown)
Line 24: Line 24:
 
== See also ==
 
== See also ==
 
* <code>$ man mount</code>
 
* <code>$ man mount</code>
 +
 +
[[Category:Configuration]]

Latest revision as of 20:15, 21 October 2011

How to share a directory, such as /home, among multiple vserver guests.

Contents


There are several ways to share a partition or directory between guests, both based upon the mount command. You are advised to read the documentation for detailed information.

[edit] Command

The following command will mount this directory for all guests:

$ for guest in /var/lib/vservers/*; do mount --bind /srv/common/home ${guest}/home; done

Note that you might have to (re)start your vserver AFTER the mount for the shared path to be visible under it.

[edit] fstab

If a directory is *only* used by a guest (or, by guests), it should *only* be configured in the guest fstab in /etc/vservers/<guest>/fstab, otherwise mount it on the host, and --bind mount it into the guest (as shown above) if required. This can also be done using an entry in the guests fstab similar to this one:

/srv/common/home       /home    none    bind    0 0

If the partition or directory is to be used by two guests, you should list it in both the guest fstabs. The kernel will then do the proper stuff, unless you are using a really weird filesystem. In this scenario, assuming a recent util-vserver of course, it is sufficient to add the following line to *both* of the guest fstabs while not adding anything to /etc/fstab on the host:

/srv/common/home       /home    none    defaults    0 0

Note: this will make the directory read-write by all the vservers that are able to access it. I have not yet figured how to have a directory mounted read-write in one vserver and read-only in another (2009-02-01 - gdm).

[edit] See also

  • $ man mount
Personal tools