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
41
$rootfs/usr/share/udhcpc \
49
mkdir -p $tree || return 1
50
chmod 755 $tree || return 1
52
pushd $rootfs/dev > /dev/null || return 1
54
# minimal devices needed for busybox
55
mknod tty c 5 0 || res=1
56
mknod console c 5 1 || res=1
57
chmod 666 tty console || res=1
58
mknod tty0 c 4 0 || res=1
59
mknod tty1 c 4 0 || res=1
60
mknod tty5 c 4 0 || res=1
61
chmod 666 tty0 || res=1
62
mknod ram0 b 1 0 || res=1
63
chmod 600 ram0 || res=1
64
mknod null c 1 3 || res=1
65
chmod 666 null || res=1
70
cat <<EOF >> $rootfs/etc/passwd
71
root:x:0:0:root:/root:/bin/sh
74
cat <<EOF >> $rootfs/etc/group
79
cat <<EOF >> $rootfs/etc/init.d/rcS
87
chmod 744 $rootfs/etc/init.d/rcS || return 1
90
cat <<EOF >> $rootfs/etc/fstab
91
proc /proc proc defaults 0 0
92
shm /dev/shm tmpfs defaults 0 0
95
# writable and readable for other
96
chmod 644 $rootfs/etc/fstab || return 1
98
# launch rcS first then make a console available
99
# and propose a shell on the tty, the last one is
101
cat <<EOF >> $rootfs/etc/inittab
102
::sysinit:/etc/init.d/rcS
103
::respawn:/bin/getty -L tty1 115200 vt100
106
# writable and readable for other
107
chmod 644 $rootfs/etc/inittab || return 1
109
cat <<EOF >> $rootfs/usr/share/udhcpc/default.script
114
ip addr flush dev \$interface
119
# flush all the routes
120
if [ -n "\$router" ]; then
121
ip route del default 2> /dev/null
125
if [ -n "\$broadcast" ]; then
126
broadcast="broadcast \$broadcast"
129
# add a new ip address
130
ip addr add \$ip/\$mask \$broadcast dev \$interface
132
if [ -n "\$router" ]; then
133
ip route add default via \$router dev \$interface
136
[ -n "\$domain" ] && echo search \$domain > /etc/resolv.conf
138
echo nameserver \$i >> /etc/resolv.conf
145
chmod 744 $rootfs/usr/share/udhcpc/default.script
155
[ [[ addgroup adduser adjtimex ar arp arping ash awk basename \
156
brctl bunzip2 bzcat bzip2 cal cat catv chattr chgrp chmod \
157
chown chpasswd chpst chroot chrt chvt cksum clear cmp comm \
158
cp cpio crond crontab cryptpw cut date dc dd deallocvt \
159
delgroup deluser df dhcprelay diff dirname dmesg dnsd dos2unix \
160
du dumpkmap dumpleases echo ed egrep eject env envdir envuidgid \
161
ether-wake expand expr fakeidentd false fbset fdformat fdisk \
162
fetchmail fgrep find findfs fold free freeramdisk fsck \
163
fsck.minix ftpget ftpput fuser getopt getty grep gunzip gzip \
164
halt hdparm head hexdump hostid hostname httpd hwclock id \
165
ifconfig ifdown ifenslave ifup inetd init insmod install ip \
166
ipaddr ipcalc ipcrm ipcs iplink iproute iprule iptunnel \
167
kbd_mode kill killall killall5 klogd last length less linux32 \
168
linux64 linuxrc ln loadfont loadkmap logger login logname \
169
logread losetup lpd lpq lpr ls lsattr lsmod lzmacat makedevs \
170
md5sum mdev mesg microcom mkdir mkfifo mkfs.minix mknod mkswap \
171
mktemp modprobe more mount mountpoint msh mt mv nameif nc \
172
netstat nice nmeter nohup nslookup od openvt passwd patch \
173
pgrep pidof ping ping6 pipe_progress pivot_root pkill poweroff \
174
printenv printf ps pscan pwd raidautorun rdate readahead \
175
readlink readprofile realpath reboot renice reset resize rm \
176
rmdir rmmod route rpm rpm2cpio run-parts runlevel runsv \
177
runsvdir rx script sed sendmail seq setarch setconsole \
178
setkeycodes setlogcons setsid setuidgid sh sha1sum slattach \
179
sleep softlimit sort split start-stop-daemon stat strings \
180
stty su sulogin sum sv svlogd swapoff swapon switch_root \
181
sync sysctl syslogd tac tail tar taskset tcpsvd tee telnet \
182
telnetd test tftp tftpd time top touch tr traceroute \
183
true tty ttysize udhcpc udhcpd udpsvd umount uname uncompress \
184
unexpand uniq unix2dos unlzma unzip uptime usleep uudecode \
185
uuencode vconfig vi vlock watch watchdog wc wget which \
186
who whoami xargs yes zcat zcip"
188
type busybox >/dev/null
190
if [ $? -ne 0 ]; then
191
echo "busybox executable is not accessible"
195
file $(which busybox) | grep -q "statically linked"
196
if [ $? -ne 0 ]; then
197
echo "warning : busybox is not statically linked."
198
echo "warning : The template script may not correctly"
199
echo "warning : setup the container environment."
202
# copy busybox in the rootfs
203
cp $(which busybox) $rootfs/bin
204
if [ $? -ne 0 ]; then
205
echo "failed to copy busybox in the rootfs"
209
# do hardlink to busybox for the different commands
210
for i in $functions; do ln $rootfs/bin/busybox $rootfs/bin/$i; done
213
ln $rootfs/bin/busybox $rootfs/sbin/init
215
# passwd exec must be setuid
216
chmod +s $rootfs/bin/passwd
217
touch $rootfs/etc/shadow
218
chroot $rootfs /bin/passwd -d root
220
echo "No password for 'root', please change !"
231
cat <<EOF >> $path/config
238
if [ -d "$rootfs/lib" ]; then
239
cat <<EOF >> $path/config
240
lxc.mount.entry=/lib $rootfs/lib none ro,bind 0 0
241
lxc.mount.entry=/usr/lib $rootfs/usr/lib none ro,bind 0 0
245
if [ -d "$rootfs/lib64" ]; then
246
cat <<EOF >> $path/config
247
lxc.mount.entry=/lib64 $rootfs/lib64 none ro,bind 0 0
248
lxc.mount.entry=/usr/lib64 $rootfs/usr/lib64 none ro,bind 0 0
256
$1 -h|--help -p|--path=<path>
261
options=$(getopt -o hp:n: -l help,path:,name: -- "$@")
262
if [ $? -ne 0 ]; then
266
eval set -- "$options"
271
-h|--help) usage $0 && exit 0;;
272
-p|--path) path=$2; shift 2;;
273
-n|--name) name=$2; shift 2;;
274
--) shift 1; break ;;
279
if [ "$(id -u)" != "0" ]; then
280
echo "This script should be run as 'root'"
284
if [ -z "$path" ]; then
285
echo "'path' parameter is required"
291
install_busybox $rootfs $name
292
if [ $? -ne 0 ]; then
293
echo "failed to install busybox's rootfs"
297
configure_busybox $rootfs
298
if [ $? -ne 0 ]; then
299
echo "failed to configure busybox template"
303
copy_configuration $path $rootfs $name
304
if [ $? -ne 0 ]; then
305
echo "failed to write configuration file"