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

From Linux-VServer

Jump to: navigation, search
(Assumptions)
(catspec)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
How to share a directory, such as <code>/home</code>, among multiple vserver guests.
 
How to share a directory, such as <code>/home</code>, among multiple vserver guests.
 +
 
__TOC__
 
__TOC__
Comprehensive Work, I liked It, Thanks
+
 
 +
There are several ways to share a partition or directory between guests, both based upon the <code>mount</code> command. You are advised to read the documentation for detailed information.
  
 
== Command ==
 
== Command ==
 +
 
The following command will mount this directory for all guests:
 
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
 
  $ for guest in /var/lib/vservers/*; do mount --bind /srv/common/home ${guest}/home; done
Line 10: Line 13:
  
 
== fstab ==
 
== fstab ==
Alternatively, you may add an entry similar to the below one in <code>/etc/vservers/<guest>/fstab</code>:
+
 
 +
If a directory is *only* used by a guest (or, by guests), it should *only* be configured in the guest fstab in <code>/etc/vservers/<guest>/fstab</code>, 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
 
  /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 <code>/etc/fstab</code> 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).
  
 
== 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