lxc-ubuntu-cloud.in revision a2abaa9ec60a8967611e8c8905698bd01bde5861
49N/A# template script for generating ubuntu container for LXC based on released cloud 49N/A# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com> 49N/A# This program is free software; you can redistribute it and/or modify 49N/A# it under the terms of the GNU General Public License version 2, as 49N/A# published by the Free Software Foundation. 49N/A# This program is distributed in the hope that it will be useful, 49N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 49N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 49N/A# GNU General Public License for more details. 49N/A# You should have received a copy of the GNU General Public License along 49N/A# with this program; if not, write to the Free Software Foundation, Inc., 49N/A# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 49N/A # if there is exactly one veth network entry, make sure it has an 49N/A # associated hwaddr. 51N/Alxc.mount = $path/fstab 49N/Alxc.pivotdir = lxc_putold 49N/Alxc.devttydir =$ttydir 51N/Alxc.cap.drop = sys_module mac_admin mac_override 51N/A# When using LXC with apparmor, uncomment the next line to run unconfined: 51N/A#lxc.aa_profile = unconfined 51N/Alxc.cgroup.devices.deny = a 51N/A# Allow any mknod (but not using the node) 51N/Alxc.cgroup.devices.allow = c *:* m 51N/Alxc.cgroup.devices.allow = b *:* m 51N/A# /dev/null and zero 49N/Alxc.cgroup.devices.allow = c 1:3 rwm 49N/Alxc.cgroup.devices.allow = c 1:5 rwm 49N/Alxc.cgroup.devices.allow = c 5:1 rwm lxc.cgroup.devices.allow = c 5:0 rwm lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 1:8 rwm lxc.cgroup.devices.allow = c 136:* rwm lxc.cgroup.devices.allow = c 5:2 rwm lxc.cgroup.devices.allow = c 254:0 rwm lxc.cgroup.devices.allow = c 10:229 rwm lxc.cgroup.devices.allow = c 10:200 rwm lxc.cgroup.devices.allow = c 1:7 rwm lxc.cgroup.devices.allow = c 10:228 rwm lxc.cgroup.devices.allow = c 10:232 rwm proc proc proc nodev,noexec,nosuid 0 0 sysfs sys sysfs defaults 0 0 # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did # get bind mounted to the host's /run/shm. So try to rmdir # it, and in case that fails move it out of the way. LXC Container configuration for Ubuntu Cloud images. [ -r | --release <release> ]: Release name of container, defaults to host [ -a | --arch ]: Arhcitecture of container, defaults to host arcitecture [ -C | --cloud ]: Configure container for use with meta-data service, defaults to no [ -T | --tarball ]: Location of tarball [ -d | --debug ]: Run with 'set -x' to debug errors [ -s | --stream]: Use specified stream rather than 'released' Options, mutually exclusive of "-C" and "--cloud": [ -i | --hostid ]: HostID for cloud-init, defaults to random string [ -u | --userdata ]: Cloud-init user-data file to configure container on start [ -S | --auth-key ]: SSH Public key file to inject into container [ -L | --nolocales ]: Do not copy host's locales into container options=
$(getopt -o a:hp:r:n:Fi:CLS:T:ds:u: -l arch:,help,path:,release:,name:,flush-cache,hostid:,auth-key:,cloud,no_locales,tarball:,debug,stream:,userdata: -- "$@") # Code taken from debootstrap if [
"$arch" =
"i686" ];
then elif [
"$arch" =
"x86_64" ];
then elif [
"$arch" =
"armv7l" ];
then # note: arm images don't exist before oneiric; are called armhf in # 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 "Only i386, amd64, armel and armhf are supported by the ubuntu cloud template." echo "Only i386, amd64, armel and armhf are supported as host." echo "Only 'daily' and 'released' streams are supported" echo "--auth-key=${auth_key} must reference a file" { echo "failed to get full path for auth_key"; exit 1; } 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 "failed to write public keys to metadata"; exit 1; } 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}') chpasswd: { expire: False } 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."