lxc-ubuntu-cloud.in revision f34ff296835b2afa4b80018651d902448c99ac75
0N/A# template script for generating ubuntu container for LXC based on released cloud 0N/A# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com> 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. 0N/A# This program is distributed in the hope that it will be useful, 115N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 116N/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. 115N/A # if there is exactly one veth network entry, make sure it has an 0N/A # associated hwaddr. 0N/Alxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//') 0N/Alxc.mount = $path/fstab 0N/Alxc.cap.drop = sys_module mac_admin 0N/Alxc.cgroup.devices.deny = a 0N/A# Allow any mknod (but not using the node) 0N/Alxc.cgroup.devices.allow = c *:* m 0N/Alxc.cgroup.devices.allow = b *:* m 0N/Alxc.cgroup.devices.allow = c 1:3 rwm 0N/Alxc.cgroup.devices.allow = c 1:5 rwm 0N/Alxc.cgroup.devices.allow = c 5:1 rwm 0N/Alxc.cgroup.devices.allow = c 5:0 rwm 0N/A#lxc.cgroup.devices.allow = c 4:0 rwm 0N/A#lxc.cgroup.devices.allow = c 4:1 rwm 0N/Alxc.cgroup.devices.allow = c 1:9 rwm 0N/Alxc.cgroup.devices.allow = c 1:8 rwm 0N/Alxc.cgroup.devices.allow = c 136:* rwm 0N/Alxc.cgroup.devices.allow = c 5:2 rwm 0N/Alxc.cgroup.devices.allow = c 254:0 rwm 0N/Alxc.cgroup.devices.allow = c 10:229 rwm 115N/Alxc.cgroup.devices.allow = c 10:200 rwm 116N/Alxc.cgroup.devices.allow = c 1:7 rwm 0N/Alxc.cgroup.devices.allow = c 10:228 rwm 0N/Alxc.cgroup.devices.allow = c 10:232 rwm 0N/Aproc proc proc nodev,noexec,nosuid 0 0 0N/Asysfs sys sysfs defaults 0 0 0N/A # rmdir /dev/shm in precise and quantal containers. 0N/A # get bind mounted to the host's /run/shm. So try to rmdir 0N/A # it, and in case that fails move it out of the way. 116N/ALXC Container configuration for Ubuntu Cloud images. 164N/A[ -r | --release <release> ]: Release name of container, defaults to host 116N/A[ -a | --arch ]: Arhcitecture of container, defaults to host arcitecture 116N/A[ -C | --cloud ]: Configure container for use with meta-data service, defaults to no 116N/A[ -T | --tarball ]: Location of tarball 116N/A[ -d | --debug ]: Run with 'set -x' to debug errors 116N/A[ -s | --stream]: Use specified stream rather than 'released' 116N/AOptions, mutually exclusive of "-C" and "--cloud": 116N/A [ -i | --hostid ]: HostID for cloud-init, defaults to random string 116N/A [ -u | --userdata ]: Cloud-init user-data file to configure container on start 116N/A [ -S | --auth-key ]: SSH Public key file to inject into container 116N/A [ -L | --nolocales ]: Do not copy host's locales into container 177N/Aoptions=
$(getopt -o a:hp:r:n:Fi:CLS:T:ds: -l arch:,help,path:,release:,name:,flush-cache,hostid:,auth-key:,cloud,no_locales,tarball:,debug,stream:,userdata: -- "$@") 120N/A# Code taken from debootstrap 0N/A # note: arm images don't exist before oneiric; are called armhf in 0N/A # precise and later; and are not supported by the query, so we don't actually 0N/A # support them yet (see check later on). When Query2 is available, 0N/A # we'll use that to enable arm images. 301N/A echo "can't create amd64 container on i386" 301N/A echo "Only i386 and amd64 are supported by the ubuntu cloud template." 301N/A echo "Only 'daily' and 'released' streams are supported" 301N/A echo "Userdata does not exist" 301N/A echo "'path' parameter is required" 301N/A echo "This script should be run as 'root'" 0N/A# determine the url, tarball, and directory names # if the release doesn't have a *-rootfs.tar.gz, then create one from the # cloudimg.tar.gz by extracting the .img, mounting it loopback, and creating # a tarball from the mounted image. echo "Downloading cloud image from $url" wget $url || { echo "Couldn't find cloud image $url."; exit 1; } echo "Creating new cached cloud image rootfs" echo "New cloud image cache created" echo "Clearing the cached images" echo "Extracting container rootfs" echo "Configuring for running outside of a cloud environment" echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container" instance_id: lxc-$host_id echo "Using custom user-data" output: {all: '| tee -a /var/log/cloud-init-output.log'} manage_etc_hosts: localhost locale: $(/usr/bin/locale | awk -F= '/LANG=/ {print$NF}') echo "Please login as user ubuntu with password ubuntu." echo "Configured for running in a cloud environment." echo "If you do not have a meta-data service, this container will likely be useless." echo "Container $name created."