3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# lxc: linux Container library
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Daniel Lezcano <daniel.lezcano@free.fr>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Template for slackware by Matteo Bernardini <ponce@slackbuilds.org>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# some parts are taken from the debian one (used as model)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# This library is free software; you can redistribute it and/or
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# modify it under the terms of the GNU Lesser General Public
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# License as published by the Free Software Foundation; either
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# version 2.1 of the License, or (at your option) any later version.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# This library is distributed in the hope that it will be useful,
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# but WITHOUT ANY WARRANTY; without even the implied warranty of
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Lesser General Public License for more details.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# You should have received a copy of the GNU Lesser General Public
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# License along with this library; if not, write to the Free Software
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Detect use under userns (unsupported)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "This template can't be used for unprivileged containers." 1>&2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "You may want to try the \"download\" template instead." 1>&2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Add some directories to PATH in case we create containers with sudo
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Use the primary Slackware site by default, but please consider changing
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# this to a closer mirror site.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniMIRROR=${MIRROR:-http://ftp.slackware.com/pub/slackware}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$arch" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# The next part contains excerpts taken from SeTconfig (written by
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Patrick Volkerding) from the slackware setup disk.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# But before pasting them just set a variable to use them as they are
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini( cd $T_PX ; chmod 755 ./ )
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -d $T_PX/usr/src/linux ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -d $T_PX/proc ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -d $T_PX/sys ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -d $T_PX/var/spool/mail ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "#!/bin/sh" > $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "# Load the keyboard map. More maps are in /usr/share/kbd/keymaps." \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "if [ -x /usr/bin/loadkeys ]; then" >> $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho " /usr/bin/loadkeys us" >> $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Network configuration is left to the user, that have to edit
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# /etc/rc.d/rc.inet1.conf and /etc/resolv.conf of the container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# just set the hostname
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini$hostname.example.net
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicp $rootfs/etc/HOSTNAME $rootfs/etc/hostname
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# make needed devices, from Chris Willing's MAKEDEV.sh
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# http://www.vislab.uq.edu.au/howto/lxc/MAKEDEV.sh
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/null c 1 3
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/zero c 1 5
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/random c 1 8
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/urandom c 1 9
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty c 5 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 600 ${DEV}/console c 5 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty0 c 4 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty1 c 4 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty2 c 4 2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty3 c 4 3
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty4 c 4 4
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty5 c 4 5
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/full c 1 7
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 660 ${DEV}/loop0 b 7 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 660 ${DEV}/loop1 b 7 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardininone /run tmpfs defaults,mode=0755 0 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# simplify rc.6 and rc.S, http://www.vislab.uq.edu.au/howto/lxc/create_container.html
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# and some other small fixes for a clean boot
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.6 2012-08-15 01:03:12.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.6 2013-02-17 10:26:30.888839354 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -9,6 +9,12 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Modified by: Patrick J. Volkerding, <volkerdi@slackware.com>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>,
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# based also on Chris Willing's modifications
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# http://www.vislab.uq.edu.au/howto/lxc/rc.6
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -37,6 +43,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Save the system time to the hardware clock using hwclock --systohc.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/hwclock ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Check for a broken motherboard RTC clock (where ioports for rtc are
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -53,6 +62,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /etc/rc.d/rc.local_shutdown ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -148,6 +159,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /etc/rc.d/rc.pcmcia ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -155,11 +169,16 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/accton -a -r /var/log/pacct ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /etc/rc.d/rc.acpid -a -r /var/run/acpid.pid ]; then # quit
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -170,6 +189,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Sending all processes the SIGTERM signal."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -179,6 +200,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if /bin/grep -q quota /etc/fstab ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/quotaoff ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -187,6 +211,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Saving random seed from /dev/urandom in /etc/random-seed."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Use the pool size from /proc, or 512 bytes:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -205,6 +231,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -216,6 +245,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Remounting root filesystem read-only."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -240,12 +271,17 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # This never hurts again (especially since root-on-LVM always fails
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # to deactivate the / logical volume... but at least it was
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -258,6 +294,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # This is to ensure all processes have completed on SMP machines:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/genpowerd ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -274,6 +313,13 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# confirm successful shutdown of the container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+echo ; echo "* container stopped. *" ; echo
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Now halt (poweroff with APM or ACPI enabled kernels) or reboot.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.S 2012-09-13 21:38:34.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.S 2013-02-17 09:39:41.579799641 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -4,9 +4,18 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Mostly written by: Patrick J. Volkerding, <volkerdi@slackware.com>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>,
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# based also on Chris Willing's modifications
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# http://www.vislab.uq.edu.au/howto/lxc/rc.S
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/mount -v proc /proc -n -t proc 2> /dev/null
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -254,10 +263,27 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ # We really don't want to start udev in the container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ if [ -f /etc/rc.d/rc.udev ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ if [ -f /etc/rc.d/rc.alsa ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ if [ -f /etc/rc.d/rc.loop ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Any /etc/mtab that exists here is old, so we start with a new one:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/rm -f /etc/mtab{,~,.tmp} && /bin/touch /etc/mtab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -337,6 +363,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -364,7 +392,7 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # if the first line of that file begins with the word 'Linux'.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # You are free to modify the rest of the file as you see fit.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /bin/sed ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini- /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr)\./}" /etc/motd
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr) lxc container\./}" /etc/motd
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If there are SystemV init scripts for this runlevel, run them.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -372,6 +400,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # CAREFUL! This can make some systems hang if the rc.serial script isn't
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # set up correctly. If this happens, you may have to edit the file from a
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -380,6 +411,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Carry an entropy pool between reboots to improve randomness.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -f /etc/random-seed ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Using /etc/random-seed to initialize /dev/urandom."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.M 2012-09-25 19:47:07.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.M 2013-02-17 09:39:41.579799641 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -10,6 +10,10 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Heavily modified by Patrick Volkerding <volkerdi@slackware.com>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Tell the viewers what's going to happen.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -20,6 +24,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Screen blanks after 15 minutes idle time, and powers down in one hour
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # if the kernel supports APM or ACPI power management:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/setterm -blank 15 -powersave powerdown -powerdown 60
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -33,6 +40,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Set the permissions on /var/log/dmesg according to whether the kernel
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # permits non-root users to access kernel dmesg information:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -r /proc/sys/kernel/dmesg_restrict ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -135,6 +144,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If APM is enabled in the kernel, start apmd:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -e /proc/apm ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -146,6 +158,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if find /usr/share/icons 2> /dev/null | grep -q icon-theme.cache ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.inet1 2012-08-05 19:13:27.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.inet1 2013-02-17 09:39:41.579799641 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -3,6 +3,11 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # This script is used to bring up the various network interfaces.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # @(#)/etc/rc.d/rc.inet1 10.2 Sun Jul 24 12:45:56 PDT 2005 (pjv)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -105,6 +110,10 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If the interface is a bridge, then create it first:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If the interface isn't in the kernel yet (but there's an alias for it in
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -115,6 +124,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # interface exists
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if ! /sbin/ifconfig | grep -w "${1}" 1>/dev/null || \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini ! /sbin/ifconfig ${1} | grep -w inet 1> /dev/null ; then # interface not up or not configured
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini( cd $rootfs ; patch -p1 < tmp/rcs.patch ; rm tmp/rcs.patch )
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# restart rc.inet1 to have routing for the loop device
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "/etc/rc.d/rc.inet1 restart" >> $rootfs/etc/rc.d/rc.local
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# reduce the number of local consoles: two should be enough
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i '/^c3\|^c4\|^c5\|^c6/s/^/# /' $rootfs/etc/inittab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# better not use this in a container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i 's/.*genpowerfail.*//' $rootfs/etc/inittab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# add a message to rc.local that confirms successful container startup
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "echo ; echo \"* container $name started. *\" ; echo" >> $rootfs/etc/rc.d/rc.local
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# borrow the time configuration from the local machine
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# make a local copy of the installed filesystem
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicp -a $cache/rootfs-$release-$arch/* $rootfs/ || exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# fix fstab with the actual path
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i "s|$cache/rootfs-$release-$arch|$rootfs|" $rootfs/etc/fstab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimkdir -p $cache/cache-$release-$arch $cache/rootfs-$release-$arch \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini $cache/slackpkg-$release-$arch $CONF/templates
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "$MIRROR/$PKGMAIN-$release/" > $CONF/mirrors
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniTEMP=$cache/cache-$release-$arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniWORKDIR=$cache/slackpkg-$release-$arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniPRIORITY=( patches %PKGMAIN extra pasture testing )
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniONLY_NEW_DOTNEW=off
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniDOWNLOAD_ALL=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniDEFAULT_ANSWER=y
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniUSE_INCLUDES=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# thanks to Vincent Batts for this list of packages
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# (that I modified a little :P)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# http://connie.slackware.com/~vbatts/minimal/
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat <<EOF > $CONF/templates/minimal-lxc.template
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardininetwork-scripts
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinisysvinit-functions
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinisysvinit-scripts
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -f /etc/slackpkg/templates/$TEMPLATE.template ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini cat /etc/slackpkg/templates/$TEMPLATE.template \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# clean previous installs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# add a slackpkg default mirror
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "$MIRROR/$PKGMAIN-$release/" >> $ROOT/etc/slackpkg/mirrors
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# blacklist the devs package (we have to use our premade devices).
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# do the same with the kernel packages (we use the host's one),
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# but leave available headers and sources
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "devs" >> $ROOT/etc/slackpkg/blacklist
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# force klog to use the system call interface to the kernel message
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# buffers - needed for unprivileged containers
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i 's|3\ \-x|3 -x -s|' $ROOT/etc/rc.d/rc.syslog || true
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.utsname = $name
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.arch = $arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.mount = $rootfs/etc/fstab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.include = ${LXC_TEMPLATE_CONFIG}/slackware.common.conf
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -e $cache ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# lock, so we won't purge while someone is creating a repository
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? != 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini$1 -h|--help -p|--path=<path> --clean
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinioptions=$(getopt -o hp:n:a:r:c -l help,rootfs:,path:,name:,arch:,release:,clean -- "$@")
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini --) shift 1; break ;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "'installpkg' command is missing."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "'slackpkg' command is missing."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$path" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "'path' parameter is required."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "This script should be run as 'root'."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# If no release version was specified, use current
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$name" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # no name given? set a default one
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# detect rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$rootfs" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini rootfs=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to install slackware."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniconfigure_slackware $cache/rootfs-$release-$arch $name
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to configure slackware for a container."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to copy rootfs."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to write configuration file."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -z $clean ]; then