lxc-archlinux.in revision 148315348760faf4ad822ded7c416d2de8050937
144N/A# template script for generating Arch linux container for LXC 144N/A# lxc: linux Container library 144N/A# Alexander Vladimirov <idkfa@vlan1.ru> 144N/A# This library is free software; you can redistribute it and/or 144N/A# modify it under the terms of the GNU Lesser General Public 144N/A# License as published by the Free Software Foundation; either 144N/A# version 2.1 of the License, or (at your option) any later version. 144N/A# This library is distributed in the hope that it will be useful, 144N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 144N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 144N/A# Lesser General Public License for more details. 954N/A# You should have received a copy of the GNU Lesser General Public 954N/A# License along with this library; if not, write to the Free Software 954N/A# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # sort of minimal package set # split comma-separated string into an array # ${2} - separator (default is ",") # ${result} - result value on success read -a result < <(echo "${1}") # Arch-specific preconfiguration for container # read locale and timezone defaults from system rc.conf if running on Arch if [ "${is_arch}" ]; then if [ ! "${default_locale}" = "en_US.UTF-8" ]; then echo "${default_locale} ${default_locale##*.}" >> "${rootfs_path}/etc/locale.gen" 127.0.0.1 localhost.localdomain localhost ${name} ::1 localhost.localdomain localhost ln -s /usr/share/zoneinfo/${default_timezone} /etc/localtime # disable services unavailable for container ln -s /dev/null /etc/systemd/system/systemd-udevd.service ln -s /dev/null /etc/systemd/system/systemd-udevd-control.socket ln -s /dev/null /etc/systemd/system/systemd-udevd-kernel.socket ln -s /dev/null /etc/systemd/system/proc-sys-fs-binfmt_misc.automount # set default systemd target ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target # write container configuration files mkdir -p "${config_path}" cat > "${config_path}/config" << EOF lxc.rootfs=${rootfs_path} lxc.mount=${config_path}/fstab lxc.cap.drop = sys_module mac_admin mac_override lxc.network.type=${lxc_network_type} lxc.network.link=${lxc_network_link} lxc.cgroup.devices.deny = a lxc.cgroup.devices.allow = c *:* m lxc.cgroup.devices.allow = b *:* m lxc.cgroup.devices.allow = c 1:3 rwm lxc.cgroup.devices.allow = c 1:5 rwm lxc.cgroup.devices.allow = c 1:7 rwm lxc.cgroup.devices.allow = c 1:8 rwm lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 4:1 rwm lxc.cgroup.devices.allow = c 5:0 rwm lxc.cgroup.devices.allow = c 5:1 rwm lxc.cgroup.devices.allow = c 5:2 rwm lxc.cgroup.devices.allow = c 136:* rwm cat > "${config_path}/fstab" << EOF sysfs sys sysfs ro,defaults 0 0 proc proc proc nodev,noexec,nosuid 0 0 /proc/sys ${rootfs_path}/proc/sys none ro,bind 0 0 #/var/log/journal ${rootfs_path}/var/log/journal none bind 0 0 # install packages within container chroot echo "Failed to install container packages" ${1} -n|--name=<container_name> [-P|--packages=<pkg1,pkg2,...>] [-p|--path=<path>] [-t|--network_type=<type>] [-l|--network_link=<link>] [-h|--help] -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 ${default_path}/rootfs. The container config will go under ${default_path} in that case -P,--packages preinstall additional packages, comma-separated list -c,--config use specified pacman config when installing container packages -t,--network_type set container network interface type (${lxc_network_type}) -l,--network_link set network link device (${lxc_network_link}) -h,--help print this help if [ -z
"${name}" ];
then echo "missing required 'name' parameter" echo "network link interface does not exist" echo "'pacman' command is missing, refer to wiki.archlinux.org for information about installing pacman" if [ -z
"${path}" ];
then path=
"${default_path}/${name}" if [
"${EUID}" !=
"0" ];
then echo "This script should be run as 'root'" echo "Interrupted, cleaning up" rm -rf "${default_path}/${name}" echo "failed to write configuration file" if [ ${
#additional_packages[@]} -gt 0 ]; then mkdir -p
"${rootfs_path}" echo "failed to install Arch Linux" rm -
rf "${config_path}" "${path}" echo "failed to configure Arch Linux for a container" rm -
rf "${config_path}" "${path}" echo "container config is ${config_path}/config"