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
# Squeeze only has /dev/tty and /dev/tty0 by default,
31
# therefore creating missing device nodes for tty1-4.
32
test -e $rootfs/dev/tty1 || mknod $rootfs/dev/tty1 c 4 1
33
test -e $rootfs/dev/tty2 || mknod $rootfs/dev/tty2 c 4 2
34
test -e $rootfs/dev/tty3 || mknod $rootfs/dev/tty3 c 4 3
35
test -e $rootfs/dev/tty4 || mknod $rootfs/dev/tty4 c 4 4
37
# configure the inittab
38
cat <<EOF > $rootfs/etc/inittab
40
si::sysinit:/etc/init.d/rcS
41
l0:0:wait:/etc/init.d/rc 0
42
l1:1:wait:/etc/init.d/rc 1
43
l2:2:wait:/etc/init.d/rc 2
44
l3:3:wait:/etc/init.d/rc 3
45
l4:4:wait:/etc/init.d/rc 4
46
l5:5:wait:/etc/init.d/rc 5
47
l6:6:wait:/etc/init.d/rc 6
48
# Normally not reached, but fallthrough in case of emergency.
49
z6:6:respawn:/sbin/sulogin
50
1:2345:respawn:/sbin/getty 38400 console
51
c1:12345:respawn:/sbin/getty 38400 tty1 linux
52
c2:12345:respawn:/sbin/getty 38400 tty2 linux
53
c3:12345:respawn:/sbin/getty 38400 tty3 linux
54
c4:12345:respawn:/sbin/getty 38400 tty4 linux
57
# disable selinux in debian
58
mkdir -p $rootfs/selinux
59
echo 0 > $rootfs/selinux/enforce
61
# configure the network using the dhcp
62
cat <<EOF > $rootfs/etc/network/interfaces
64
iface lo inet loopback
71
cat <<EOF > $rootfs/etc/hostname
75
# reconfigure some services
76
if [ -z "$LANG" ]; then
77
chroot $rootfs locale-gen en_US.UTF-8
78
chroot $rootfs update-locale LANG=en_US.UTF-8
80
chroot $rootfs locale-gen $LANG
81
chroot $rootfs update-locale LANG=$LANG
84
# remove pointless services in a container
85
chroot $rootfs /usr/sbin/update-rc.d -f checkroot remove
86
chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove
87
chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove
88
chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove
90
echo "root:root" | chroot $rootfs chpasswd
91
echo "Root password is 'root', please change !"
112
# check the mini debian was not already downloaded
113
mkdir -p "$cache/partial-$SUITE-$arch"
114
if [ $? -ne 0 ]; then
115
echo "Failed to create '$cache/partial-$SUITE-$arch' directory"
119
# download a mini debian into a cache
120
echo "Downloading debian minimal ..."
121
debootstrap --verbose --variant=minbase --arch=$arch \
122
--include $packages \
123
"$SUITE" "$cache/partial-$SUITE-$arch" http://ftp.debian.org/debian
124
if [ $? -ne 0 ]; then
125
echo "Failed to download the rootfs, aborting."
129
mv "$1/partial-$SUITE-$arch" "$1/rootfs-$SUITE-$arch"
130
echo "Download complete."
141
# make a local copy of the minidebian
142
echo -n "Copying rootfs to $rootfs..."
143
cp -a "$cache/rootfs-$SUITE-$arch" $rootfs || return 1
149
cache="@LOCALSTATEDIR@/cache/lxc/debian"
151
mkdir -p @LOCALSTATEDIR@/lock/subsys/
154
if [ $? -ne 0 ]; then
155
echo "Cache repository is busy."
160
if [ "$arch" == "x86_64" ]; then
164
if [ "$arch" == "i686" ]; then
168
echo "Checking cache download in $cache/rootfs-$SUITE-$arch ... "
169
if [ ! -e "$cache/rootfs-$SUITE-$arch" ]; then
170
download_debian $cache $arch
171
if [ $? -ne 0 ]; then
172
echo "Failed to download 'debian base'"
177
copy_debian $cache $arch $rootfs
178
if [ $? -ne 0 ]; then
179
echo "Failed to copy rootfs"
185
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
196
cat <<EOF >> $path/config
200
lxc.cgroup.devices.deny = a
202
lxc.cgroup.devices.allow = c 1:3 rwm
203
lxc.cgroup.devices.allow = c 1:5 rwm
205
lxc.cgroup.devices.allow = c 5:1 rwm
206
lxc.cgroup.devices.allow = c 5:0 rwm
207
lxc.cgroup.devices.allow = c 4:0 rwm
208
lxc.cgroup.devices.allow = c 4:1 rwm
210
lxc.cgroup.devices.allow = c 1:9 rwm
211
lxc.cgroup.devices.allow = c 1:8 rwm
212
lxc.cgroup.devices.allow = c 136:* rwm
213
lxc.cgroup.devices.allow = c 5:2 rwm
215
lxc.cgroup.devices.allow = c 254:0 rwm
218
lxc.mount.entry=proc $rootfs/proc proc nodev,noexec,nosuid 0 0
219
lxc.mount.entry=devpts $rootfs/dev/pts devpts defaults 0 0
220
lxc.mount.entry=sysfs $rootfs/sys sysfs defaults 0 0
223
if [ $? -ne 0 ]; then
224
echo "Failed to add configuration"
233
cache="@LOCALSTATEDIR@/cache/lxc/debian"
235
if [ ! -e $cache ]; then
239
# lock, so we won't purge while someone is creating a repository
243
echo "Cache repository is busy."
247
echo -n "Purging the download cache..."
248
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
251
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
257
$1 -h|--help -p|--path=<path> --clean
262
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
263
if [ $? -ne 0 ]; then
267
eval set -- "$options"
272
-h|--help) usage $0 && exit 0;;
273
-p|--path) path=$2; shift 2;;
274
-n|--name) name=$2; shift 2;;
275
-c|--clean) clean=$2; shift 2;;
276
--) shift 1; break ;;
281
if [ ! -z "$clean" -a -z "$path" ]; then
287
if [ $? -ne 0 ]; then
288
echo "'debootstrap' command is missing"
292
if [ -z "$path" ]; then
293
echo "'path' parameter is required"
297
if [ "$(id -u)" != "0" ]; then
298
echo "This script should be run as 'root'"
304
install_debian $rootfs
305
if [ $? -ne 0 ]; then
306
echo "failed to install debian"
310
configure_debian $rootfs $name
311
if [ $? -ne 0 ]; then
312
echo "failed to configure debian for a container"
316
copy_configuration $path $rootfs
317
if [ $? -ne 0 ]; then
318
echo "failed write configuration file"
322
if [ ! -z $clean ]; then