lxc-altlinux.in revision 96283b546081e7ff709968378fca25cb44f1ab6c
883N/A# template script for generating altlinux container for LXC 883N/A# lxc: linux Container library 883N/A# Alexey Shabalin <shaba@altlinux.org> 883N/A# This library is free software; you can redistribute it and/or 883N/A# modify it under the terms of the GNU Lesser General Public 883N/A# License as published by the Free Software Foundation; either 883N/A# version 2.1 of the License, or (at your option) any later version. 883N/A# This library is distributed in the hope that it will be useful, 883N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 883N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 883N/A# Lesser General Public License for more details. 3996N/A# You should have received a copy of the GNU Lesser General Public 883N/A# License along with this library; if not, write to the Free Software 883N/A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 883N/A# Detect use under userns (unsupported) 883N/A if [
"$arg" =
"--mapped-uid" -o
"$arg" =
"--mapped-gid" ];
then 883N/A echo "This template can't be used for unprivileged containers." 1>&
2 883N/A echo "You may want to try the \"download\" template instead." 1>&
2 883N/A# Make sure the usual locations are in PATH 883N/A # disable selinux in altlinux 883N/A cat <<EOF > ${rootfs_path}/etc/net/ifaces/veth0/options 913N/A cat <<EOF > ${rootfs_path}/etc/net/ifaces/veth0/ipv4address 3996N/A cat <<EOF > ${rootfs_path}/etc/net/ifaces/veth0/ipv4route cat <<EOF > ${rootfs_path}/etc/net/ifaces/veth0/resolv.conf cat <<EOF > ${rootfs_path}/etc/net/ifaces/veth0/ipv6address cat <<EOF > ${rootfs_path}/etc/net/ifaces/veth0/ipv6route cat <<EOF > ${rootfs_path}/etc/sysconfig/network cat <<EOF > $rootfs_path/etc/hosts 127.0.0.1 localhost.localdomain localhost $name # Allow to login at virsh console. loginuid.so doen't work in the absence of auditd. # Allow root to login at virsh console # chroot ${rootfs_path} chkconfig keytable off # touch file for fastboot # check the mini altlinux was not already downloaded # download a mini altlinux into a cache echo "Downloading altlinux minimal ..." # PKG_LIST="basesystem apt apt-conf-sisyphus etcnet openssh-server passwd sysklogd net-tools e2fsprogs" echo "Failed to download the rootfs, aborting." echo "Download complete." # make a local copy of the minialtlinux # i prefer rsync (no reason really) echo "Cache repository is busy." echo "Checking cache download in $cache/rootfs ... " if [ ! -e "$cache/rootfs" ]; then echo "Failed to download 'altlinux base'" echo "Cache found. Updating..." echo "Failed to update 'altlinux base', continuing with last known good cache" echo "Failed to copy rootfs" cat <<EOF >> $config_path/config lxc.mount = $config_path/fstab 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.network.type = $lxc_network_type lxc.network.link = $lxc_network_link if [ ! -z ${ipv4} ]; then cat <<EOF >> $config_path/config cat <<EOF >> $config_path/config lxc.network.ipv4.gateway = $gw if [ ! -z ${ipv6} ]; then cat <<EOF >> $config_path/config cat <<EOF >> $config_path/config lxc.network.ipv6.gateway = $gw6 cat <<EOF >> $config_path/config lxc.cgroup.devices.deny = a lxc.cgroup.devices.allow = c 1:3 rwm lxc.cgroup.devices.allow = c 1:5 rwm lxc.cgroup.devices.allow = c 5:1 rwm lxc.cgroup.devices.allow = c 5:0 rwm lxc.cgroup.devices.allow = c 4:0 rwm lxc.cgroup.devices.allow = c 4:1 rwm lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 1:8 rwm lxc.cgroup.devices.allow = c 136:* rwm lxc.cgroup.devices.allow = c 5:2 rwm lxc.cgroup.devices.allow = c 10:135 rwm cat <<EOF > $config_path/fstab proc proc proc nodev,noexec,nosuid 0 0 sysfs sys sysfs defaults 0 0 echo "Failed to add configuration" # lock, so we won't purge while someone is creating a repository echo "Cache repository is busy." echo -n "Purging the download cache for ALTLinux-$release..." $1 -n|--name=<container_name> [-p|--path=<path>] [-c|--clean] [-R|--release=<ALTLinux_release>] [-4|--ipv4=<ipv4 address>] [-6|--ipv6=<ipv6 address>] [-g|--gw=<gw address>] [-d|--dns=<dns address>] [-P|--profile=<name of the profile>] [--rootfs=<path>] [-A|--arch=<arch of the container>] -n,--name container name, used to as an identifier for that container from now on -p,--path path to where the container rootfs will be created, defaults to @LXCPATH@. The container config will go under @LXCPATH@ in that case -c,--clean clean the cache -R,--release ALTLinux release for the new container. if the host is ALTLinux, then it will defaultto the host's release. -4,--ipv4 specify the ipv4 address to assign to the virtualized interface, eg. 192.168.1.123/24 -6,--ipv6 specify the ipv6 address to assign to the virtualized interface, eg. 2003:db8:1:0:214:1234:fe0b:3596/64 -g,--gw specify the default gw, eg. 192.168.1.1 -G,--gw6 specify the default gw, eg. 2003:db8:1:0:214:1234:fe0b:3596 -d,--dns specify the DNS server, eg. 192.168.1.2 -P,--profile Profile name is the file name in /etc/lxc/profiles contained packages name for install to cache. -A,--arch NOT USED YET. Define what arch the container will be [i686,x86_64] -h,--help print this help -g|--
gw)
gw=$
2;
shift 2;;
echo "'apt-get' command is missing" echo "This is not a ALTLinux host and release missing, use -R|--release to specify release" if [
"$(id -u)" !=
"0" ];
then echo "This script should be run as 'root'" # check for 'lxc.rootfs' passed in through default config by lxc-create echo "A container with that name exists, chose a different name" echo "failed to install altlinux" echo "failed to configure altlinux for a container" echo "failed write configuration file" echo "container rootfs and config created"