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
40
$rootfs/usr/share/udhcpc \
43
mkdir -p $tree || return 1
44
chmod 755 $tree || return 1
46
pushd $rootfs/dev > /dev/null || return 1
48
# minimal devices needed for busybox
49
mknod tty c 5 0 || res=1
50
mknod console c 5 1 || res=1
51
chmod 666 tty console || res=1
52
mknod tty0 c 4 0 || res=1
53
mknod tty1 c 4 0 || res=1
54
mknod tty5 c 4 0 || res=1
55
chmod 666 tty0 || res=1
56
mknod ram0 b 1 0 || res=1
57
chmod 600 ram0 || res=1
58
mknod null c 1 3 || res=1
59
chmod 666 null || res=1
64
cat <<EOF >> $rootfs/etc/passwd
65
root:x:0:0:root:/root:/bin/sh
68
cat <<EOF >> $rootfs/etc/group
73
cat <<EOF >> $rootfs/etc/shadow
74
root:\$1\$NJJLsV0P\$Y/esfSXDNR88G/bZFzgWY1:14595:0:99999:7:::
77
echo "empty password for root, don't forget to change it !"
80
cat <<EOF >> $rootfs/etc/init.d/rcS
88
chmod 744 $rootfs/etc/init.d/rcS || return 1
91
cat <<EOF >> $rootfs/etc/fstab
92
proc /proc proc defaults 0 0
93
shm /dev/shm tmpfs defaults 0 0
96
# writable and readable for other
97
chmod 644 $rootfs/etc/fstab || return 1
99
# launch rcS first then make a console available
100
# and propose a shell on the tty, the last one is
102
cat <<EOF >> $rootfs/etc/inittab
103
::sysinit:/etc/init.d/rcS
104
::respawn:/bin/getty -L tty1 115200 vt100
107
# writable and readable for other
108
chmod 644 $rootfs/etc/inittab || return 1
110
cat <<EOF >> $rootfs/usr/share/udhcpc/default.script
115
ip addr flush dev \$interface
120
# flush all the routes
121
if [ -n "\$router" ]; then
122
ip route del default 2> /dev/null
126
if [ -n "\$broadcast" ]; then
127
broadcast="broadcast \$broadcast"
130
# add a new ip address
131
ip addr add \$ip/\$mask \$broadcast dev \$interface
133
if [ -n "\$router" ]; then
134
ip route add default via \$router dev \$interface
137
[ -n "\$domain" ] && echo search \$domain > /etc/resolv.conf
139
echo nameserver \$i >> /etc/resolv.conf
146
chmod 744 $rootfs/usr/share/udhcpc/default.script
156
[ [[ addgroup adduser adjtimex ar arp arping ash awk basename \
157
brctl bunzip2 bzcat bzip2 cal cat catv chattr chgrp chmod \
158
chown chpasswd chpst chroot chrt chvt cksum clear cmp comm \
159
cp cpio crond crontab cryptpw cut date dc dd deallocvt \
160
delgroup deluser df dhcprelay diff dirname dmesg dnsd dos2unix \
161
du dumpkmap dumpleases echo ed egrep eject env envdir envuidgid \
162
ether-wake expand expr fakeidentd false fbset fdformat fdisk \
163
fetchmail fgrep find findfs fold free freeramdisk fsck \
164
fsck.minix ftpget ftpput fuser getopt getty grep gunzip gzip \
165
halt hdparm head hexdump hostid hostname httpd hwclock id \
166
ifconfig ifdown ifenslave ifup inetd init insmod install ip \
167
ipaddr ipcalc ipcrm ipcs iplink iproute iprule iptunnel \
168
kbd_mode kill killall killall5 klogd last length less linux32 \
169
linux64 linuxrc ln loadfont loadkmap logger login logname \
170
logread losetup lpd lpq lpr ls lsattr lsmod lzmacat makedevs \
171
md5sum mdev mesg microcom mkdir mkfifo mkfs.minix mknod mkswap \
172
mktemp modprobe more mount mountpoint msh mt mv nameif nc \
173
netstat nice nmeter nohup nslookup od openvt passwd patch \
174
pgrep pidof ping ping6 pipe_progress pivot_root pkill poweroff \
175
printenv printf ps pscan pwd raidautorun rdate readahead \
176
readlink readprofile realpath reboot renice reset resize rm \
177
rmdir rmmod route rpm rpm2cpio run-parts runlevel runsv \
178
runsvdir rx script sed sendmail seq setarch setconsole \
179
setkeycodes setlogcons setsid setuidgid sh sha1sum slattach \
180
sleep softlimit sort split start-stop-daemon stat strings \
181
stty su sulogin sum sv svlogd swapoff swapon switch_root \
182
sync sysctl syslogd tac tail tar taskset tcpsvd tee telnet \
183
telnetd test tftp tftpd time top touch tr traceroute \
184
true tty ttysize udhcpc udhcpd udpsvd umount uname uncompress \
185
unexpand uniq unix2dos unlzma unzip uptime usleep uudecode \
186
uuencode vconfig vi vlock watch watchdog wc wget which \
187
who whoami xargs yes zcat zcip"
189
type busybox >/dev/null
191
if [ $? -ne 0 ]; then
192
echo "busybox executable is not accessible"
196
# copy busybox in the rootfs
197
cp $(which busybox) $rootfs/bin
198
if [ $? -ne 0 ]; then
199
echo "failed to copy busybox in the rootfs"
203
# do hardlink to busybox for the different commands
204
for i in $functions; do ln $rootfs/bin/busybox $rootfs/bin/$i; done
207
ln $rootfs/bin/busybox $rootfs/sbin/init
209
# passwd exec must be setuid
210
chmod +s $rootfs/bin/passwd
221
cat <<EOF >> $path/config
225
lxc.cgroup.devices.deny = a
227
lxc.cgroup.devices.allow = c 1:3 rwm
228
lxc.cgroup.devices.allow = c 1:5 rwm
230
lxc.cgroup.devices.allow = c 5:1 rwm
231
lxc.cgroup.devices.allow = c 5:0 rwm
232
lxc.cgroup.devices.allow = c 4:0 rwm
233
lxc.cgroup.devices.allow = c 4:1 rwm
235
lxc.cgroup.devices.allow = c 1:9 rwm
236
lxc.cgroup.devices.allow = c 1:8 rwm
237
lxc.cgroup.devices.allow = c 136:* rwm
238
lxc.cgroup.devices.allow = c 5:2 rwm
240
lxc.cgroup.devices.allow = c 254:0 rwm
247
$1 -h|--help -p|--path=<path>
252
options=$(getopt -o hp:n: -l help,path:,name: -- "$@")
253
if [ $? -ne 0 ]; then
257
eval set -- "$options"
262
-h|--help) usage $0 && exit 0;;
263
-p|--path) path=$2; shift 2;;
264
-n|--name) name=$2; shift 2;;
265
--) shift 1; break ;;
270
if [ "$(id -u)" != "0" ]; then
271
echo "This script should be run as 'root'"
275
if [ -z "$path" ]; then
276
echo "'path' parameter is required"
282
install_busybox $rootfs $name
283
if [ $? -ne 0 ]; then
284
echo "failed to install busybox's rootfs"
288
configure_busybox $rootfs
289
if [ $? -ne 0 ]; then
290
echo "failed to configure busybox template"
294
copy_configuration $path $rootfs $name
295
if [ $? -ne 0 ]; then
296
echo "failed to write configuration file"