lxc-ubuntu.in revision 3e9c97c17a86ff52897bdb965182c36248cdb97a
0N/A# template script for generating ubuntu container for LXC 0N/A# This script consolidates and extends the existing lxc ubuntu scripts 0N/A# XXX todo: add -lvm option 0N/A# Copyright � 2011 Serge Hallyn <serge.hallyn@canonical.com> 0N/A# Copyright � 2010 Wilhelm Meier 0N/A# Author: Wilhelm Meier <wilhelm.meier@fh-kl.de> 0N/A# This program is free software; you can redistribute it and/or modify 0N/A# it under the terms of the GNU General Public License version 2, as 0N/A# published by the Free Software Foundation. 928N/A# This program is distributed in the hope that it will be useful, 0N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 0N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0N/A# GNU General Public License for more details. 0N/A# You should have received a copy of the GNU General Public License along 0N/A# with this program; if not, write to the Free Software Foundation, Inc., 0N/A# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 58N/A # configure the network using the dhcp 99N/A cat <<EOF > $rootfs/etc/network/interfaces 0N/A cat <<EOF > $rootfs/etc/hostname 98N/A127.0.0.1 localhost $hostname 819N/A # suppress log level output for udev 98N/A # remove jobs for consoles 5 and 6 since we only create 4 consoles in 98N/A echo "Please change root-password !" 98N/A packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg 819N/A packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg,netbase 98N/A packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase 98N/A packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,ubuntu-keyring 58N/A # check the mini ubuntu was not already downloaded 0N/A # download a mini ubuntu into a cache 0N/A echo "Failed to download the rootfs, aborting." 0N/A echo "Download complete." 928N/A # make a local copy of the miniubuntu 0N/A echo "Cache repository is busy." 830N/A echo "Failed to copy rootfs" 830N/Alxc.cgroup.devices.deny = a 830N/Alxc.cgroup.devices.allow = c 1:3 rwm 830N/Alxc.cgroup.devices.allow = c 1:5 rwm 819N/Alxc.cgroup.devices.allow = c 5:1 rwm 928N/Alxc.cgroup.devices.allow = c 5:0 rwm 819N/A#lxc.cgroup.devices.allow = c 4:0 rwm 819N/A#lxc.cgroup.devices.allow = c 4:1 rwm 819N/Alxc.cgroup.devices.allow = c 1:9 rwm 819N/Alxc.cgroup.devices.allow = c 1:8 rwm 819N/Alxc.cgroup.devices.allow = c 136:* rwm 819N/Alxc.cgroup.devices.allow = c 5:2 rwm 928N/Alxc.cgroup.devices.allow = c 254:0 rwm 819N/Alxc.cgroup.devices.allow = c 10:229 rwm 819N/Aproc $rootfs/proc proc nodev,noexec,nosuid 0 0 819N/Asysfs $rootfs/sys sysfs defaults 0 0 819N/A echo "Failed to add configuration" 819N/A # provide the lxc service 819N/A# fake some events needed for correct startup other services 0N/Adescription "Container Upstart" 849N/A rm -rf /var/run/network/* 510N/A /sbin/initctl emit stopped JOB=udevtrigger --no-wait 510N/A /sbin/initctl emit started JOB=udev --no-wait 345N/A # fix buggus runlevel with sshd 0N/A cat <<EOF > $rootfs/etc/init/ssh.conf 850N/A# ssh - OpenBSD Secure Shell server 942N/A# The OpenSSH server provides secure shell access to the system. 942N/Adescription "OpenSSH server" 107N/Astop on runlevel [!2345] 158N/A# replaces SSHD_OOM_ADJUST in /etc/default/ssh 158N/A test -x /usr/sbin/sshd || { stop; exit 0; } 152N/A test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; } 152N/A test -c /dev/null || { stop; exit 0; } 144N/A mkdir -p -m0755 /var/run/sshd 144N/A# if you used to set SSHD_OPTS in /etc/default/ssh, you can change the 0N/A# 'exec' line here instead 0N/A cat <<EOF > $rootfs/etc/init/console.conf 853N/A# This service maintains a console on tty1 from the point the system is 850N/A# started until it is shut down again. 850N/Astart on stopped rc RUNLEVEL=[2345] 850N/Astop on runlevel [!2345] 866N/Aexec /sbin/getty -8 38400 /dev/console 866N/A# /lib/init/fstab: cleared out for bare-bones lxc 850N/A # reconfigure some services 850N/A # remove pointless services in a container 0N/A # if this isn't lucid, then we need to twiddle the network upstart bits :( 830N/A # for lucid and maverick, if not trimming, then add the ubuntu-virt 830N/A # ppa and install lxcguest 99N/A # bind-mount the user's path into the container's /home 0N/A echo 'Warning: failed to copy password entry for $user' 0N/A # lock, so we won't purge while someone is creating a repository 0N/A if [ $? != 0 ]; then 603N/A echo "Cache repository is busy." 830N/A echo -n "Purging the download cache..." 0N/A$1 -h|--help -p|--path=<path> --clean [-a|--arch] [-b|--bindhome <user>] [--trim] [-r|--release] 0N/Arelease: lucid | maverick | natty | oneiric 830N/Atrim: make a minimal (faster, but not upgrade-safe) container 0N/Abindhome: bind <user>'s home into the container 603N/Aarch: amd64 or i386: defaults to host arch 0N/A# Code taken from debootstrap 0N/A --)
shift 1;
break ;;
850N/A echo "can't create amd64 container on i386" 819N/A echo "'debootstrap' command is missing" 0N/A echo "'path' parameter is required" 0N/Aif [
"$(id -u)" !=
"0" ];
then 0N/A echo "This script should be run as 'root'" 0N/A echo "failed to configure ubuntu $release for a container" 819N/A echo "failed write configuration file"