lxc-ubuntu-cloud.in revision b8bced69a80a8be95fdbbb6b4e9ad7fa85464b1e
2ronwalf# template script for generating ubuntu container for LXC based on released cloud 2ronwalf# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com> 2ronwalf# This program is free software; you can redistribute it and/or modify 2ronwalf# it under the terms of the GNU General Public License version 2, as 2ronwalf# published by the Free Software Foundation. 2ronwalf# This program is distributed in the hope that it will be useful, 2ronwalf# but WITHOUT ANY WARRANTY; without even the implied warranty of 2ronwalf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2ronwalf# GNU General Public License for more details. 2ronwalf# You should have received a copy of the GNU General Public License along 2ronwalf# with this program; if not, write to the Free Software Foundation, Inc., 2ronwalf# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 2ronwalf # if there is exactly one veth network entry, make sure it has an 2ronwalflxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//') 2ronwalflxc.cap.drop = sys_module mac_admin 2ronwalf# Allow any mknod (but not using the node) 2ronwalflxc.cgroup.devices.allow = c *:* m 2ronwalflxc.cgroup.devices.allow = b *:* m 2ronwalflxc.cgroup.devices.allow = c 1:3 rwm 2ronwalflxc.cgroup.devices.allow = c 1:5 rwm 2ronwalflxc.cgroup.devices.allow = c 5:1 rwm 2ronwalflxc.cgroup.devices.allow = c 5:0 rwm 2ronwalf#lxc.cgroup.devices.allow = c 4:0 rwm 2ronwalf#lxc.cgroup.devices.allow = c 4:1 rwm 2ronwalflxc.cgroup.devices.allow = c 1:9 rwm 2ronwalflxc.cgroup.devices.allow = c 1:8 rwm 2ronwalflxc.cgroup.devices.allow = c 136:* rwm 2ronwalflxc.cgroup.devices.allow = c 5:2 rwm 2ronwalflxc.cgroup.devices.allow = c 254:0 rwm 2ronwalflxc.cgroup.devices.allow = c 10:229 rwm 2ronwalflxc.cgroup.devices.allow = c 10:200 rwm 2ronwalflxc.cgroup.devices.allow = c 1:7 rwm 2ronwalflxc.cgroup.devices.allow = c 10:228 rwm 2ronwalflxc.cgroup.devices.allow = c 10:232 rwm 2ronwalfproc proc proc nodev,noexec,nosuid 0 0 2ronwalf # it, and in case that fails move it out of the way. 2ronwalfLXC Container configuration for Ubuntu Cloud images. 2ronwalf[ -r | --release <release> ]: Release name of container, defaults to host 2ronwalf[ -a | --arch ]: Arhcitecture of container, defaults to host arcitecture 2ronwalf[ -C | --cloud ]: Configure container for use with meta-data service, defaults to no 2ronwalf[ -T | --tarball ]: Location of tarball 2ronwalf[ -d | --debug ]: Run with 'set -x' to debug errors 2ronwalf[ -s | --stream]: Use specified stream rather than 'released' 2ronwalfOptions, mutually exclusive of "-C" and "--cloud": 2ronwalf [ -i | --hostid ]: HostID for cloud-init, defaults to random string 2ronwalf [ -u | --userdata ]: Cloud-init user-data file to configure container on start 2ronwalf [ -S | --auth-key ]: SSH Public key file to inject into container 2ronwalf [ -L | --nolocales ]: Do not copy host's locales into container 2ronwalfoptions=
$(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: -- "$@") 14daenzerorama # note: arm images don't exist before oneiric; are called armhf in 14daenzerorama # precise and later; and are not supported by the query, so we don't actually 18daenzerorama # support them yet (see check later on). When Query2 is available, if [
"$arch" ==
"i686" ];
then echo "can't create amd64 container on i386" echo "Only i386 and amd64 are supported by the ubuntu cloud template." echo "Only 'daily' and 'released' streams are supported" echo "Userdata does not exist" echo "'path' parameter is required" if [
"$(id -u)" !=
"0" ];
then echo "This script should be run as 'root'" # 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."