lxc-archlinux.in revision d8c77af0ae59a3c48a44a11c95b991bd10473713
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# template script for generating Arch linux container for LXC
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# lxc: linux Container library
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Alexander Vladimirov <idkfa@vlan1.ru>
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This library is free software; you can redistribute it and/or
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# modify it under the terms of the GNU Lesser General Public
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# License as published by the Free Software Foundation; either
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# version 2.1 of the License, or (at your option) any later version.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# This library is distributed in the hope that it will be useful,
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# but WITHOUT ANY WARRANTY; without even the implied warranty of
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Lesser General Public License for more details.
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# You should have received a copy of the GNU Lesser General Public
8900b9eb2514c07047541833286428572493a9fdStéphane Graber# License along with this library; if not, write to the Free Software
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# sort of minimal package set
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# split comma-separated string into an array
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# ${1} - string to split
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# ${2} - separator (default is ",")
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# ${result} - result value on success
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# Arch-specific preconfiguration for container
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi # read locale and timezone defaults from system rc.conf if running on Arch
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi cp -p /etc/vconsole.conf /etc/locale.conf /etc/locale.gen "${rootfs_path}/etc/"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "LANG=${default_lang}" > "${rootfs_path}/etc/locale.conf"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "KEYMAP=us" > "${rootfs_path}/etc/vconsole.conf"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ -e "${rootfs_path}/etc/locale.gen" ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi sed -i 's@^#\(en_US\.UTF-8\)@\1@' "${rootfs_path}/etc/locale.gen"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi if [ ! "${default_locale}" = "en_US.UTF-8" ]; then
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "${default_locale} ${default_locale##*.}" >> "${rootfs_path}/etc/locale.gen"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi echo "${name}" > "${rootfs_path}/etc/hostname"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi127.0.0.1 localhost.localdomain localhost ${name}
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi::1 localhost.localdomain localhost
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi grep nameserver /etc/resolv.conf > "${rootfs_path}/etc/resolv.conf"
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi arch-chroot "${rootfs_path}" /bin/bash -s << EOF
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumimkdir /run/lock
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiln -s /usr/share/zoneinfo/${default_timezone} /etc/localtime
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# disable services unavailable for container
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiln -s /dev/null /etc/systemd/system/systemd-udevd.service
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiln -s /dev/null /etc/systemd/system/systemd-udevd-control.socket
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiln -s /dev/null /etc/systemd/system/systemd-udevd-kernel.socket
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiln -s /dev/null /etc/systemd/system/proc-sys-fs-binfmt_misc.automount
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# set default systemd target
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumiln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
57da8c32f85c0255efa61ee32e260068afdaa565KATOH Yasufumi# write container configuration files
grep -q "^lxc.rootfs" ${config_path}/config 2>/dev/null || echo "lxc.rootfs = ${rootfs_path}" >> ${config_path}/config
cat <<EOF
[-P|--packages=<pkg1,pkg2,...>] [-p|--path=<path>] [-t|--network_type=<type>] [-l|--network_link=<link>] [-h|--help]
-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
options=$(getopt -o hp:P:n:c:l:t: -l help,rootfs:,path:,packages:,name:,config:,network_type:,network_link: -- "${@}")
echo "'pacman' command is missing, refer to wiki.archlinux.org for information about installing pacman"
if [ -z "$rootfs_path" ]; then