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