Error when starting LXC container (Too many levels of symbolic links - init in /usr/lib/x86_64-linux-gnu/lxc/sbin/init was a symbolic link!)

I can create the container but could not start it.

I have used a different template.
lxc-minimal.sh template
#!/bin/sh

#
# lxc: linux Container library

# Authors:
# Daniel Lezcano daniel.lezcano@free.fr

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# Detect use under userns (unsupported)
for arg in “$@”; do
[ “$arg” = “–” ] && break
if [ “$arg” = “–mapped-uid” -o “$arg” = “–mapped-gid” ]; then
echo “This template can’t be used for unprivileged containers.” 1>&2
echo “You may want to try the “download” template instead.” 1>&2
exit 1
fi
done

# Make sure the usual locations are in PATH
export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin

install_minimal()
{
rootfs=$1

tree="\

$rootfs/var/run/minimal
$rootfs/var/empty/minimal
$rootfs/var/lib/empty/minimal
$rootfs/etc/init.d
$rootfs/etc/rc.d
$rootfs/etc/sysconfig/network-scripts
$rootfs/dev/shm
$rootfs/run/shm
$rootfs/proc
$rootfs/sys
$rootfs/bin
$rootfs/sbin
$rootfs/usr
$rootfs/tmp
$rootfs/home
$rootfs/root
$rootfs/lib
$rootfs/lib64"

mkdir -p $tree
if [ $? -ne 0 ]; then
    return 1
fi

return 0

}

configure_minimal()
{
rootfs=$1

cat <<EOF > $rootfs/etc/passwd

root:x:0:0:root:/root:/bin/bash
EOF

cat <<EOF > $rootfs/etc/group

root:x:0:root
EOF

return 0

}

copy_configuration()
{
path=$1
rootfs=$2
name=$3

grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config

cat <> $path/config
lxc.utsname = $name
lxc.pts = 1024
lxc.kmsg = 0
lxc.cap.drop = sys_module mac_admin mac_override sys_time
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
lxc.mount.entry = /dev dev none ro,bind 0 0
lxc.mount.entry = /lib lib none ro,bind 0 0
lxc.mount.entry = /bin bin none ro,bind 0 0
lxc.mount.entry = /usr usr none ro,bind 0 0
lxc.mount.entry = /sbin sbin none ro,bind 0 0
lxc.mount.entry = /usr/share/lxc/templates/lxc-minimal sbin/init none ro,bind 0 0
lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
lxc.mount.entry = sysfs sys sysfs ro 0 0
lxc.mount.entry = /etc/init.d etc/init.d none ro,bind 0 0
EOF

# Oracle Linux and Fedora need the following two bind mounted
if [ -d /etc/sysconfig/network-scripts ]; then
    cat <<EOF >> $path/config

lxc.mount.entry = /etc/sysconfig/network-scripts etc/sysconfig/network-scripts none ro,bind 0 0
EOF
fi

if [ -d /etc/rc.d ]; then
    cat <<EOF >> $path/config

lxc.mount.entry = /etc/rc.d etc/rc.d none ro,bind 0 0
EOF
fi

# if no .ipv4 section in config, then have the container run dhcp
grep -q "^lxc.network.ipv4" $path/config || touch $rootfs/run-dhcp

if [ "$(uname -m)" = "x86_64" ]; then
    cat <<EOF >> $path/config

lxc.mount.entry = /lib64 lib64 none ro,bind 0 0
EOF
fi
}

usage()
{
cat <<EOF
$1 -h|–help -p|–path= [–rootfs=]
EOF
return 0
}

check_for_cmd()
{
cmd_path=type $1
if [ $? -ne 0 ]; then
echo “The command ‘$1’ $cmd_path is not accessible on the system”
exit 1
fi
# we use cut instead of awk because awk is alternatives symlink on ubuntu
# and /etc/alternatives isn’t bind mounted
cmd_path=echo $cmd_path |cut -d ' ' -f 3
}

options=$(getopt -o hp:n:S: -l help,rootfs:,path:,name: – “$@”)
if [ $? -ne 0 ]; then
usage $(basename $0)
exit 1
fi
eval set – “$options”

while true
do
case “$1” in
-h|–help) usage $0 && exit 0;;
-p|–path) path=$2; shift 2;;
–rootfs) rootfs=$2; shift 2;;
-n|–name) name=$2; shift 2;;
–) shift 1; break ;;
*) break ;;
esac
done

