Vserver

From Tom's notes
Jump to navigation Jump to search

Creating a new guest

Deploy the template:

vserver sandbox build --context 100 --hostname sandbox --interface eth0:192.168.0.100/24 --initstyle gentoo -m template -- -d gentoo -t /vservers/stage3-amd64-20160317.tar.bz2

Install a service:

ROOT=/vservers/sandbox emerge -pv syslog-ng
chroot /vservers/sandbox
rc-update add syslog-ng default

Check vserver config files:

  • /etc/vservers/sandbox/fstab

If you want autostart:

echo default > /etc/vservers/git/apps/init/mark

Start the guest:

vserver sandbox start

Check config files:

  • /etc/portage/make.conf

Bind mount a directory in a running guest

source: http://linux-vserver.org/Frequently_Asked_Questions#How_do_I_bind_mount_a_host_directory_inside_a_running_guest.3F

Let's enter the management namespace of the guest (that's what -i 0 is for):

vnamespace -i 0 -e <guest-xid> -- /bin/bash

Now you have access to all host devices; mount the device that contains your directory wherever you want, but you may prefer to mount it in the same location you used on the host. (Note, though, that it's not even necessary for the device to be mounted in the host namespace at all.)

It's likely best to use mount -n lest your host /etc/mtab get polluted with mounts from other namespaces.

mount -n /dev/sr0 /media/cdrom
exit

We're now back in the host namespace. vmount can now be used to bind mount /media/cdrom/foo inside a running guest (in this example, under /foo inside the vserver root):

vmount guestname -- --bind /media/cdrom/foo /mnt/foo

Resizing tmpfs in running guest

vnamespace -e 11 chroot /data/vservers/sandbox mount -t tmpfs -o remount,size=4g none /tmp