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

« back to all changes in this revision

Viewing changes to .pc/0009-templates-dont-use-devpts-in-fstab/templates/lxc-fedora.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 fedora container for LXC
5
 
#
6
 
 
7
 
#
8
 
# lxc: linux Container library
9
 
 
10
 
# Authors:
11
 
# Daniel Lezcano <daniel.lezcano@free.fr>
12
 
 
13
 
# This library is free software; you can redistribute it and/or
14
 
# modify it under the terms of the GNU Lesser General Public
15
 
# License as published by the Free Software Foundation; either
16
 
# version 2.1 of the License, or (at your option) any later version.
17
 
 
18
 
# This library is distributed in the hope that it will be useful,
19
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 
# Lesser General Public License for more details.
22
 
 
23
 
# You should have received a copy of the GNU Lesser General Public
24
 
# License along with this library; if not, write to the Free Software
25
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
 
 
27
 
DISTRO=fedora-10
28
 
 
29
 
configure_fedora()
30
 
{
31
 
    rootfs=$1
32
 
    hostname=$2
33
 
 
34
 
    # disable selinux in fedora
35
 
    mkdir -p $rootfs/selinux
36
 
    echo 0 > $rootfs/selinux/enforce
37
 
 
38
 
   # configure the network using the dhcp
39
 
    cat <<EOF > $rootfs/etc/network/interfaces
40
 
auto lo
41
 
iface lo inet loopback
42
 
 
43
 
auto eth0
44
 
iface eth0 inet dhcp
45
 
EOF
46
 
 
47
 
    # set the hostname
48
 
    cat <<EOF > $rootfs/etc/hostname
49
 
$hostname
50
 
EOF
51
 
    # set minimal hosts
52
 
    cat <<EOF > $rootfs/etc/hosts
53
 
127.0.0.1 localhost $hostname
54
 
EOF
55
 
 
56
 
    # provide the lxc service
57
 
    cat <<EOF > $rootfs/etc/init/lxc.conf
58
 
# fake some events needed for correct startup other services
59
 
 
60
 
description     "Container Upstart"
61
 
 
62
 
start on startup
63
 
 
64
 
script
65
 
        rm -rf /var/run/*.pid
66
 
        rm -rf /var/run/network/*
67
 
        /sbin/initctl emit stopped JOB=udevtrigger --no-wait
68
 
        /sbin/initctl emit started JOB=udev --no-wait
69
 
end script
70
 
EOF
71
 
 
72
 
    cat <<EOF > $rootfs/etc/init/console.conf
73
 
# console - getty
74
 
#
75
 
# This service maintains a console on tty1 from the point the system is
76
 
# started until it is shut down again.
77
 
 
78
 
start on stopped rc RUNLEVEL=[2345]
79
 
stop on runlevel [!2345]
80
 
 
81
 
respawn
82
 
exec /sbin/getty -8 38400 /dev/console
83
 
EOF
84
 
 
85
 
    cat <<EOF > $rootfs/lib/init/fstab
86
 
# /lib/init/fstab: lxc system fstab
87
 
none            /spu                      spufs           gid=spu,optional                  0 0
88
 
none            /tmp                      none            defaults                          0 0
89
 
none            /var/lock                 tmpfs           nodev,noexec,nosuid,showthrough   0 0
90
 
none            /lib/init/rw              tmpfs           mode=0755,nosuid,optional         0 0
91
 
EOF
92
 
 
93
 
    # reconfigure some services
94
 
    if [ -z "$LANG" ]; then
95
 
        chroot $rootfs locale-gen en_US.UTF-8
96
 
        chroot $rootfs update-locale LANG=en_US.UTF-8
97
 
    else
98
 
        chroot $rootfs locale-gen $LANG
99
 
        chroot $rootfs update-locale LANG=$LANG
100
 
    fi
101
 
 
102
 
    # remove pointless services in a container
103
 
    chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove
104
 
 
105
 
    chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do mv $f $f.orig; done'
106
 
    chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do mv $f $f.orig; done'
107
 
    chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); do mv $f $f.orig; done'
108
 
    chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do mv $f $f.orig; done'
109
 
    chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do mv $f $f.orig; done'
110
 
 
111
 
    echo "Please change root-password !"
112
 
    echo "root:root" | chroot $rootfs chpasswd
113
 
 
114
 
    return 0
115
 
}
116
 
 
117
 
download_fedora()
118
 
{
119
 
    cache=$1
120
 
    arch=$2
121
 
 
122
 
    # check the mini fedora was not already downloaded
123
 
    mkdir -p "$cache/partial-$arch"
124
 
    if [ $? -ne 0 ]; then
125
 
        echo "Failed to create '$cache/partial-$arch' directory"
126
 
        return 1
127
 
    fi
128
 
 
129
 
    # download a mini fedora into a cache
130
 
    echo "Downloading fedora minimal ..."
131
 
    febootstrap $DISTRO $cache/partial-$arch
132
 
    if [ $? -ne 0 ]; then
133
 
        echo "Failed to download the rootfs, aborting."
134
 
        return 1
135
 
    fi
136
 
 
137
 
    mv "$1/partial-$arch" "$1/rootfs-$arch"
138
 
    echo "Download complete."
139
 
 
140
 
    return 0
141
 
}
142
 
 
143
 
copy_fedora()
144
 
{
145
 
    cache=$1
146
 
    arch=$2
147
 
    rootfs=$3
148
 
 
149
 
    # make a local copy of the minifedora
150
 
    echo -n "Copying rootfs to $rootfs ..."
151
 
    cp -a $cache/rootfs-$arch $rootfs || return 1
152
 
    return 0
153
 
}
154
 
 
155
 
install_fedora()
156
 
{
157
 
    cache="/var/cache/lxc/fedora"
158
 
    rootfs=$1
159
 
    mkdir -p /var/lock/subsys/
160
 
    (
161
 
        flock -n -x 200
162
 
        if [ $? -ne 0 ]; then
163
 
            echo "Cache repository is busy."
164
 
            return 1
165
 
        fi
166
 
 
167
 
        arch=$(arch)
168
 
 
169
 
        echo "Checking cache download in $cache/rootfs-$arch ... "
170
 
        if [ ! -e "$cache/rootfs-$arch" ]; then
171
 
            download_fedora $cache $arch
172
 
            if [ $? -ne 0 ]; then
173
 
                echo "Failed to download 'fedora base'"
174
 
                return 1
175
 
            fi
176
 
        fi
177
 
 
178
 
        echo "Copy $cache/rootfs-$arch to $rootfs ... "
179
 
        copy_fedora $cache $arch $rootfs
180
 
        if [ $? -ne 0 ]; then
181
 
            echo "Failed to copy rootfs"
182
 
            return 1
183
 
        fi
184
 
 
185
 
        return 0
186
 
 
187
 
        ) 200>/var/lock/subsys/lxc
188
 
 
189
 
    return $?
190
 
}
191
 
 
192
 
copy_configuration()
193
 
{
194
 
    path=$1
195
 
    rootfs=$2
196
 
    name=$3
197
 
 
198
 
    cat <<EOF >> $path/config
199
 
lxc.utsname = $name
200
 
 
201
 
lxc.tty = 4
202
 
lxc.pts = 1024
203
 
lxc.rootfs = $rootfs
204
 
lxc.mount  = $path/fstab
205
 
 
206
 
lxc.console = /dev/console
207
 
 
208
 
lxc.cgroup.devices.deny = a
209
 
# /dev/null and zero
210
 
lxc.cgroup.devices.allow = c 1:3 rwm
211
 
lxc.cgroup.devices.allow = c 1:5 rwm
212
 
# consoles
213
 
lxc.cgroup.devices.allow = c 5:1 rwm
214
 
lxc.cgroup.devices.allow = c 5:0 rwm
215
 
lxc.cgroup.devices.allow = c 4:0 rwm
216
 
lxc.cgroup.devices.allow = c 4:1 rwm
217
 
# /dev/{,u}random
218
 
lxc.cgroup.devices.allow = c 1:9 rwm
219
 
lxc.cgroup.devices.allow = c 1:8 rwm
220
 
lxc.cgroup.devices.allow = c 136:* rwm
221
 
lxc.cgroup.devices.allow = c 5:2 rwm
222
 
# rtc
223
 
lxc.cgroup.devices.allow = c 254:0 rwm
224
 
EOF
225
 
 
226
 
    cat <<EOF > $path/fstab
227
 
proc            $rootfs/proc         proc    nodev,noexec,nosuid 0 0
228
 
devpts          $rootfs/dev/pts      devpts defaults 0 0
229
 
sysfs           $rootfs/sys          sysfs defaults  0 0
230
 
EOF
231
 
 
232
 
    if [ $? -ne 0 ]; then
233
 
        echo "Failed to add configuration"
234
 
        return 1
235
 
    fi
236
 
 
237
 
    return 0
238
 
}
239
 
 
240
 
clean()
241
 
{
242
 
    cache="/var/cache/lxc/fedora"
243
 
 
244
 
    if [ ! -e $cache ]; then
245
 
        exit 0
246
 
    fi
247
 
 
248
 
    # lock, so we won't purge while someone is creating a repository
249
 
    (
250
 
        flock -n -x 200
251
 
        if [ $? != 0 ]; then
252
 
            echo "Cache repository is busy."
253
 
            exit 1
254
 
        fi
255
 
 
256
 
        echo -n "Purging the download cache..."
257
 
        rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
258
 
        exit 0
259
 
 
260
 
    ) 200>/var/lock/subsys/lxc
261
 
}
262
 
 
263
 
usage()
264
 
{
265
 
    cat <<EOF
266
 
$1 -h|--help -p|--path=<path> --clean
267
 
EOF
268
 
    return 0
269
 
}
270
 
 
271
 
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
272
 
if [ $? -ne 0 ]; then
273
 
    usage $(basename $0)
274
 
    exit 1
275
 
fi
276
 
eval set -- "$options"
277
 
 
278
 
while true
279
 
do
280
 
    case "$1" in
281
 
        -h|--help)      usage $0 && exit 0;;
282
 
        -p|--path)      path=$2; shift 2;;
283
 
        -n|--name)      name=$2; shift 2;;
284
 
        -c|--clean)     clean=$2; shift 2;;
285
 
        --)             shift 1; break ;;
286
 
        *)              break ;;
287
 
    esac
288
 
done
289
 
 
290
 
if [ ! -z "$clean" -a -z "$path" ]; then
291
 
    clean || exit 1
292
 
    exit 0
293
 
fi
294
 
 
295
 
type febootstrap
296
 
if [ $? -ne 0 ]; then
297
 
    echo "'febootstrap' command is missing"
298
 
    exit 1
299
 
fi
300
 
 
301
 
if [ -z "$path" ]; then
302
 
    echo "'path' parameter is required"
303
 
    exit 1
304
 
fi
305
 
 
306
 
if [ "$(id -u)" != "0" ]; then
307
 
    echo "This script should be run as 'root'"
308
 
    exit 1
309
 
fi
310
 
 
311
 
rootfs=$path/rootfs
312
 
 
313
 
install_fedora $rootfs
314
 
if [ $? -ne 0 ]; then
315
 
    echo "failed to install fedora"
316
 
    exit 1
317
 
fi
318
 
 
319
 
configure_fedora $rootfs $name
320
 
if [ $? -ne 0 ]; then
321
 
    echo "failed to configure fedora for a container"
322
 
    exit 1
323
 
fi
324
 
 
325
 
copy_configuration $path $rootfs $name
326
 
if [ $? -ne 0 ]; then
327
 
    echo "failed write configuration file"
328
 
    exit 1
329
 
fi
330
 
 
331
 
if [ ! -z $clean ]; then
332
 
    clean || exit 1
333
 
    exit 0
334
 
fi