if [ “$(id -u)” != “0” ]; then
echo “This script should be run as ‘root’”
exit 1
fi

cat << ‘EOF’ > /tmp/boringd
#! /usr/bin/env bash
/usr/bin/daemon – watch ls /tmp
EOF
chmod +x /tmp/boringd

if [ $0 = “/sbin/init” ]; then

PATH="$PATH:/bin:/sbin:/usr/sbin"
check_for_cmd /usr/lib/lxc/lxc-init
check_for_cmd /tmp/boringd
daemon_path=$cmd_path
echo "init'ing with ${daemon_path}"

exec /usr/lib/lxc/lxc-init -- $daemon_path
exit 1

fi

if [ -z “$path” ]; then
echo “‘path’ parameter is required”
exit 1
fi

# detect rootfs
config="$path/config"
if [ -z “$rootfs” ]; then
if grep -q ‘^lxc.rootfs’ $config 2>/dev/null ; then
rootfs=$(awk -F= ‘/^lxc.rootfs =/{ print $2 }’ $config)
else
rootfs=$path/rootfs
fi
fi

install_minimal $rootfs
if [ $? -ne 0 ]; then
echo “failed to install minimal’s rootfs”
exit 1
fi

configure_minimal $rootfs
if [ $? -ne 0 ]; then
echo “failed to configure minimal template”
exit 1
fi

copy_configuration $path $rootfs $name
if [ $? -ne 0 ]; then
echo “failed to write configuration file”
exit 1
fi
end of template

