4
# lxc: linux Container library
7
# Daniel Lezcano <daniel.lezcano@free.fr>
9
# This library is free software; you can redistribute it and/or
10
# modify it under the terms of the GNU Lesser General Public
11
# License as published by the Free Software Foundation; either
12
# version 2.1 of the License, or (at your option) any later version.
14
# This library is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
# Lesser General Public License for more details.
19
# You should have received a copy of the GNU Lesser General Public
20
# License along with this library; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
# configure the inittab
31
cat <<EOF > $rootfs/etc/inittab
33
si::sysinit:/etc/init.d/rcS
34
l0:0:wait:/etc/init.d/rc 0
35
l1:1:wait:/etc/init.d/rc 1
36
l2:2:wait:/etc/init.d/rc 2
37
l3:3:wait:/etc/init.d/rc 3
38
l4:4:wait:/etc/init.d/rc 4
39
l5:5:wait:/etc/init.d/rc 5
40
l6:6:wait:/etc/init.d/rc 6
41
# Normally not reached, but fallthrough in case of emergency.
42
z6:6:respawn:/sbin/sulogin
43
1:2345:respawn:/sbin/getty 38400 console
44
c1:12345:respawn:/sbin/getty 38400 tty1 linux
45
c2:12345:respawn:/sbin/getty 38400 tty2 linux
46
c3:12345:respawn:/sbin/getty 38400 tty3 linux
47
c4:12345:respawn:/sbin/getty 38400 tty4 linux
50
# disable selinux in debian
51
mkdir -p $rootfs/selinux
52
echo 0 > $rootfs/selinux/enforce
54
# configure the network using the dhcp
55
cat <<EOF > $rootfs/etc/network/interfaces
57
iface lo inet loopback
64
cat <<EOF > $rootfs/etc/hostname
68
# reconfigure some services
69
if [ -z "$LANG" ]; then
70
chroot $rootfs locale-gen en_US.UTF-8
71
chroot $rootfs update-locale LANG=en_US.UTF-8
73
chroot $rootfs locale-gen $LANG
74
chroot $rootfs update-locale LANG=$LANG
77
# remove pointless services in a container
78
chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove
79
chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove
80
chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove
82
echo "root:root" | chroot $rootfs chpasswd
83
echo "Root password is 'root', please change !"
104
# check the mini debian was not already downloaded
105
mkdir -p "$cache/partial-$SUITE-$arch"
106
if [ $? -ne 0 ]; then
107
echo "Failed to create '$cache/partial-$SUITE-$arch' directory"
111
# download a mini debian into a cache
112
echo "Downloading debian minimal ..."
113
debootstrap --verbose --variant=minbase --arch=$arch \
114
--include $packages \
115
"$SUITE" "$cache/partial-$SUITE-$arch" http://ftp.debian.org/debian
116
if [ $? -ne 0 ]; then
117
echo "Failed to download the rootfs, aborting."
121
mv "$1/partial-$SUITE-$arch" "$1/rootfs-$SUITE-$arch"
122
echo "Download complete."
133
# make a local copy of the minidebian
134
echo -n "Copying rootfs to $rootfs..."
135
cp -a "$cache/rootfs-$SUITE-$arch" $rootfs || return 1
141
cache="@LOCALSTATEDIR@/cache/lxc/$SUITE"
143
mkdir -p @LOCALSTATEDIR@/lock/subsys/
146
if [ $? -ne 0 ]; then
147
echo "Cache repository is busy."
151
arch=$(dpkg --print-architecture)
153
echo "Checking cache download in $cache/rootfs-$SUITE-$arch ... "
154
if [ ! -e "$cache/rootfs-$SUITE-$arch" ]; then
155
download_debian $cache $arch
156
if [ $? -ne 0 ]; then
157
echo "Failed to download 'debian base'"
162
copy_debian $cache $arch $rootfs
163
if [ $? -ne 0 ]; then
164
echo "Failed to copy rootfs"
170
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
181
cat <<EOF >> $path/config
185
lxc.cgroup.devices.deny = a
187
lxc.cgroup.devices.allow = c 1:3 rwm
188
lxc.cgroup.devices.allow = c 1:5 rwm
190
lxc.cgroup.devices.allow = c 5:1 rwm
191
lxc.cgroup.devices.allow = c 5:0 rwm
192
lxc.cgroup.devices.allow = c 4:0 rwm
193
lxc.cgroup.devices.allow = c 4:1 rwm
195
lxc.cgroup.devices.allow = c 1:9 rwm
196
lxc.cgroup.devices.allow = c 1:8 rwm
197
lxc.cgroup.devices.allow = c 136:* rwm
198
lxc.cgroup.devices.allow = c 5:2 rwm
200
lxc.cgroup.devices.allow = c 254:0 rwm
203
lxc.mount.entry=proc $rootfs/proc proc nodev,noexec,nosuid 0 0
204
lxc.mount.entry=sysfs $rootfs/sys sysfs defaults 0 0
207
if [ $? -ne 0 ]; then
208
echo "Failed to add configuration"
217
cache="@LOCALSTATEDIR@/cache/lxc/$SUITE"
219
if [ ! -e $cache ]; then
223
# lock, so we won't purge while someone is creating a repository
227
echo "Cache repository is busy."
231
echo -n "Purging the download cache..."
232
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
235
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
241
$1 -h|--help -p|--path=<path> --clean
246
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
247
if [ $? -ne 0 ]; then
251
eval set -- "$options"
256
-h|--help) usage $0 && exit 0;;
257
-p|--path) path=$2; shift 2;;
258
-n|--name) name=$2; shift 2;;
259
-c|--clean) clean=$2; shift 2;;
260
--) shift 1; break ;;
265
if [ ! -z "$clean" -a -z "$path" ]; then
271
if [ $? -ne 0 ]; then
272
echo "'debootstrap' command is missing"
276
if [ -z "$path" ]; then
277
echo "'path' parameter is required"
281
if [ "$(id -u)" != "0" ]; then
282
echo "This script should be run as 'root'"
288
install_debian $rootfs
289
if [ $? -ne 0 ]; then
290
echo "failed to install debian"
294
configure_debian $rootfs $name
295
if [ $? -ne 0 ]; then
296
echo "failed to configure debian for a container"
300
copy_configuration $path $rootfs
301
if [ $? -ne 0 ]; then
302
echo "failed write configuration file"
306
if [ ! -z $clean ]; then