lxc-archlinux.in revision 99cbd2996bd5cebf1869c2f7637f6c9fc2004849
58N/A# template script for generating Arch Linux container for LXC 58N/A# lxc: linux Container library 58N/A# Alexander Vladimirov <alexander.idkfa.vladimirov@gmail.com> 58N/A# John Lane <lxc@jelmail.com> 58N/A# This library is free software; you can redistribute it and/or 58N/A# modify it under the terms of the GNU Lesser General Public 58N/A# License as published by the Free Software Foundation; either 58N/A# version 2.1 of the License, or (at your option) any later version. 58N/A# This library is distributed in the hope that it will be useful, 58N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 58N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1186N/A# Lesser General Public License for more details. 1186N/A# You should have received a copy of the GNU Lesser General Public 1186N/A# License along with this library; if not, write to the Free Software 1186N/A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1186N/A# Detect use under userns (unsupported) 1186N/A echo "This template can't be used for unprivileged containers." 1>&
2 1186N/A echo "You may want to try the \"download\" template instead." 1>&
2 1186N/A# Make sure the usual locations are in PATH 1186N/A# by default, install 'base' except the kernel 1186N/A# split comma-separated string into an array 1186N/A# ${2} - separator (default is ",") 1186N/A# ${result} - result value on success read -a result < <(echo "${1}") # Arch-specific preconfiguration for container # on ArchLinux, read defaults from host systemd configuration if [ "${is_arch}" ]; then if [ ! "${default_locale}" = "en_US.UTF-8" ]; then echo "${default_locale} ${default_locale##*.}" >> \ # hostname and nameservers [ "${r#nameserver}" = "$r" ] || echo "$r" # chroot and configure system ln -s /usr/share/zoneinfo/${default_timezone} /etc/localtime # set default boot target ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target # override getty@.service for container ttys sed -e 's/^ConditionPathExists=/# ConditionPathExists=/' \ -e 's/After=dev-%i.device/After=/' \ < /lib/systemd/system/getty\@.service \ > /etc/systemd/system/getty\@.service # initialize pacman keyring pacman-key --populate archlinux # enable getty on active ttys file to allow root logins on tty7 and higher" # write container configuration files mkdir -p "${config_path}" local config="${config_path}/config" || echo "lxc.arch = ${arch}" >> "${config}" || echo "lxc.rootfs = ${rootfs_path}" >> "${config}" [ -e "${shared_config}" ] \ && echo "lxc.include = ${shared_config}" >> "${config}" echo "Failed to configure container" # install packages within container chroot if [ "${different_arch}" = "true" ]; then sed -e "s:Architecture =.*:Architecture = ${arch}:g" \ "${pacman_config}" > "${container_pacman_config}" sed -e "s:\(x86_64\|\$arch\):${arch}:g" \ echo "Failed to install container packages" if [ "${different_arch}" = "true" ]; then sed -i -e "s:Architecture =.*:Architecture = ${arch}:g" \ rm "${container_pacman_config}" "${container_mirrorlist}" ${1} -n|--name=<container_name> [-p|--path=<path>] [-a|--arch=<arch of the container>] [-r|--root_password=<root password>] [-P|--packages=<pkg1,pkg2,...>] [-e|--enable_units=unit1,unit2...] [-d|--disable_units=unit1,unit2...] [-c|--config=<pacman config path>] [-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 (${default_path}) --rootfs path for actual container rootfs, (${default_path/rootfs) -P,--packages preinstall additional packages, comma-separated list -e,--enable_units enable systemd services, comma-separated list -d,--disable_units disable systemd services, comma-separated list -c,--config use specified pacman config when installing container packages -a,--arch use specified architecture instead of host's architecture -r,--root_password set container root password -h,--help print this help if [ -z
"${name}" ];
then echo "missing required 'name' parameter" 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}" if [ ${
#enable_units[@]} -gt 0 ]; then [
"${unit##*.}" =
"service" ] ||
unit=
"${unit}.service"if [ ${
#disable_units[@]} -gt 0 ]; then [
"${unit##*.}" =
"service" ] ||
unit=
"${unit}.service"if [ -n
"${root_passwd}" ];
then Arch Linux container ${name} is successfully created! The configuration is stored in ${config_path}/config. Please refer to https://wiki.archlinux.org for information about configuring Arch Linux.