Installation on Gentoo
From Linux-VServer
Contents |
Guest creation
Download a precompiled stage3
Since many hardware related commands are not available inside a virtual server, there has been a patched version of baselayout known as baselayout-vserver. However, since baselayout-2/openrc, all required changes have been integrated, eliminating the need for separate vserver stages, profiles and baselayout. The only (temporary) drawback is that baselayout-2/openrc is still in testing (~arch) and there are no stages with baselayout-2/openrc available on the mirrors yet.
As soon as baselayout-2/openrc is stable you can use a precompiled stage3 from one of the Gentoo mirrors. In the meantime please download a stage3 or gentoo-vserver stage from here. Since a stage3 contains a complete root file system you can use the template build method of util-vserver. However, this method only works reliable since util-vserver-0.30.213_rc5, so make sure you have the right version installed.
You have to choose a context ID for your vserver (dynamic context IDs are discouraged) as well as the necessary network device information (In this example eth0 is configured with 192.168.1.253/24 and the context ID is equivalent to the last two parts of the virtual servers IP).
Using the template build method
For a long time now, plain init style was the only init style available for gentoo, i.e. a normal init process will be started inside the guest, just like on any common Unix system. However this approach has some drawbacks:
- No possibility to see output of init/rc scripts
- Wasted resources for idle init processes in each guest
- Annoying conflicts for /etc/inittab
Therefore, many users have requested the gentoo init style to be reimplemented, which has been abandoned since it was a very hacky implementation and more or less worked by accident due to other modifications done to baselayout back then. However, as of util-vserver-0.30.212 the gentoo init style has been reimplemented in a concise manner and will become the default in the future.
# vserver myguest build \ --context 1253 \ --hostname myguest \ --interface eth0:192.168.1.253/24 \ --initstyle gentoo \ -m template -- \ -t /path/to/gentoo-vserver-<arch>-<version>.tar.bz2 \ -d gentoo
You should be able to start and enter the vserver by using the commands below.
# vserver myguest start OpenRC 0.4.3 is starting up Gentoo Linux (x86_64) [VSERVER] Press I to enter interactive boot mode * /proc is already mounted, skipping * Setting hostname to myguest... [ ok ] * Creating user login records... [ ok ] * Cleaning /var/run... [ ok ] * Wiping /tmp directory... [ ok ] * Updating /etc/mtab... [ ok ] * Initializing random number generator... [ ok ] * Starting syslog-ng... [ ok ] * Starting fcron... [ ok ] * Starting Name Service Cache Daemon... [ ok ] * Starting local... [ ok ] # vserver-stat CTX PROC VSZ RSS userTIME sysTIME UPTIME NAME 0 90 1.4G 153.4K 14m00s11 6m45s17 2h59m59 root server 1253 2 3M 286 0m00s45 0m00s42 0m02s91 myguest # vserver myguest enter # ps ax PID TTY STAT TIME COMMAND 1 ? Ss 0:04 init [3] 27637 ? Ss 0:00 /usr/sbin/syslog-ng 27656 ? Ss 0:00 /usr/sbin/fcron -c /etc/fcron/fcron.conf 27676 ? Ssl 0:00 /usr/sbin/nscd 27713 ? S+ 0:00 login 27737 pts/15 Ss 0:00 /bin/bash 27832 pts/15 R+ 0:00 ps ax # logout
Maintenance made easy
Start guests on boot
You can start certain guests during boot. Each guest can be assigned a MARK. Now everything you have to do is configure these MARKs in the guests configuration and tell the init script to run all MARKed guests.
(Do this for every guest you want to start) # mkdir -p /etc/vservers/myguest/apps/init # echo "default" > /etc/vservers/myguest/apps/init/mark
Note: Since all guests marked with "default" are started by default, nothing more has to be done. If you have different marks you should also update /etc/conf.d/vservers.
Keep portage in sync
The script vesync will help you to keep the metadata cache and overlays in sync. vemerge is a simple wrapper for emerge in guests.
(Sync metadata for 'myguest') # vesync myguest (Sync metadata for all guests) # vesync -a (Sync metadata for all guests except 'myguest') # vesync -a -e myguest (Sync 'myoverlay' for all guests) # vesync -a \ --overlay /usr/local/overlays/myoverlay \ --overlay-host rsync://rsync.myhost.com/myoverlay \ --overlay-only (emerge app-editors/vim in 'myguest') # vemerge myguest -- app-editors/vim -va
Update guests
Gentoo guests can share packages to save compilation time. In order to use shared packages, you have to create a central directory for packages on the host. We will use /var/cache/vpackages on the host and mount it to /usr/portage/packages in every guest.
# mkdir -p /var/cache/vpackages # $EDITOR /etc/vservers/myguest/fstab (Add this line at the end) /var/cache/vpackages /usr/portage/packages none bind,rw 0 0
Now you can use vupdateworld to update every guest. The command is equivalent to something like emerge --deep --update --newuse world depending on command line options.
(Pretend update for 'myguest') # vupdateworld -p myguest (Update 'myguest' using binary packages) # vupdateworld -k myguest (Update all guests using binary packages) # vupdateworld -ka
Note: In order to get binary packages you can either use PORTAGE_BINHOST (see man make.conf) or set FEATURES="buildpkg" in one or more guests.
After a successful update you can easily update all configuration files with vdispatch-conf. It is a simple wrapper for dispatch-conf and behaves exactly the same.
(Update configuration files for 'myguest') # vdispatch-conf myguest (Update configuration files for all guests) # vdispatch-conf -a
Bash scripts
These scripts will hopefully help some of you out with some basic tasks. Review each script carefully, so you know what it is doing.
Build Script
This will build virtual servers a little quicker with a shorter command and pre-saved parameters stored as variables.
Note: Edit this script to fit your environment.
genvs_create.sh
#!/bin/sh #Author: Dereck Martin #Email: dmartin@tekconxus.com VSERVER_TEMPLATE=/etc/vservers/.templates/stage4-i686-20070905.tar.bz2 VSERVER_HOST=${1} VSERVER_DOMAIN=domain.tld VSERVER_CONTEXT=${2} VSERVER_IP=${3} VSERVER_LOC=/vservers if [ "${1}" == "--help" ]; then echo "Usage:" echo " genvs_create.sh <host> <context id> <ip>" echo " " echo " <host> = Name of Virtual Server" echo " <context id> = Usually last digits of IP. (10.10.0.15 <-> 15)" echo " <ip> = IP Address 10.10.0.15/24" else vserver -v ${VSERVER_HOST} build --context ${VSERVER_CONTEXT} \ --hostname ${VSERVER_HOST}.${VSERVER_DOMAIN} --interface eth0:${VSERVER_IP} \ --initstyle gentoo -m template -- -d gentoo -t ${VSERVER_TEMPLATE} #Need to chop off the /xx fromt eh ip address before adding it to the sshd_config # #echo "ListenAddress ${3}" >> ${VSERVER_LOC}/${1}/etc/ssh/sshd_config vserver ${VSERVER_HOST} start fi
Gentoo Update World
The command for updating each virtual host did not work for me, so this script was created.
Note: Use at your own risk. Updating gentoo this way could break your system.
genvs_update.sh
#!/bin/sh VSERVER_LOC=/vservers echo -e '\E[33;40m' echo -e 'Gentoo Update Script for Virtual Servers' echo -e 'Author: Dereck Martin <dmartin@tekconxus.com>' echo -e '' echo -e '\E[34;40m' echo -e '####################################################################' echo -e '# Running Emerge Sync' echo -e '# This update the portage on the host' echo -e '####################################################################' echo -e '\E[31;40m' echo -e '\033[1mCtrl+C to Stop.\033[0m' echo -e '\E[32;40mStarting in:' for count in 5 4 3 2 1 do sleep 1 echo "> ${count}" done echo -e '\E[37;40m' emerge --sync echo -e '\E[34;40m' echo -e '####################################################################' echo -e '# Running VPS Sync' echo -e '# This will update the portage cache on all VPS' echo -e '####################################################################' echo -e '\E[31;40m' echo -e '\033[1mCtrl+C to Stop.\033[0m' echo -e '\E[32;40mStarting in:' for count in 5 4 3 2 1 do sleep 1 echo "> ${count}" done echo -e '\E[37;40m' vesync --all echo -e '\E[34;40m' echo -e '####################################################################' echo -e '# Running Emerge Update World' echo -e '# This will update every single package on your VPS' echo -e '####################################################################' echo -e '\E[31;40m' echo -e '\033[1mCtrl+C to Stop.\033[0m' echo -e '\E[32;40mStarting in:' for count in 5 4 3 2 1 do sleep 1 echo "> ${count}" done echo -e '\E[37;40m' vemerge --all -- --deep --update --newuse world vemerge --all -- --depclean # Still a little buggy... #for vs in ${VSERVER_LOC}/* #do # vserver ${vs} exec revdep-rebuild #done
Host and Resolv Update Script
I had troubles with getting my custom resolv.conf and hosts file to be auto generated at build time so I created this script to update them at any time when there are changes.
Note: Change locations as required.
genvsetc_cp.sh
#!/bin/sh #Author: Dereck Martin #Email: dmartin@tekconxus.com VSERVER_LOC=/vservers PWD=${CWD} cd ${VSERVER_LOC} for vs in * do cp -v /etc/vservers/.defaults/files/hosts ${VSERVER}/${vs}/etc/ cp -v /etc/vservers/.defaults/files/resolv.conf ${VSERVER}/${vs}/etc/ done cd ${PWD}
Shutdown/Reboot/Start All Scripts
This will let you perform a shutdown of all virtual guests
genvs_stopall.sh
#!/bin/sh #Author: Dereck Martin #Email: dmartin@tekconxus.com VSERVER_LOC=/vservers echo -e '\E[34;40m' echo -e '####################################################################' echo -e '# Stopping All Virtual Servers' echo -e '####################################################################' echo -e '\E[31;40m' echo -e '\033[1mCtrl+C to Stop.\033[0m' echo -e '\E[32;40mStarting in:' for count in 5 4 3 2 1 do sleep 1 echo -e "> ${count}" done echo -e '\E[37;40m' PWD=${CWD} cd ${VSERVER_LOC} for vs in * do vserver ${vs} stop done cd ${PWD}
genvs_startall.sh
#!/bin/sh #Author: Dereck Martin #Email: dmartin@tekconxus.com VSERVER_LOC=/vservers echo -e '\E[34;40m' echo -e '####################################################################' echo -e '# Starting All Virtual Servers' echo -e '####################################################################' echo -e '\E[31;40m' echo -e '\033[1mCtrl+C to Stop.\033[0m' echo -e '\E[32;40mStarting in:' for count in 5 4 3 2 1 do sleep 1 echo -e "> ${count}" done echo -e '\E[37;40m' PWD=${CWD} cd ${VSERVER_LOC} for vs in * do vserver ${vs} start done cd ${PWD}
genvs_rebootall.sh
#!/bin/sh #Author: Dereck Martin #Email: dmartin@tekconxus.com VSERVER_LOC=/vservers echo -e '\E[34;40m' echo -e '####################################################################' echo -e '# Rebooting All Virtual Servers' echo -e '####################################################################' echo -e '\E[31;40m' echo -e '\033[1mCtrl+C to Stop.\033[0m' echo -e '\E[32;40mStarting in:' for count in 5 4 3 2 1 do sleep 1 echo -e "> ${count}" done echo -e '\E[37;40m' PWD=${CWD} cd ${VSERVER_LOC} for vs in * do vserver ${vs} restart done cd ${PWD}
External Resources
Please take a look at the Gentoo Linux-VServer Howto for more information. In general we try to keep the wiki in sync, nevertheless it might help :)