running command as root: lxc-start -n my-container -d -l trace -o debug.out
lxc-start 20170623081935.192 INFO lxc_start_ui - tools/lxc_start.c:main:275 - using rcfile /home/intern/.local/share/lxc/LXC/config
lxc-start 20170623081935.192 ERROR lxc_start_ui - tools/lxc_start.c:main:317 - Executing ‘/sbin/init’ with no configuration file may crash the host
lxc-start 20170623081943.706 INFO lxc_start_ui - tools/lxc_start.c:main:275 - using rcfile /var/lib/lxc/LXC/config
lxc-start 20170623081943.706 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:309 - Going to wait for pid 28616.
lxc-start 20170623081943.706 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:328 - Trying to sync with child process.
lxc-start 20170623081943.706 INFO lxc_start - start.c:lxc_check_inherited:235 - Closed inherited fd: 3.
lxc-start 20170623081943.706 INFO lxc_start - start.c:lxc_check_inherited:235 - Closed inherited fd: 5.
lxc-start 20170623081943.706 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:366 - Using pipe file descriptor 6 for monitord.
lxc-start 20170623081943.708 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:343 - Sucessfully synced with child process.
lxc-start 20170623081943.709 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:312 - Finished waiting on pid 28616.
lxc-start 20170623081943.709 INFO lxc_container - lxccontainer.c:do_lxcapi_start:804 - Attempting to set proc title to [lxc monitor] /var/lib/lxc LXC
lxc-start 20170623081943.709 INFO lxc_start - start.c:lxc_check_inherited:235 - Closed inherited fd: 3.
lxc-start 20170623081943.709 INFO lxc_lsm - lsm/lsm.c:lsm_init:48 - LSM security driver AppArmor
lxc-start 20170623081943.709 DEBUG lxc_start - start.c:setup_signal_fd:273 - Set SIGCHLD handler with file descriptor: 5.
lxc-start 20170623081943.709 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:309 - Going to wait for pid 28620.
lxc-start 20170623081943.709 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:328 - Trying to sync with child process.
lxc-start 20170623081943.709 INFO lxc_start - start.c:lxc_check_inherited:235 - Closed inherited fd: 3.
lxc-start 20170623081943.709 INFO lxc_start - start.c:lxc_check_inherited:235 - Closed inherited fd: 5.
lxc-start 20170623081943.709 DEBUG console - console.c:lxc_console_peer_default:468 - no console peer
lxc-start 20170623081943.709 INFO lxc_start - start.c:lxc_init:475 - Container “LXC” is initialized.
lxc-start 20170623081943.709 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:366 - Using pipe file descriptor 6 for monitord.
lxc-start 20170623081943.710 DEBUG lxc_start - start.c:__lxc_start:1317 - Not dropping CAP_SYS_BOOT or watching utmp.
lxc-start 20170623081943.712 INFO lxc_conf - conf.c:instantiate_veth:2647 - Retrieved mtu 1500 from lxcbr0
lxc-start 20170623081943.712 INFO lxc_conf - conf.c:instantiate_veth:2672 - Attached ‘veth17YY3G’: to the bridge ‘lxcbr0’:
lxc-start 20170623081943.712 DEBUG lxc_conf - conf.c:instantiate_veth:2689 - instantiated veth ‘veth17YY3G/vethXE1GU4’, index is ‘23’
lxc-start 20170623081943.712 INFO lxc_cgroup - cgroups/cgroup.c:cgroup_init:68 - cgroup driver cgroupfs-ng initing for LXC
lxc-start 20170623081943.712 ERROR lxc_cgfsng - cgroups/cgfsng.c:create_path_for_hierarchy:1306 - Path “/sys/fs/cgroup/systemd//lxc/LXC” already existed.
lxc-start 20170623081943.712 ERROR lxc_cgfsng - cgroups/cgfsng.c:cgfsng_create:1363 - No such file or directory - Failed to create /sys/fs/cgroup/systemd//lxc/LXC: No such file or directory
lxc-start 20170623081943.712 DEBUG lxc_cgfsng - cgroups/cgfsng.c:filter_and_set_cpus:474 - No isolated cpus detected.
lxc-start 20170623081943.712 DEBUG lxc_cgfsng - cgroups/cgfsng.c:handle_cpuset_hierarchy:644 - “cgroup.clone_children” was already set to “1”.
lxc-start 20170623081943.713 INFO lxc_start - start.c:lxc_spawn:1154 - Cloned CLONE_NEWNS.
lxc-start 20170623081943.713 INFO lxc_start - start.c:lxc_spawn:1154 - Cloned CLONE_NEWPID.
lxc-start 20170623081943.713 INFO lxc_start - start.c:lxc_spawn:1154 - Cloned CLONE_NEWUTS.
lxc-start 20170623081943.713 INFO lxc_start - start.c:lxc_spawn:1154 - Cloned CLONE_NEWIPC.
lxc-start 20170623081943.713 INFO lxc_start - start.c:lxc_spawn:1154 - Cloned CLONE_NEWNET.
lxc-start 20170623081943.713 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:343 - Sucessfully synced with child process.
lxc-start 20170623081943.714 DEBUG lxc_monitor - monitor.c:lxc_monitord_spawn:312 - Finished waiting on pid 28620.
lxc-start 20170623081943.714 INFO lxc_monitor - monitor.c:lxc_monitor_sock_name:185 - Using monitor socket name “lxc/ad055575fe28ddd5//var/lib/lxc”.
lxc-start 20170623081943.752 DEBUG lxc_conf - conf.c:lxc_assign_network:3185 - move ‘vethXE1GU4’/’(null)’ to ‘28632’: .
lxc-start 20170623081943.752 DEBUG lxc_conf - conf.c:setup_rootfs:1273 - mounted ‘/var/lib/lxc/LXC/rootfs’ on ‘/usr/lib/x86_64-linux-gnu/lxc’
lxc-start 20170623081943.752 INFO lxc_conf - conf.c:setup_utsname:901 - ‘LXC’ hostname has been setup
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:setup_hw_addr:2225 - mac address ‘00:16:3e:ed:c3:28’ on ‘eth0’ has been setup
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:setup_netdev:2452 - ‘eth0’ has been setup
lxc-start 20170623081943.784 INFO lxc_conf - conf.c:setup_network:2473 - network has been setup
lxc-start 20170623081943.784 INFO lxc_conf - conf.c:mount_autodev:1130 - Mounting container /dev
lxc-start 20170623081943.784 INFO lxc_conf - conf.c:mount_autodev:1153 - Mounted tmpfs onto /usr/lib/x86_64-linux-gnu/lxc/dev
lxc-start 20170623081943.784 INFO lxc_conf - conf.c:mount_autodev:1171 - Mounted container /dev
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1715 - remounting /dev on /usr/lib/x86_64-linux-gnu/lxc/dev to respect bind or remount options
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1730 - (at remount) flags for /dev was 4098, required extra flags are 3
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1765 - mounted ‘/dev’ on ‘/usr/lib/x86_64-linux-gnu/lxc/dev’, type ‘none’
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1715 - remounting /lib on /usr/lib/x86_64-linux-gnu/lxc/lib to respect bind or remount options
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1730 - (at remount) flags for /lib was 4096, required extra flags are 1
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1765 - mounted ‘/lib’ on ‘/usr/lib/x86_64-linux-gnu/lxc/lib’, type ‘none’
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1715 - remounting /bin on /usr/lib/x86_64-linux-gnu/lxc/bin to respect bind or remount options
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1730 - (at remount) flags for /bin was 4096, required extra flags are 1
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1765 - mounted ‘/bin’ on ‘/usr/lib/x86_64-linux-gnu/lxc/bin’, type ‘none’
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1715 - remounting /usr on /usr/lib/x86_64-linux-gnu/lxc/usr to respect bind or remount options
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1730 - (at remount) flags for /usr was 4096, required extra flags are 1
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1765 - mounted ‘/usr’ on ‘/usr/lib/x86_64-linux-gnu/lxc/usr’, type ‘none’
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1715 - remounting /sbin on /usr/lib/x86_64-linux-gnu/lxc/sbin to respect bind or remount options
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1730 - (at remount) flags for /sbin was 4096, required extra flags are 1
lxc-start 20170623081943.784 DEBUG lxc_conf - conf.c:mount_entry:1765 - mounted ‘/sbin’ on ‘/usr/lib/x86_64-linux-gnu/lxc/sbin’, type ‘none’
lxc-start 20170623081943.784 ERROR lxc_utils - utils.c:open_without_symlink:1682 - Too many levels of symbolic links - init in /usr/lib/x86_64-linux-gnu/lxc/sbin/init was a symbolic link!
lxc-start 20170623081943.784 ERROR lxc_conf - conf.c:mount_entry:1708 - Too many levels of symbolic links - failed to mount ‘/usr/share/lxc/templates/lxc-minimal’ on ‘/usr/lib/x86_64-linux-gnu/lxc/sbin/init’
lxc-start 20170623081943.784 ERROR lxc_conf - conf.c:lxc_setup:3869 - failed to setup the mount entries for ‘LXC’
lxc-start 20170623081943.784 ERROR lxc_start - start.c:do_start:811 - Failed to setup container “LXC”.
lxc-start 20170623081943.784 ERROR lxc_sync - sync.c:__sync_wait:57 - An error occurred in another process (expected sequence number 3)
lxc-start 20170623081943.784 INFO lxc_conf - conf.c:lxc_delete_network:3005 - Interface “(null)” with index 23 already deleted or existing in different network namespace.
lxc-start 20170623081943.836 INFO lxc_conf - conf.c:lxc_delete_network:3040 - Removed interface “veth17YY3G” from host.
lxc-start 20170623081943.836 ERROR lxc_start - start.c:__lxc_start:1346 - Failed to spawn container “LXC”.
lxc-start 20170623081943.868 WARN lxc_commands - commands.c:lxc_cmd_rsp_recv:172 - Command get_cgroup failed to receive response: Connection reset by peer.
lxc-start 20170623081948.873 ERROR lxc_start_ui - tools/lxc_start.c:main:366 - The container failed to start.
lxc-start 20170623081948.873 ERROR lxc_start_ui - tools/lxc_start.c:main:368 - To get more details, run the container in foreground mode.
lxc-start 20170623081948.873 ERROR lxc_start_ui - tools/lxc_start.c:main:370 - Additional information can be obtained by setting the --logfile and --logpriority options.

why do I have the error “Too many levels of symbolic links”?

What template is this? It is not in our tree anymore and so we consider it unsupported. Usually such errors are caused when there’s a circular dependency in the symbolic links

This template is found online https://gist.github.com/nelsnelson/9601966
So you mean that this template is not supported? So I cannot use this template?

We’re not supporting it and as such it is quite difficult for us to debug this. If you’re able to do so you should use the standard templates we ship with LXC. They span quite a range of distributions. Unless you have very very specific requirements using on of our standard templates is a good idea. :slight_smile:

I need to use a template which has a small rootfs size. As the standard templates rootfs size are large. Do you have any template that do not take up too much space?

The busybox or ssh templates would be good candidate for something very small. Busybox as a standalone rootfs, ssh as an example of sharing the host’s binaries through bind-mounts.