~serge-hallyn/ubuntu/oneiric/lxc/fix-shutdown

« back to all changes in this revision

Viewing changes to .pc/diff-to-bcbd102cb/templates/lxc-maverick.in

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-07-07 13:53:52 UTC
  • mfrom: (1.1.9 upstream) (3.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20110707135352-phbbo2w1jb41r8fh
Tags: 0.7.4.2-0.3ubuntu1
* Sync upstream 0.7.4.2
* Add diff up to git head.
  - Fix interaction with cgroups-bin (LP: #784093)
  - Fix arch support to create i386 containers on amd64 (LP: #798476)
  - Support a bind-mounted $HOME with template (LP: #800482)
* add debootstrap to Recommends (LP: #803745)
* debian/patchs updates:
  - refresh 0002-disable-debian-checkroot-script.patch
  - drop:
    * 0004-add-ubuntu-mirrors.patch
    * 0005-add-netbase-to-templates.patch
    * 0006-fix-template-syntax-error.patch
    * 0007-natty-template-install-lxcguest.patch
    * 0010-templates-use-dpkg.patch
  - renamed and updated:
    * 0008-add-arm-to-supported-archs.patch to
      0004-add-arm-to-supported-archs.patch
    * 0009-templates-dont-use-devpts-in-fstab to
      0005-dont-use-devpts-in-fstab
    * 0011-templates-allow-fuse.patch to
      0006-templates-allow-fuse.patch
* remove unused debian/lxc-start.sh
* include autoreconf.mk to force Makefile.in to be rebuilt
* Remaining changes over debian:
  - add lxcguest package
  - debian/control
    * keep docbook-utils in Build-Depends
  - lxc.default: add commented example MIRROR

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
#
 
4
# template script for generating ubuntu/maverick container for LXC
 
5
#
 
6
# This script is based on lxc-debian (Daniel Lezcano <daniel.lezcano@free.fr>)
 
7
#
 
8
 
 
9
# Copyright � 2010 Wilhelm Meier
 
10
# Author: Wilhelm Meier <wilhelm.meier@fh-kl.de>
 
11
#
 
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.
 
15
 
 
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.
 
20
 
 
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.
 
24
#
 
25
 
 
26
configure_ubuntu()
 
27
{
 
28
    rootfs=$1
 
29
    hostname=$2
 
30
 
 
31
   # configure the network using the dhcp
 
32
    cat <<EOF > $rootfs/etc/network/interfaces
 
33
auto lo
 
34
iface lo inet loopback
 
35
 
 
36
auto eth0
 
37
iface eth0 inet dhcp
 
38
EOF
 
39
 
 
40
    sed -i "s/<hostname>/$hostname/" $rootfs/etc/dhcp3/dhclient.conf
 
41
 
 
42
    # set the hostname
 
43
    cat <<EOF > $rootfs/etc/hostname
 
44
$hostname
 
45
EOF
 
46
    # set minimal hosts
 
47
    cat <<EOF > $rootfs/etc/hosts
 
48
127.0.0.1 localhost $hostname
 
49
EOF
 
50
 
 
51
    # suppress log level output for udev
 
52
    sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
 
53
 
 
54
    # tweak consoles
 
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
 
58
 
 
59
    # don't let upstart mount anything from its builtin fs
 
60
    echo "#Emptied out by lxc-maverick template"  > $rootfs/lib/init/fstab
 
61
 
 
62
    echo "Please change root-password !"
 
63
    echo "root:root" | chroot $rootfs chpasswd
 
64
 
 
65
    return 0
 
66
}
 
67
 
 
68
download_ubuntu()
 
69
{
 
70
    packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,vim,dhcp3-client,ssh,lsb-release,gnupg
 
71
 
 
72
    cache=$1
 
73
    arch=$2
 
74
 
 
75
    # check the mini ubuntu was not already downloaded
 
76
    mkdir -p "$cache/partial-$arch"
 
77
    if [ $? -ne 0 ]; then
 
78
        echo "Failed to create '$cache/partial-$arch' directory"
 
79
        return 1
 
80
    fi
 
81
 
 
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
 
85
    if [ $? -ne 0 ]; then
 
86
        echo "Failed to download the rootfs, aborting."
 
87
        return 1
 
88
    fi
 
89
 
 
90
    mv "$1/partial-$arch" "$1/rootfs-$arch"
 
91
    echo "Download complete."
 
92
 
 
93
    return 0
 
94
}
 
95
 
 
96
copy_ubuntu()
 
97
{
 
98
    cache=$1
 
99
    arch=$2
 
100
    rootfs=$3
 
101
 
 
102
    # make a local copy of the miniubuntu
 
103
    echo -n "Copying rootfs to $rootfs ..."
 
104
    cp -a $cache/rootfs-$arch $rootfs || return 1
 
105
    return 0
 
106
}
 
107
 
 
108
install_ubuntu()
 
109
{
 
110
    cache="/var/cache/lxc/maverick"
 
111
    rootfs=$1
 
112
    mkdir -p /var/lock/subsys/
 
113
    (
 
114
        flock -n -x 200
 
115
        if [ $? -ne 0 ]; then
 
116
            echo "Cache repository is busy."
 
117
            return 1
 
118
        fi
 
119
 
 
120
        arch=$(arch)
 
121
        if [ "$arch" == "x86_64" ]; then
 
122
            arch=amd64
 
123
        fi
 
124
 
 
125
        if [ "$arch" == "i686" ]; then
 
126
            arch=i386
 
127
        fi
 
128
 
 
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'"
 
134
                return 1
 
135
            fi
 
136
        fi
 
137
 
 
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"
 
142
            return 1
 
143
        fi
 
144
 
 
145
        return 0
 
146
 
 
147
        ) 200>/var/lock/subsys/lxc
 
148
 
 
149
    return $?
 
150
}
 
151
 
 
152
copy_configuration()
 
153
{
 
154
    path=$1
 
155
    rootfs=$2
 
156
    name=$3
 
157
 
 
158
    cat <<EOF >> $path/config
 
159
lxc.utsname = $name
 
160
 
 
161
lxc.tty = 4
 
162
lxc.pts = 1024
 
163
lxc.rootfs = $rootfs
 
164
lxc.mount  = $path/fstab
 
165
 
 
166
lxc.cgroup.devices.deny = a
 
167
# /dev/null and zero
 
168
lxc.cgroup.devices.allow = c 1:3 rwm
 
169
lxc.cgroup.devices.allow = c 1:5 rwm
 
170
# consoles
 
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
 
175
# /dev/{,u}random
 
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
 
180
# rtc
 
181
lxc.cgroup.devices.allow = c 254:0 rwm
 
182
EOF
 
183
 
 
184
    cat <<EOF > $path/fstab
 
185
proc            $rootfs/proc         proc    nodev,noexec,nosuid 0 0
 
186
sysfs           $rootfs/sys          sysfs defaults  0 0
 
187
EOF
 
188
 
 
189
    if [ $? -ne 0 ]; then
 
190
        echo "Failed to add configuration"
 
191
        return 1
 
192
    fi
 
193
 
 
194
    return 0
 
195
}
 
196
 
 
197
clean()
 
198
{
 
199
    cache="/var/cache/lxc/maverick"
 
200
 
 
201
    if [ ! -e $cache ]; then
 
202
        exit 0
 
203
    fi
 
204
 
 
205
    # lock, so we won't purge while someone is creating a repository
 
206
    (
 
207
        flock -n -x 200
 
208
        if [ $? != 0 ]; then
 
209
            echo "Cache repository is busy."
 
210
            exit 1
 
211
        fi
 
212
 
 
213
        echo -n "Purging the download cache..."
 
214
        rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
 
215
        exit 0
 
216
 
 
217
    ) 200>/var/lock/subsys/lxc
 
218
}
 
219
 
 
220
usage()
 
221
{
 
222
    cat <<EOF
 
223
$1 -h|--help -p|--path=<path> --clean
 
224
EOF
 
225
    return 0
 
226
}
 
227
 
 
228
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
 
229
if [ $? -ne 0 ]; then
 
230
    usage $(basename $0)
 
231
    exit 1
 
232
fi
 
233
eval set -- "$options"
 
234
 
 
235
while true
 
236
do
 
237
    case "$1" in
 
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 ;;
 
243
        *)              break ;;
 
244
    esac
 
245
done
 
246
 
 
247
if [ ! -z "$clean" -a -z "$path" ]; then
 
248
    clean || exit 1
 
249
    exit 0
 
250
fi
 
251
 
 
252
type debootstrap
 
253
if [ $? -ne 0 ]; then
 
254
    echo "'debootstrap' command is missing"
 
255
    exit 1
 
256
fi
 
257
 
 
258
if [ -z "$path" ]; then
 
259
    echo "'path' parameter is required"
 
260
    exit 1
 
261
fi
 
262
 
 
263
if [ "$(id -u)" != "0" ]; then
 
264
    echo "This script should be run as 'root'"
 
265
    exit 1
 
266
fi
 
267
 
 
268
rootfs=$path/rootfs
 
269
 
 
270
install_ubuntu $rootfs
 
271
if [ $? -ne 0 ]; then
 
272
    echo "failed to install ubuntu maverick"
 
273
    exit 1
 
274
fi
 
275
 
 
276
configure_ubuntu $rootfs $name
 
277
if [ $? -ne 0 ]; then
 
278
    echo "failed to configure ubuntu maverick for a container"
 
279
    exit 1
 
280
fi
 
281
 
 
282
copy_configuration $path $rootfs $name
 
283
if [ $? -ne 0 ]; then
 
284
    echo "failed write configuration file"
 
285
    exit 1
 
286
fi
 
287
 
 
288
if [ ! -z $clean ]; then
 
289
    clean || exit 1
 
290
    exit 0
 
291
fi