lxc-altlinux.in revision 262f4e48a51a55ad9cee06abbcfe4a6ad6166f49
e02a063b3d675678c3b08075d84f30e665d1d53and# template script for generating altlinux container for LXC
e02a063b3d675678c3b08075d84f30e665d1d53and# lxc: linux Container library
0662ed52e814f8f08ef0e09956413a792584eddffuankg# Alexey Shabalin <shaba@altlinux.org>
e02a063b3d675678c3b08075d84f30e665d1d53and# This library is free software; you can redistribute it and/or
e02a063b3d675678c3b08075d84f30e665d1d53and# modify it under the terms of the GNU Lesser General Public
e02a063b3d675678c3b08075d84f30e665d1d53and# License as published by the Free Software Foundation; either
e02a063b3d675678c3b08075d84f30e665d1d53and# version 2.1 of the License, or (at your option) any later version.
e02a063b3d675678c3b08075d84f30e665d1d53and# This library is distributed in the hope that it will be useful,
16b55a35cff91315d261d1baa776138af465c4e4fuankg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16b55a35cff91315d261d1baa776138af465c4e4fuankg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e02a063b3d675678c3b08075d84f30e665d1d53and# Lesser General Public License for more details.
b387b9d37fc71c534f4718777454a8f5a1169017fuankg# You should have received a copy of the GNU Lesser General Public
e02a063b3d675678c3b08075d84f30e665d1d53and# License along with this library; if not, write to the Free Software
e02a063b3d675678c3b08075d84f30e665d1d53and# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e02a063b3d675678c3b08075d84f30e665d1d53and#Configurations
e02a063b3d675678c3b08075d84f30e665d1d53and# is this altlinux?
e02a063b3d675678c3b08075d84f30e665d1d53andBOOTPROTO=dhcp
e02a063b3d675678c3b08075d84f30e665d1d53andNM_CONTROLLED=no
e02a063b3d675678c3b08075d84f30e665d1d53andNETWORKING=yes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgCONFMETHOD=etcnet
e02a063b3d675678c3b08075d84f30e665d1d53andHOSTNAME=${UTSNAME}
e02a063b3d675678c3b08075d84f30e665d1d53andRESOLV_MODS=yes
e02a063b3d675678c3b08075d84f30e665d1d53and127.0.0.1 localhost.localdomain localhost $name
e02a063b3d675678c3b08075d84f30e665d1d53and # Allow to login at virsh console. loginuid.so doen't work in the absence of auditd.
e02a063b3d675678c3b08075d84f30e665d1d53and sed -i 's/^.*loginuid.so.*$/\#&/' ${rootfs_path}/etc/pam.d/common-login
e02a063b3d675678c3b08075d84f30e665d1d53and# chroot ${rootfs_path} chkconfig keytable off
e02a063b3d675678c3b08075d84f30e665d1d53and subst 's/^\([0-9]\+:[0-9]\+:respawn:\/sbin\/mingetty.*\)/#\1/' ${rootfs_path}/etc/inittab
e02a063b3d675678c3b08075d84f30e665d1d53and subst 's,\/dev\/tty12,/var/log/syslog/console,' ${rootfs_path}/etc/syslog.conf
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/null c 1 3
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/zero c 1 5
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 644 ${dev_path}/random c 1 8
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 644 ${dev_path}/urandom c 1 9
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty c 5 0
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty0 c 4 0
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg mknod -m 666 ${dev_path}/tty1 c 4 1
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty2 c 4 2
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty3 c 4 3
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg mknod -m 666 ${dev_path}/tty4 c 4 4
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 600 ${dev_path}/console c 5 1
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/full c 1 7
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/ptmx c 5 2
e02a063b3d675678c3b08075d84f30e665d1d53and echo "root:$root_password" | chroot $rootfs_path chpasswd
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
0662ed52e814f8f08ef0e09956413a792584eddffuankg PKG_LIST="$(grep -hs '^[^#]' "$profile_dir/$profile")"
e02a063b3d675678c3b08075d84f30e665d1d53and# PKG_LIST="basesystem apt apt-conf-sisyphus etcnet openssh-server passwd sysklogd net-tools e2fsprogs"
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Failed to update 'altlinux base', continuing with last known good cache"
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
8ffac2c334103c0336602aaede650cb578611151fuankglxc.utsname = $name
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.tty = 4
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.pts = 1024
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.rootfs = $rootfs_path
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.mount = $config_path/fstab
e02a063b3d675678c3b08075d84f30e665d1d53and#networking
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.type = $lxc_network_type
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.flags = up
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.link = $lxc_network_link
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.name = eth0
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.network.mtu = 1500
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.deny = a
e02a063b3d675678c3b08075d84f30e665d1d53and# /dev/null and zero
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:3 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:5 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 5:1 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 5:0 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 4:0 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 4:1 rwm
e02a063b3d675678c3b08075d84f30e665d1d53and# /dev/{,u}random
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:9 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:8 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 136:* rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 5:2 rwm
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.cgroup.devices.allow = c 254:0 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andproc $rootfs_path/proc proc nodev,noexec,nosuid 0 0
e02a063b3d675678c3b08075d84f30e665d1d53anddevpts $rootfs_path/dev/pts devpts defaults 0 0
e02a063b3d675678c3b08075d84f30e665d1d53andsysfs $rootfs_path/sys sysfs defaults 0 0
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
if [ ! -e $cache ]; then
flock -n -x 200
cat <<EOF
-p,--path path to where the container rootfs will be created, defaults to /var/lib/lxc. The container config will go under /var/lib/lxc in and case
-R,--release ALTLinux release for the new container. if the host is ALTLinux, then it will defaultto the host's release.
-P,--profile Profile name is the file name in /etc/lxc/profiles contained packages name for install to cache.
eval set -- "$options"
if [ -z "$path" ]; then
if [ -z "$profile" ]; then
if [ -z "$release" ]; then
if [ "$is_altlinux" ]; then
if [ ! -z $clean ]; then
echo "container is configured for lxc.network.type=veth and lxc.network.link=virbr0 (which is default if you have libvirt runnig)"