Slackware guest on Linux-Vserver

Linux-Vserver is an open source software which acts as a virtual private server implementation done by adding operating system-level virtualization capabilities to the Linux kernel.

This means that all guests share the same kernel and they don't need to provide hardware support.

The purpose of this note is to show how to setup a guest based on Slackware into a Slackware host. What follows was tested on Slackware 14.1, 14.0, 13.37 and 13.1 (both 32b and 64b). I will assume that you have a Linux-Vserver box working. You can find here a quick and easy howto concerning Linux-Vserver installation and configuration (patching the kernel + utils-vserver installation).

Download

wget http://notes.sagredo.eu/sites/notes.sagredo.eu/files/linux-vserver/slack_vserver.tar.gz
tar xzf slack_vserver.tar.gz
cd slack_vserver
ls

You have downloaded the following files:

  • PKG_LIST is the package list to be installed in the guest
  • download_slack_pkg.sh is a script that you can use to download all the PKG_LIST. If you use this scriptlet all the package will be stored in the slackware[64]-version_pkg sub-folder.
  • make_slack_vserver.sh is the shell script that you have to adjust. It installs the guest.
  • rc is the startup script for the virtual server. It will be automatically copied in /etc/rc.d/init.d/rc
  • slackware-14.1.patch is the patch which modify rc.0, rc.6 rc.M, rc.S, rc.inet2 and rc.syslog. It must be applyed after the creation of the vserver process. In the patch I switched off all the mounts and executable that are related to the hardware. Comments would be welcome about this :-).

Download the packages

First of all select a minimal set of packages to be installed on the virtual server. This list of 110 packages is based on the Minimal System reported at http://www.slackwiki.com/Minimal_System without all hardware, kernel and multimedia related packages. The install leads to a guest of about 448M of size. This set fits with the installation of a complete virtual web server including apache, apache-tomcat, php, mysql, postgresql, qmail and related, ftp, named.

I assume that the packages to be installed are stored in the slackware{$ARCH}-{$VERSION}_pkg folder. If not, adjust its location editing the make_slack_vserver.sh script.

You can download my minimal set of packages running the shell script download_slack_pkg.sh. It can create a folder like slackware{$ARCH}-{$VERSION}_pkg for you, where $ARCH has to be "64" if you want to download 64b packages or empty otherwise, while $VERSION is the Slackware version, so it's something like "14.1".

#!/bin/bash
#
# v. 2013.12.29
# Now the script parses comments in the package list (thanks to Mark Colclough)

VERSION="14.1" # Slackware version
ARCH="64" # you can put 64 for 64b cpu just to separate 64/32 download folders

# Put here your favourite Slackware repository
SRC="ftp://ftp.slackware.no/slackware/slackware${ARCH}-${VERSION}/"

# put here your pkg list
LIST="${PWD}/PKG_LIST"

# the directory where you unpacked slack_vserver.tar.gz
# $PWD should work, otherwise put /path/to/slack_vserver
SETUP=$PWD

# the directory where you want to download the slackware packages
PACKAGES="${SETUP}/slackware${ARCH}-${VERSION}_pkg"

# create the folder where the pkg will be downloaded
if [ ! -d "$PACKAGES" ]; then
        mkdir -p $PACKAGES
fi

# create the "patches" sub-folder
if [ ! -d "${PACKAGES}/patches" ]; then
        mkdir -p "${PACKAGES}/patches"
fi

# download
cd $PACKAGES

if [ -f $LIST ]; then
        while read LINE
            do
            [ "$LINE" ] || continue
            [ "${LINE#\#}" = "$LINE" ] || continue
            wget "${SRC}slackware${ARCH}/${LINE}*.t?z"
        done < $LIST
else
        echo "Can't find $LIST file."
        exit 1
fi

# download packages from the patches folder
cd ${PACKAGES}/patches

if [ -f ${LIST} ]; then
        while read LINE
        do
                IFS='/' read -ra PKG <<< "$LINE"
                [ "${PKG#\#}" = "${PKG}" ] || continue
                PKG_LEN=${#PKG[@]}
                if [ $PKG_LEN == 2 ]; then
                        wget "${SRC}patches/packages/${PKG[1]}*.t?z"
                fi
        done < $LIST
else
        echo "Can't find $LIST file."
        exit 1
fi

Adjust the package PKG_LIST, enter your favorite ftp server and run from the command line

./download_slack_pkg.sh

NB: this script tries also to overwrite the packages downloaded from the /slackware folder with the updates belonging to the /patches dir.

Make the guest

Now let's create the guest and install the packages. As you know you must choose at least a "name", a "context" and an ip. In addition you have to modify most of the rc.* startup scripts removing all the hardware related daemons, and finally replace the /dev dir.

This is done adjusting and running the script make_slack_vserver.sh:

#!/bin/bash
#
# v. 2014.09.04
# Author: Roberto Puzzanghera
# Thanks to Mark Colclough for corrections
#
# This script installs a Slackware guest into a linux-vserver host (http://linux-vserver.org)
#
# Comments are welcome :-)
# More info here: http://notes.sagredo.eu/node/7
#
# guest now have chmod -x rc.inetd to avoid conflicts between host and guest using the same ports

# adjust this to where your things live
NAME=test
HOSTNAME=$NAME.YOURDOMAIN.XY
IP=10.0.0.182
INTERFACE=eth0:$IP/24
CONTEXT=5182
VERSION=14.1 # Slackware version
ARCH="64" # you can put 64 for 64b cpu just to separate 64/32 download folders

# where is the vservers dir? default is /vservers
VDIR="/usr/local/vservers"

# the directory where you unpacked slack_vserver.tar.gz
# $PWD should work, otherwise put /path/to/slack_vserver
SETUP=$PWD

# the directory where you downloaded the slackware packages
PACKAGES="${SETUP}/slackware${ARCH}-${VERSION}_pkg"

# the path to rc script file (leave as is)
RC="${SETUP}/rc"

################### end configuration

# sanity check

if [ ! -d "$VDIR" ]; then
        echo
        echo "Can't find VDIR dir: $VDIR"
        echo "Exiting"
    echo
        exit 1 
fi
if [ ! -d "$SETUP" ]; then
        echo  
        echo "Can't find SETUP dir: $SETUP"
        echo "Exiting"
    echo
        exit 1
fi
if [ ! -d "$PACKAGES" ]; then
        echo
        echo "Can't find PACKAGES dir: $PACKAGES"
        echo "Exiting"
        echo
        exit 1
fi
if [ ! -f "$RC" ]; then
        echo
        echo "Can't find RC path: $RC"
        echo "Exiting"
        echo
        exit 1
fi

# if everything is ok start the install

echo
read -p "press any key to make skeleton..."
vserver ${NAME} build -m skeleton \
        --hostname ${HOSTNAME} \
        --interface ${INTERFACE} \
        --context $CONTEXT \
        --flags lock,virt_mem,virt_uptime,virt_cpu,virt_load,sched_hard,hide_netif \
        --initstyle sysv
echo "...done"
echo

read -p "press any key to move the /dev folder to a temp dir the /dev folder..."
mv $VDIR/$NAME/dev $VDIR/$NAME/dev2

echo
read -p "press any key to install packages..."
cd $PACKAGES
installpkg --root $VDIR/$NAME *.t?z;
ROOT=$VDIR/$NAME upgradepkg patches/*.t?z;
echo "...done"
echo

echo
read -p "press any key to copy the rc script to /etc/rc.d/init.d..."
echo
echo "copying rc to /etc/rc.d/init.d/rc"
cp -p $RC $VDIR/$NAME/etc/rc.d/init.d/
echo "...done"

echo
echo "removing x flag to rc.inet1 rc.inetd rc.loop and rc.sshd"
chmod -x $VDIR/$NAME/etc/rc.d/rc.inet1 $VDIR/$NAME/etc/rc.d/rc.inetd $VDIR/$NAME/etc/rc.d/rc.loop $VDIR/$NAME/etc/rc.d/rc.sshd
echo "...done"
echo

echo "trying to adjust HOSTNAME, hosts, resolv.conf, profile. Check later..."
cp /etc/resolv.conf $VDIR/$NAME/etc/
cp /etc/localtime $VDIR/$NAME/etc/
rm $VDIR/$NAME/etc/profile
cp /etc/profile $VDIR/$NAME/etc/
echo $HOSTNAME >  $VDIR/$NAME/etc/HOSTNAME
echo "127.0.0.1 localhost" > $VDIR/$NAME/etc/hosts
echo "$IP $HOSTNAME $NAME" >> $VDIR/$NAME/etc/hosts
touch $VDIR/$NAME/etc/mtab
touch $VDIR/$NAME/etc/fstab
echo "...done"
echo

read -p "press any key to restore /dev2 to /dev"
rm -r $VDIR/$NAME/dev
mv $VDIR/$NAME/dev2 $VDIR/$NAME/dev

echo
echo -n "Do you want that I apply the patch for you y/n? [y] "
read VAR_PATCH

if [ "$VAR_PATCH" = 'y' ] || [ "$VAR_PATCH" = '' ]; then

    if [ ! -f "${SETUP}/linux-vserver_slackware-${VERSION}.patch" ]; then
        echo
        echo "Can't find any PATCH here: ${SETUP}/linux-vserver_slackware-${VERSION}.patch"
        echo "Exiting"
        echo
        exit 1
    fi

        cd ${VDIR}/${NAME}/etc/rc.d
        patch -p1 < ${SETUP}/linux-vserver_slackware-${VERSION}.patch
        echo "patch applyed."
        echo
        echo "You can start and enter the virtual server typing: "
        echo
        echo "vserver $NAME start"
        echo "vserver $NAME enter"
        
        else
                echo
                echo "DON'T FORGET to patch /etc/rc.d as follows: "
                echo
                echo "cd $VDIR/$NAME/etc/rc.d"
                echo "patch -p1 < $SETUP/linux-vserver_slackware-$VERSION.patch"
fi

echo
echo "More info at http://notes.sagredo.eu/node/7"
echo

Note that /etc/resolv.conf /etc/localtime /etc/profile are copied form the host.

Edit the script inserting at least the NAME, the IP and the CONTEXT. The packages' location should be ok if you downloaded them using my script.

./make_slack_vserver.sh

Apply the patch

The script itsself can install the patch for you. Anyway this is how to apply the patch by yourself:

cd /vservers/vserver_name/etc/rc.d
patch -p1 < /path/to/slack_vserver/slackware-14.1.patch

Inside the tarball you can find the old patch for Slackware 13.1 and 13.37, 14.0 if you like.

Post installation tasks

Put this inside your rc.local:

/usr/local/etc/init.d/vprocunhide  start

Start the new server

vserver <vserver_name> start
vserver <vserver_name> enter

Comments

slackware on other distro

Hey,

Thanks for this great article. Does anybody got expierence of having a slackware vserver on a other distro like Debian. My host is Debian, but I want some vserver running Slackware.

I've never tried but

Hi, I've never tried but I suppose that you have to install the slackware's pkgtools on your Debian and the above script should work as is..

Please post the details if you manage to do it!

cheers :)


no self-patch

Hey, when i tried to install the package, the patch was not installed and after me trying to install the patch myself it hangs up. Any idea on what i might be doing wrong?

Can you provide more details

Can you provide more details about the error you get, please? Everything was tested for Slackware 13.37 with the packages listed in the file PKG_LIST. I'm quite sure that it works, also yesterday I installed a slackware guest following my own directives..

cheers :)