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
23
SUITE=${SUITE:-squeeze}
24
MIRROR=${MIRROR:-http://cdn.debian.net/debian}
31
# squeeze only has /dev/tty and /dev/tty0 by default,
32
# therefore creating missing device nodes for tty1-4.
33
for tty in $(seq 1 4); do
34
if [ ! -e $rootfs/dev/tty$tty ]; then
35
mknod $rootfs/dev/tty$tty c 4 $tty
39
# configure the inittab
40
cat <<EOF > $rootfs/etc/inittab
42
si::sysinit:/etc/init.d/rcS
43
l0:0:wait:/etc/init.d/rc 0
44
l1:1:wait:/etc/init.d/rc 1
45
l2:2:wait:/etc/init.d/rc 2
46
l3:3:wait:/etc/init.d/rc 3
47
l4:4:wait:/etc/init.d/rc 4
48
l5:5:wait:/etc/init.d/rc 5
49
l6:6:wait:/etc/init.d/rc 6
50
# Normally not reached, but fallthrough in case of emergency.
51
z6:6:respawn:/sbin/sulogin
52
1:2345:respawn:/sbin/getty 38400 console
53
c1:12345:respawn:/sbin/getty 38400 tty1 linux
54
c2:12345:respawn:/sbin/getty 38400 tty2 linux
55
c3:12345:respawn:/sbin/getty 38400 tty3 linux
56
c4:12345:respawn:/sbin/getty 38400 tty4 linux
59
# disable selinux in debian
60
mkdir -p $rootfs/selinux
61
echo 0 > $rootfs/selinux/enforce
63
# configure the network using the dhcp
64
cat <<EOF > $rootfs/etc/network/interfaces
66
iface lo inet loopback
73
cat <<EOF > $rootfs/etc/hostname
77
# reconfigure some services
78
if [ -z "$LANG" ]; then
79
chroot $rootfs locale-gen en_US.UTF-8 UTF-8
80
chroot $rootfs update-locale LANG=en_US.UTF-8
82
chroot $rootfs locale-gen $LANG $(echo $LANG | cut -d. -f2)
83
chroot $rootfs update-locale LANG=$LANG
86
# remove pointless services in a container
87
chroot $rootfs /usr/sbin/update-rc.d -f checkroot.sh remove
88
chroot $rootfs /usr/sbin/update-rc.d -f umountfs remove
89
chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove
90
chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove
91
chroot $rootfs /usr/sbin/update-rc.d -f module-init-tools remove
93
echo "root:root" | chroot $rootfs chpasswd
94
echo "Root password is 'root', please change !"
115
# check the mini debian was not already downloaded
116
mkdir -p "$cache/partial-$SUITE-$arch"
117
if [ $? -ne 0 ]; then
118
echo "Failed to create '$cache/partial-$SUITE-$arch' directory"
122
# download a mini debian into a cache
123
echo "Downloading debian minimal ..."
124
debootstrap --verbose --variant=minbase --arch=$arch \
125
--include=$packages \
126
"$SUITE" "$cache/partial-$SUITE-$arch" $MIRROR
127
if [ $? -ne 0 ]; then
128
echo "Failed to download the rootfs, aborting."
132
mv "$1/partial-$SUITE-$arch" "$1/rootfs-$SUITE-$arch"
133
echo "Download complete."
144
# make a local copy of the minidebian
145
echo -n "Copying rootfs to $rootfs..."
146
cp -a "$cache/rootfs-$SUITE-$arch" $rootfs || return 1
152
cache="@LOCALSTATEDIR@/cache/lxc/debian"
154
mkdir -p @LOCALSTATEDIR@/lock/subsys/
157
if [ $? -ne 0 ]; then
158
echo "Cache repository is busy."
162
# Code taken from debootstrap
163
if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
164
arch=`/usr/bin/dpkg --print-architecture`
165
elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
166
arch=`/usr/bin/udpkg --print-architecture`
169
if [ "$arch" = "i686" ]; then
171
elif [ "$arch" = "x86_64" ]; then
176
echo "Checking cache download in $cache/rootfs-$SUITE-$arch ... "
177
if [ ! -e "$cache/rootfs-$SUITE-$arch" ]; then
178
download_debian $cache $arch
179
if [ $? -ne 0 ]; then
180
echo "Failed to download 'debian base'"
185
copy_debian $cache $arch $rootfs
186
if [ $? -ne 0 ]; then
187
echo "Failed to copy rootfs"
193
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
204
cat <<EOF >> $path/config
208
lxc.cgroup.devices.deny = a
210
lxc.cgroup.devices.allow = c 1:3 rwm
211
lxc.cgroup.devices.allow = c 1:5 rwm
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
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
223
lxc.cgroup.devices.allow = c 254:0 rwm
226
lxc.mount.entry=proc $rootfs/proc proc nodev,noexec,nosuid 0 0
227
lxc.mount.entry=sysfs $rootfs/sys sysfs defaults 0 0
230
if [ $? -ne 0 ]; then
231
echo "Failed to add configuration"
240
cache="@LOCALSTATEDIR@/cache/lxc/debian"
242
if [ ! -e $cache ]; then
246
# lock, so we won't purge while someone is creating a repository
250
echo "Cache repository is busy."
254
echo -n "Purging the download cache..."
255
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
258
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
264
$1 -h|--help -p|--path=<path> --clean
269
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
270
if [ $? -ne 0 ]; then
274
eval set -- "$options"
279
-h|--help) usage $0 && exit 0;;
280
-p|--path) path=$2; shift 2;;
281
-n|--name) name=$2; shift 2;;
282
-c|--clean) clean=$2; shift 2;;
283
--) shift 1; break ;;
288
if [ ! -z "$clean" -a -z "$path" ]; then
294
if [ $? -ne 0 ]; then
295
echo "'debootstrap' command is missing"
299
if [ -z "$path" ]; then
300
echo "'path' parameter is required"
304
if [ "$(id -u)" != "0" ]; then
305
echo "This script should be run as 'root'"
311
install_debian $rootfs
312
if [ $? -ne 0 ]; then
313
echo "failed to install debian"
317
configure_debian $rootfs $name
318
if [ $? -ne 0 ]; then
319
echo "failed to configure debian for a container"
323
copy_configuration $path $rootfs
324
if [ $? -ne 0 ]; then
325
echo "failed write configuration file"
329
if [ ! -z $clean ]; then