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