By default, a LXC container created with the "debian" template (/usr/share/lxc/templates/lxc-debian) contains the systemd init system. And even if the physical host itself doesn't run the systemd, the containers still do.
To prevent this from happening or better said to remove systemd and install another init system, the template can be slightly modified. In this example I replace systemd with the classical SysV init. Before the usage() function, I added:
nosystemd()
{
# Based on http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installation
echo "Installing SysV init and removing systemd"
# Install SysV init
chroot $rootfs apt-get -y --force-yes -qq install sysvinit-core sysvinit-utils
chroot $rootfs cp /usr/share/sysvinit/inittab /etc/inittab
# Remove SystemD
chroot $rootfs apt-get -y --force-yes -qq remove --purge --auto-remove systemd
# Prevent apt from installing systemd packages in the future
echo -e 'Package: systemd\nPin: release *\nPin-Priority: -1' > $rootfs/etc/apt/preferences.d/systemd
echo -e '\n\nPackage: *systemd*\nPin: release *\nPin-Priority: -1' >> $rootfs/etc/apt/preferences.d/systemd
}
And at the end of the template file, where the functions are launched one after another, the new function "nosystemd" is called:
install_debian $rootfs $release $arch
if [ $? -ne 0 ]; then
echo "failed to install debian"
exit 1
fi
configure_debian $rootfs $name
if [ $? -ne 0 ]; then
echo "failed to configure debian for a container"
exit 1
fi
copy_configuration $path $rootfs $name $arch
if [ $? -ne 0 ]; then
echo "failed write configuration file"
exit 1
fi
configure_debian_systemd $path $rootfs
# Manual modifications
nosystemd
if [ ! -z $clean ]; then
clean || exit 1
exit 0
fi
A created container now runs the following processes:
root@ ~ # ps auxf
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 485 0.0 0.0 21892 3696 ? S 21:31 0:00 /bin/bash
root 583 0.0 0.0 19096 2500 ? R+ 21:31 0:00 \_ ps auxf
root 1 0.0 0.0 15492 1812 ? Ss 21:30 0:00 init [2]
root 465 0.0 0.0 27476 2228 ? Ss 21:30 0:00 /usr/sbin/cron
root 468 0.0 0.0 55180 2892 ? Ss 21:30 0:00 /usr/sbin/sshd
root 475 0.0 0.0 12664 1868 tty1 Ss+ 21:30 0:00 /sbin/getty 38400 tty1
root 476 0.0 0.0 12664 1820 tty2 Ss+ 21:30 0:00 /sbin/getty 38400 tty2
root 477 0.0 0.0 12664 1856 tty3 Ss+ 21:30 0:00 /sbin/getty 38400 tty3
root 478 0.0 0.0 12664 1836 tty4 Ss+ 21:30 0:00 /sbin/getty 38400 tty4
root 577 0.0 0.0 12664 1748 ? Ss 21:31 0:00 /sbin/getty 38400 tty5
root 578 0.0 0.0 12664 1860 ? Ss 21:31 0:00 /sbin/getty 38400 tty6
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder