Installation on Slackware

From Linux-VServer

Revision as of 20:12, 21 October 2011 by Glenn (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a quick-and-dirty Slackware Vserver Howto as I haven't seen anything about vserver on slack. The advantage of this approach is that you can easily setup new vsevers and keep all of them up to date with the slackware packaging system, with just a few commands. There is also a portuguese version of this howto.

Note that this howto is a from scratch way to do the job, there's a tool called simplepkg that uses templates do create vservers and have some scripts to keep all the jails updated.

Contents

Setting up Vserver

First I assume you have successfully compiled and booted a kernel with vserver patch, installed the util-vserver package and created a /vservers with the chroot-barrier.

Selecting packages

Then, put all your preffered slack packages on some dir, eg /slackware, respecting the default disk sets hierarchy. You can leave just the most essential packs, like some of the a, ap, n and l sets.

Now copy and edit the /etc/profile and all the rc.d's scripts you want to some place, for example /scripts. Do a chmod +x to any script you want to start at the vserver initialization, and a -x to what you dont want.

Create a default skeleton for your vserver's config (skel.conf) and put it the the same dir of the scripts. You'll also need a tgz file with a small /dev folder containing the following devices/subfolders:

crw-r--r--  1 root root 1, 7 2004-09-13 00:00 full
-rw-r--r--  1 root root    0 2004-09-13 00:00 hdv1
srw-rw-rw-  1 root root    0 2005-07-23 09:35 log
crw-r--r--  1 root root 1, 3 2004-09-13 00:00 null
crw-r--r--  1 root root 5, 2 2004-09-13 00:00 ptmx
drwxr-xr-x  2 root root    0 2005-07-22 18:28 pts
crw-r--r--  1 root root 1, 8 2004-09-13 00:00 random
crw-r--r--  1 root root 5, 0 2004-09-26 15:15 tty
crw-r--r--  1 root root 1, 9 2004-09-13 00:00 urandom
crw-r--r--  1 root root 1, 5 2004-09-13 00:00 zero

Mkjail script

Create the following /usr/local/bin/mkjail script:

#!/bin/bash
#          
# mkjail v0.2: chroot jail maker (slack 10.1.0)                                                                            
# feedback: rhatto at riseup.net | GPL                                                                                     
#                                                                                                                          

# adjust this to where your things live
PACKAGES="/storage/vserver/slack/"
DEVICES="/storage/vserver/devices.tar.gz"
SCRIPTS="/storage/vserver/etc/"
GPGKEY="/storage/vserver/slack/GPG-KEY" 
SKEL="/storage/vserver/skel.conf"

if (($# != 1)); then                                                                                                          
  echo "usage: $0 <server-name>"                                                                                                
  exit 1                                                                                                                   
fi                                                                                                                         

server=$1                                                                                                                  
mkdir /vservers/$server                                                                                                       

echo "instaling packages..." 
cd $PACKAGES
for dir in a ap n extra contrib; do
  cd $dir; installpkg -root /vservers/$server *tgz; cd ..                                                                  
done                                                                                                                       

echo "creating /etc/ and copying init scripts"
rsync -Cav $SCRIPTS/ /vservers/$server/etc/                                                                    
cp /etc/resolv.conf /vservers/$server/etc/
cp /etc/localtime /vservers/$server/etc/
echo /dev/hdv1 / ext2 defaults 1 1 > /vservers/$server/etc/fstab                                                           
echo /dev/hdv1 / ext2 rw 0 0 > /vservers/$server/etc/mtab                                                                  

echo "creating devices and dependencies"
cd /vservers/$server/                                                                                                      
tar zxvf $DEVICES
chroot /vservers/$server/ sbin/ldconfig                                                                                    

echo "creating /etc/vservers/$server.conf"                                                                                     
cp $SKEL /etc/vservers/$server.conf                                                                   

echo "importing slack gpg pubkey"                                                                                  
mkdir /vservers/$server/root/.gnupg                                                                                        
gpg --homedir /vservers/$server/root/.gnupg --import $GPGKEY

# todo: add rebootmgr
echo "done; now edit /etc/vservers/$server.conf"
echo "then, set iptables rules and start $server vserver"
echo "dont forget to change root's password" 

The trick is that you can ask installpkg to install a tgz in a rootdir other than /.

Creating vservers

Now you simple need to do a

mkjail your-server

and then edit /etc/vservers/your-server.conf, assigning an ip to it, choosing the capabilities, etc, and

vserver your-server start

Now you have a slackware vserver.

For the first time you start or stop your vserver maybe you get some errors from the scripts like rc.6 trying to umount devices or something like. Just remove these commands from the scripts and everything works fine.

Upgrading vservers

To upgrade your vservers, simple use something like this fabulous script:

#!/bin/sh
#
# vserver-upgrade v0.2: fabulous script for slack vserver upgrade
# feedback: rhatto at riseup.net | GPL
#
# Uses some functions from pkgtools, which license is:
#
# Copyright 1999  Patrick Volkerding, Moorhead, Minnesota, USA 
# Copyright 2001, 2002, 2003  Slackware Linux, Inc., Concord, California, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

PACKAGE_DIR=/storage/packages/patches/

# pkgtool stuff
package_name() {
  STRING=`basename $1 .tgz`
  # Check for old style package name with one segment:
  if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then
    echo $STRING
  else # has more than one dash delimited segment
    # Count number of segments:
    INDEX=1
    while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do
      INDEX=`expr $INDEX + 1`
    done
    INDEX=`expr $INDEX - 1` # don't include the null value
    # If we don't have four segments, return the old-style (or out of spec) package name:
    if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then
      echo $STRING
    else # we have four or more segments, so we'll consider this a new-style name:
      NAME=`expr $INDEX - 3`
      NAME="`echo $STRING | cut -f 1-$NAME -d -`"
      echo $NAME
    fi
  fi
}

# vserver stuff
cd $PACKAGE_DIR
for file in `ls *tgz`; do
  pack=`package_name $file`
  for installed in `ls /var/log/packages/$pack* 2> /dev/null`; do
    if [[ "$pack" == "`package_name $installed.tgz`" ]]; then
      if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
        upgradepkg $file
      fi
    fi
  done
  for vserver in `ls /vservers`; do
    for installed in `ls /vservers/$vserver/var/log/packages/$pack* 2> /dev/null`; do
      if [[ $pack == `package_name $installed.tgz` ]]; then
        if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then
          ROOT=/vservers/$vserver upgradepkg $file
        fi
      fi
    done
  done
done

Hints

Config format

If you're using the new configuration method for your vservers and want to use the sysv init style, you should create the following /etc/rc.d/rc script inside your vserver:

#!/bin/bash

if [ "$1" == "3" ]; then
  /etc/rc.d/rc.M
elif [ "$1" == "6" ]; then
  /etc/rc.d/rc.6
else
  echo "Invalid level."
  exit 1
fi

Passive FTP

Don't forget to put a

export FTP_PASSIVE=1

on your default /etc/profile.

Contact

Any questions/comments: mailto:rhatto@riseup.net

Personal tools