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/debian"
143
mkdir -p @LOCALSTATEDIR@/lock/subsys/
146
if [ $? -ne 0 ]; then
147
echo "Cache repository is busy."
152
if [ "$arch" == "x86_64" ]; then
156
if [ "$arch" == "i686" ]; then
160
echo "Checking cache download in $cache/rootfs-$SUITE-$arch ... "
161
if [ ! -e "$cache/rootfs-$SUITE-$arch" ]; then
162
download_debian $cache $arch
163
if [ $? -ne 0 ]; then
164
echo "Failed to download 'debian base'"
169
copy_debian $cache $arch $rootfs
170
if [ $? -ne 0 ]; then
171
echo "Failed to copy rootfs"
177
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
188
cat <<EOF >> $path/config
192
lxc.cgroup.devices.deny = a
194
lxc.cgroup.devices.allow = c 1:3 rwm
195
lxc.cgroup.devices.allow = c 1:5 rwm
197
lxc.cgroup.devices.allow = c 5:1 rwm
198
lxc.cgroup.devices.allow = c 5:0 rwm
199
lxc.cgroup.devices.allow = c 4:0 rwm
200
lxc.cgroup.devices.allow = c 4:1 rwm
202
lxc.cgroup.devices.allow = c 1:9 rwm
203
lxc.cgroup.devices.allow = c 1:8 rwm
204
lxc.cgroup.devices.allow = c 136:* rwm
205
lxc.cgroup.devices.allow = c 5:2 rwm
207
lxc.cgroup.devices.allow = c 254:0 rwm
210
lxc.mount.entry=proc $rootfs/proc proc nodev,noexec,nosuid 0 0
211
lxc.mount.entry=devpts $rootfs/dev/pts devpts defaults 0 0
212
lxc.mount.entry=sysfs $rootfs/sys sysfs defaults 0 0
215
if [ $? -ne 0 ]; then
216
echo "Failed to add configuration"
225
cache="@LOCALSTATEDIR@/cache/lxc/debian"
227
if [ ! -e $cache ]; then
231
# lock, so we won't purge while someone is creating a repository
235
echo "Cache repository is busy."
239
echo -n "Purging the download cache..."
240
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
243
) 200>@LOCALSTATEDIR@/lock/subsys/lxc
249
$1 -h|--help -p|--path=<path> --clean
254
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
255
if [ $? -ne 0 ]; then
259
eval set -- "$options"
264
-h|--help) usage $0 && exit 0;;
265
-p|--path) path=$2; shift 2;;
266
-n|--name) name=$2; shift 2;;
267
-c|--clean) clean=$2; shift 2;;
268
--) shift 1; break ;;
273
if [ ! -z "$clean" -a -z "$path" ]; then
279
if [ $? -ne 0 ]; then
280
echo "'debootstrap' command is missing"
284
if [ -z "$path" ]; then
285
echo "'path' parameter is required"
289
if [ "$(id -u)" != "0" ]; then
290
echo "This script should be run as 'root'"
296
install_debian $rootfs
297
if [ $? -ne 0 ]; then
298
echo "failed to install debian"
302
configure_debian $rootfs $name
303
if [ $? -ne 0 ]; then
304
echo "failed to configure debian for a container"
308
copy_configuration $path $rootfs
309
if [ $? -ne 0 ]; then
310
echo "failed write configuration file"
314
if [ ! -z $clean ]; then