lxc-ubuntu-cloud.in revision 3f5f5d99b0ea1c204699b13d4a0caf4d9e745449
2ronwalf# template script for generating ubuntu container for LXC based on released 2ronwalf# Copyright © 2012 Serge Hallyn <serge.hallyn@canonical.com> 2ronwalf# This library is free software; you can redistribute it and/or 2ronwalf# modify it under the terms of the GNU Lesser General Public 2ronwalf# License as published by the Free Software Foundation; either 2ronwalf# version 2.1 of the License, or (at your option) any later version. 2ronwalf# This library 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 GNU 2ronwalf# Lesser General Public License for more details. 2ronwalf# You should have received a copy of the GNU Lesser General Public 2ronwalf# License along with this library; if not, write to the Free Software 2ronwalf# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18daenzerorama # if there is exactly one veth network entry, make sure it has an 2ronwalf ## Relocate any other config entries 18daenzerorama if [ -e "${LXC_TEMPLATE_CONFIG}/ubuntu-cloud.${release}.conf" ]; then ## Add the container-specific config echo "# Container specific configuration" >> $path/config cat <<EOF >> $path/config ## Re-add the previously removed network config # Set initial timezone as on host echo "Timezone in container is not configured. Adjust it manually." # 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. # NOTE: This can only be removed once 12.04 goes out of support LXC Container configuration for Ubuntu Cloud images. [ -r | --release <release> ]: Release name of container, defaults to host [ --rootfs <path> ]: Path in which rootfs will be placed [ -a | --arch ]: Architecture of container, defaults to host architecture [ -T | --tarball ]: Location of tarball [ -d | --debug ]: Run with 'set -x' to debug errors [ -s | --stream]: Use specified stream rather than 'released' Additionally, clone hooks can be passed through (ie, --userdata). For those, options=
$(getopt -o a:hp:r:n:Fi:CLS:T:ds:u: -l arch:,help,rootfs:,path:,release:,name:,flush-cache,hostid:,auth-key:,cloud,no_locales,tarball:,debug,stream:,userdata:,mapped-uid: -- "$@") # default release is precise, or the systems release if recognized rels=
"lucid natty oneiric precise quantal raring saucy" # 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 "'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 "Container $name created."