vserver Howto/FAQ

Howto index

Is it possible to share one area of a file system between vservers

Vservers are running in chroot environment. As such, they can only see what is under their / directory. So it does not sounds possible to share one area or one file-system between several virtual servers.

There is an option. Kernel 2.4 allows one volume to be mounted several time with different mount point. Say you have a volume /dev/hda3 and you would like to share it between vserver v1 and v2. You can do the following

	mkdir /vservers/v1/data
	mkdir /vservers/v2/data
	mount /dev/hda3 /vservers/v1/data
	mount /dev/hda3 /vservers/v2/data

You can fill the /etc/fstab file so that /dev/hda3 is mounted at boot time.

This is not completely flexible since you can only share a full partition. If you want to share a smaller area (and potentially several of those small area), you can loopback mount a file and share it. For example:

	dd if=/dev/zero bs=1024k count=10 of=/var/data
	/sbin/losetup /dev/loop0 /var/data
	/sbin/mke2fs /dev/loop0
	mount /dev/loop0 /vservers/v1/data
	mount /dev/loop0 /vservers/v2/data

Kernel 2.4 also support the mount --bind option. This allows one to connect a directory in multiple places in the file system, even if this directory is not a mount point. For example, you may want to create several vservers to tests various distributions, yet you want to share the /home directory between each. The following command will do the job. This is probably the easiest way to share data between vservers.

	mount --bind /home /vservers/name/home