# template script for generating ubuntu container for LXC
#
# This script consolidates and extends the existing lxc ubuntu scripts
#
# Copyright © 2013 Canonical Ltd.
# Author: Scott Moser <scott.moser@canonical.com>
#
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Detect use under userns (unsupported)
# Make sure the usual locations are in PATH
BUILD="standard"
LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
DEF_VERSION="released"
DEF_SOURCE="nocloud"
case "${UNAME_M}" in
*) DEF_ARCH="i386";;
esac
echo yes
}
# Allow the cache base to be set by environment variable
else
fi
shift
done
return 1
}
cat <<EOF
${0##*/} [options]
-a | --arch A architecture to use [${ARCHES[*]}]
default: ${DEF_ARCH}
-h | --help this usage
-v | --verbose increase verbosity
-S | --auth-key K insert auth key 'K'
-v | --version V version [${STREAMS[*]}]
default: ${DEF_VERSION}
-u | --userdata U user-data file
--tarball T read from tarball 'T' rather than downloading
or using cache.
--source S insert userdata/metadata via source S
[${SOURCES[*]}]
EOF
}
local level=${1}; shift;
error "${@}"
}
k="${arg%%=*}"
v="${arg#*=}"
ret="${ret} \"${k}\": \"$v\","
done
ret="${ret%,} }"
echo "$ret"
}
{
# Template used to create this container: cirros
lxc.rootfs = $rootfs
lxc.pivotdir = lxc_putold
lxc.tty = 4
lxc.pts = 1024
lxc.utsname = $name
lxc.arch = $arch
lxc.cap.drop = sys_module mac_admin mac_override sys_time
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed
lxc.cgroup.devices.deny = a
# Allow any mknod (but not using the node)
lxc.cgroup.devices.allow = c *:* m
lxc.cgroup.devices.allow = b *:* m
# /dev/null and zero
lxc.cgroup.devices.allow = c 1:3 rwm
lxc.cgroup.devices.allow = c 1:5 rwm
# consoles
lxc.cgroup.devices.allow = c 5:1 rwm
lxc.cgroup.devices.allow = c 5:0 rwm
# /dev/{,u}random
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
# rtc
lxc.cgroup.devices.allow = c 254:0 rwm
# fuse
lxc.cgroup.devices.allow = c 10:229 rwm
# tun
lxc.cgroup.devices.allow = c 10:200 rwm
# full
lxc.cgroup.devices.allow = c 1:7 rwm
# hpet
lxc.cgroup.devices.allow = c 10:228 rwm
# kvm
lxc.cgroup.devices.allow = c 10:232 rwm
EOF
fi
}
iid="iid-local01"
else
fi
}
esac
}
if [ $in_userns -eq 1 ]; then
else
fi
return 0
}
file="cirros-$ver-$arch-lxc.tar.gz"
outd="${cached}/${dlpath%/*}"
return 0
fi
return 1;
}
}
local short_opts="a:hn:p:S:uvV"
local long_opts="arch:,auth-key:,name:,path:,tarball:,userdata:,verbose,version:,rootfs:,mapped-uid:,mapped-gid:"
local getopt_out=""
eval set -- "${getopt_out}" ||
{ bad_Usage; return; }
local rootfs_d=""
while [ $# -ne 0 ]; do
cur=$1; next=$2;
--mapped-uid) LXC_MAPPED_UID=$next; shift;;
--mapped-gid) LXC_MAPPED_GID=$next; shift;;
--) shift; break;;
esac
shift;
done
fi
esac
return 1;
fi
error "--auth-key=${authkey_f} must reference a file"
return 1
fi
fi
error "${userdata_f}: --userdata arg not a file"
return 1
fi
fi
return
fi
fi
return 1
}
fi
return
}
create_main "$@"
# vi: ts=4 expandtab