2013-11-01

Slitaz -- lxc / templates

lxc-busybox
....
install_busybox()

1.
root@slitaz:/home/tux# ls /usr/lib/lxc/templates
lxc-busybox   lxc-fedora    lxc-lucid     lxc-natty
lxc-debian    lxc-lenny     lxc-maverick  lxc-sshd


2.
root@slitaz:/home/tux# ls /var/lib/lxc/slitaz-lxc/rootfs
bin      etc      lib      mnt      root     selinux  usr
dev      home     lib64    proc     sbin     tmp      var

    rootfs=$1
    name=$2
    res=0
    tree="\
$rootfs/selinux \
$rootfs/dev \
$rootfs/home \
$rootfs/root \
$rootfs/etc \
$rootfs/etc/init.d \
$rootfs/bin \
$rootfs/sbin \
$rootfs/proc \
$rootfs/mnt \
$rootfs/tmp \
$rootfs/var/log \
$rootfs/usr/share/udhcpc \
$rootfs/dev/pts \
$rootfs/dev/shm \
$rootfs/lib \
$rootfs/usr/lib \
$rootfs/lib64 \
$rootfs/usr/lib64"

    mkdir -p $tree || return 1
    chmod 755 $tree || return 1


3.
root@slitaz:/home/tux# ls -l /var/lib/lxc/slitaz-lxc/rootfs/dev
total 8
crw-rw-rw-    1 root     root        5,   1 Nov  1 12:47 console
crw-rw-rw-    1 root     root        1,   3 Nov  1 12:47 null
lrwxrwxrwx    1 root     root            13 Nov  1 13:12 ptmx -> /dev/pts/ptmx
drwxr-xr-x    2 root     root          4096 Nov  1 12:47 pts
brw-------    1 root     root        1,   0 Nov  1 12:47 ram0
drwxr-xr-x    2 root     root          4096 Nov  1 12:47 shm
crw-rw-rw-    1 root     root        5,   0 Nov  1 12:47 tty
crw-rw-rw-    1 root     root        4,   0 Nov  1 12:47 tty0
crw-r--r--    1 root     root        4,   0 Nov  1 12:47 tty1
crw-r--r--    1 root     root        4,   0 Nov  1 12:47 tty5

    # minimal devices needed for busybox
    mknod tty c 5 0       || res=1
    mknod console c 5 1   || res=1
    chmod 666 tty console || res=1
    mknod tty0 c 4 0      || res=1
    mknod tty1 c 4 0      || res=1
    mknod tty5 c 4 0      || res=1
    chmod 666 tty0        || res=1
    mknod ram0 b 1 0      || res=1
    chmod 600 ram0        || res=1
    mknod null c 1 3      || res=1
    chmod 666 null        || res=1


4.
root@slitaz:/home/tux# cat /var/lib/lxc/slitaz-lxc/rootfs/etc/passwd
root:x:0:0:root:/root:/bin/sh

    # root user defined
    cat <<EOF >> $rootfs/etc/passwd
root:x:0:0:root:/root:/bin/sh
EOF


5.
root@slitaz:/home/tux# cat /var/lib/lxc/slitaz-lxc/rootfs/etc/group
root:x:0:root

    cat <<EOF >> $rootfs/etc/group
root:x:0:root
EOF


6.
root@slitaz:/home/tux# cat /var/lib/lxc/slitaz-lxc/rootfs/etc/init.d/rcS
#!/bin/sh
/bin/syslogd
/bin/mount -a
/bin/udhcpc

    cat <<EOF >> $rootfs/etc/init.d/rcS
#!/bin/sh
/bin/syslogd
/bin/mount -a
/bin/udhcpc
EOF


7.
root@slitaz:/home/tux# cat /var/lib/lxc/slitaz-lxc/rootfs/etc/fstab
proc  /proc      proc    defaults     0      0
shm   /dev/shm   tmpfs   defaults     0      0

    # mount points
    cat <<EOF >> $rootfs/etc/fstab
proc  /proc      proc    defaults     0      0
shm   /dev/shm   tmpfs   defaults     0      0
EOF


8.
root@slitaz:/home/tux# cat /var/lib/lxc/slitaz-lxc/rootfs/etc/inittab
::sysinit:/etc/init.d/rcS
tty1::respawn:/bin/getty -L tty1 115200 vt100
console::askfirst:/bin/sh

    cat <<EOF >> $rootfs/etc/inittab
::sysinit:/etc/init.d/rcS
tty1::respawn:/bin/getty -L tty1 115200 vt100
console::askfirst:/bin/sh
EOF


9.
root@slitaz:/home/tux# cat /var/lib/lxc/slitaz-lxc/rootfs/usr/share/udhcpc/default.script
#!/bin/sh

case "$1" in
    deconfig)
        ip addr flush dev $interface
                ;;

    renew|bound)

                # flush all the routes
        if [ -n "$router" ]; then
                        ip route del default 2> /dev/null
        fi

                # check broadcast
                if [ -n "$broadcast" ]; then
                        broadcast="broadcast $broadcast"
                fi

                # add a new ip address
        ip addr add $ip/$mask $broadcast dev $interface

        if [ -n "$router" ]; then
                        ip route add default via $router dev $interface
                fi

        [ -n "$domain" ] && echo search $domain > /etc/resolv.conf
        for i in $dns ; do
            echo nameserver $i >> /etc/resolv.conf
        done
        ;;
esac
exit 0

----

    cat <<EOF >> $rootfs/usr/share/udhcpc/default.script
#!/bin/sh

case "\$1" in
    deconfig)
        ip addr flush dev \$interface
                ;;

    renew|bound)

                # flush all the routes
        if [ -n "\$router" ]; then
                        ip route del default 2> /dev/null
        fi

                # check broadcast
                if [ -n "\$broadcast" ]; then
                        broadcast="broadcast \$broadcast"
                fi

                # add a new ip address
        ip addr add \$ip/\$mask \$broadcast dev \$interface

        if [ -n "\$router" ]; then
                        ip route add default via \$router dev \$interface
                fi

        [ -n "\$domain" ] && echo search \$domain > /etc/resolv.conf
        for i in \$dns ; do
            echo nameserver \$i >> /etc/resolv.conf
        done
        ;;
esac
exit 0
EOF