4
# template script for generating ubuntu/maverick container for LXC
6
# This script is based on lxc-debian (Daniel Lezcano <daniel.lezcano@free.fr>)
9
# Copyright � 2010 Wilhelm Meier
10
# Author: Wilhelm Meier <wilhelm.meier@fh-kl.de>
12
# This program is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License version 2, as
14
# published by the Free Software Foundation.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License along
22
# with this program; if not, write to the Free Software Foundation, Inc.,
23
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31
# configure the network using the dhcp
32
cat <<EOF > $rootfs/etc/network/interfaces
34
iface lo inet loopback
40
sed -i "s/<hostname>/$hostname/" $rootfs/etc/dhcp3/dhclient.conf
43
cat <<EOF > $rootfs/etc/hostname
47
cat <<EOF > $rootfs/etc/hosts
48
127.0.0.1 localhost $hostname
51
# suppress log level output for udev
52
sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
55
rm -f $rootfs/etc/init/tty{5,6}.conf
56
cp $rootfs/etc/init/tty1.conf $rootfs/etc/init/console.conf
57
sed -i 's/tty1/\/dev\/console/' $rootfs/etc/init/console.conf
59
# don't let upstart mount anything from its builtin fs
60
echo "#Emptied out by lxc-maverick template" > $rootfs/lib/init/fstab
62
echo "Please change root-password !"
63
echo "root:root" | chroot $rootfs chpasswd
70
packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg
75
# check the mini ubuntu was not already downloaded
76
mkdir -p "$cache/partial-$arch"
78
echo "Failed to create '$cache/partial-$arch' directory"
82
# download a mini ubuntu into a cache
83
echo "Downloading ubuntu maverick minimal ..."
84
debootstrap --verbose --variant=minbase --components=main,universe --arch=$arch --include=$packages maverick $cache/partial-$arch
86
echo "Failed to download the rootfs, aborting."
90
mv "$1/partial-$arch" "$1/rootfs-$arch"
91
echo "Download complete."
102
# make a local copy of the miniubuntu
103
echo -n "Copying rootfs to $rootfs ..."
104
cp -a $cache/rootfs-$arch $rootfs || return 1
110
cache="/var/cache/lxc/maverick"
112
mkdir -p /var/lock/subsys/
115
if [ $? -ne 0 ]; then
116
echo "Cache repository is busy."
121
if [ "$arch" == "x86_64" ]; then
125
if [ "$arch" == "i686" ]; then
129
echo "Checking cache download in $cache/rootfs-$arch ... "
130
if [ ! -e "$cache/rootfs-$arch" ]; then
131
download_ubuntu $cache $arch
132
if [ $? -ne 0 ]; then
133
echo "Failed to download 'ubuntu maverick base'"
138
echo "Copy $cache/rootfs-$arch to $rootfs ... "
139
copy_ubuntu $cache $arch $rootfs
140
if [ $? -ne 0 ]; then
141
echo "Failed to copy rootfs"
147
) 200>/var/lock/subsys/lxc
158
cat <<EOF >> $path/config
164
lxc.mount = $path/fstab
166
lxc.cgroup.devices.deny = a
168
lxc.cgroup.devices.allow = c 1:3 rwm
169
lxc.cgroup.devices.allow = c 1:5 rwm
171
lxc.cgroup.devices.allow = c 5:1 rwm
172
lxc.cgroup.devices.allow = c 5:0 rwm
173
#lxc.cgroup.devices.allow = c 4:0 rwm
174
#lxc.cgroup.devices.allow = c 4:1 rwm
176
lxc.cgroup.devices.allow = c 1:9 rwm
177
lxc.cgroup.devices.allow = c 1:8 rwm
178
lxc.cgroup.devices.allow = c 136:* rwm
179
lxc.cgroup.devices.allow = c 5:2 rwm
181
lxc.cgroup.devices.allow = c 254:0 rwm
184
cat <<EOF > $path/fstab
185
proc $rootfs/proc proc nodev,noexec,nosuid 0 0
186
sysfs $rootfs/sys sysfs defaults 0 0
189
if [ $? -ne 0 ]; then
190
echo "Failed to add configuration"
199
cache="/var/cache/lxc/maverick"
201
if [ ! -e $cache ]; then
205
# lock, so we won't purge while someone is creating a repository
209
echo "Cache repository is busy."
213
echo -n "Purging the download cache..."
214
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
217
) 200>/var/lock/subsys/lxc
223
$1 -h|--help -p|--path=<path> --clean
228
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
229
if [ $? -ne 0 ]; then
233
eval set -- "$options"
238
-h|--help) usage $0 && exit 0;;
239
-p|--path) path=$2; shift 2;;
240
-n|--name) name=$2; shift 2;;
241
-c|--clean) clean=$2; shift 2;;
242
--) shift 1; break ;;
247
if [ ! -z "$clean" -a -z "$path" ]; then
253
if [ $? -ne 0 ]; then
254
echo "'debootstrap' command is missing"
258
if [ -z "$path" ]; then
259
echo "'path' parameter is required"
263
if [ "$(id -u)" != "0" ]; then
264
echo "This script should be run as 'root'"
270
install_ubuntu $rootfs
271
if [ $? -ne 0 ]; then
272
echo "failed to install ubuntu maverick"
276
configure_ubuntu $rootfs $name
277
if [ $? -ne 0 ]; then
278
echo "failed to configure ubuntu maverick for a container"
282
copy_configuration $path $rootfs $name
283
if [ $? -ne 0 ]; then
284
echo "failed write configuration file"
288
if [ ! -z $clean ]; then