]>
git.proxmox.com Git - mirror_lxc.git/blob - templates/lxc-busybox.in
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
43 $rootfs/usr/share/udhcpc \
51 mkdir
-p $tree ||
return 1
52 chmod 755 $tree ||
return 1
54 pushd $rootfs/dev
> /dev
/null ||
return 1
56 # minimal devices needed for busybox
57 mknod tty c
5 0 || res
=1
58 mknod console c
5 1 || res
=1
59 chmod 666 tty console || res
=1
60 mknod tty0 c
4 0 || res
=1
61 mknod tty1 c
4 0 || res
=1
62 mknod tty5 c
4 0 || res
=1
63 chmod 666 tty0 || res
=1
64 mknod ram0 b
1 0 || res
=1
65 chmod 600 ram0 || res
=1
66 mknod null c
1 3 || res
=1
67 chmod 666 null || res
=1
68 mknod urandom c
1 9 || res
=1
69 chmod 666 urandom || res
=1
74 cat <<EOF >> $rootfs/etc/passwd
75 root:x:0:0:root:/root:/bin/sh
78 cat <<EOF >> $rootfs/etc/group
83 cat <<EOF >> $rootfs/etc/init.d/rcS
91 chmod 744 $rootfs/etc
/init.d
/rcS ||
return 1
94 cat <<EOF >> $rootfs/etc/fstab
95 proc /proc proc defaults 0 0
96 shm /dev/shm tmpfs defaults 0 0
99 # writable and readable for other
100 chmod 644 $rootfs/etc
/fstab ||
return 1
102 # launch rcS first then make a console available
103 # and propose a shell on the tty, the last one is
105 cat <<EOF >> $rootfs/etc/inittab
106 ::sysinit:/etc/init.d/rcS
107 tty1::respawn:/bin/getty -L tty1 115200 vt100
108 console::askfirst:/bin/sh
110 # writable and readable for other
111 chmod 644 $rootfs/etc
/inittab ||
return 1
113 cat <<EOF >> $rootfs/usr/share/udhcpc/default.script
117 ip addr flush dev \$interface
121 # flush all the routes
122 if [ -n "\$router" ]; then
123 ip route del default 2> /dev/null
127 if [ -n "\$broadcast" ]; then
128 broadcast="broadcast \$broadcast"
131 # add a new ip address
132 ip addr add \$ip/\$mask \$broadcast dev \$interface
134 if [ -n "\$router" ]; then
135 ip route add default via \$router dev \$interface
138 [ -n "\$domain" ] && echo search \$domain > /etc/resolv.conf
140 echo nameserver \$i >> /etc/resolv.conf
147 chmod 744 $rootfs/usr
/share
/udhcpc
/default.
script
156 which busybox
>/dev
/null
2>&1
158 if [ $?
-ne 0 ]; then
159 echo "busybox executable is not accessible"
163 file $
(which busybox
) |
grep -q "statically linked"
164 if [ $?
-ne 0 ]; then
165 echo "warning : busybox is not statically linked."
166 echo "warning : The template script may not correctly"
167 echo "warning : setup the container environment."
170 # copy busybox in the rootfs
171 cp $
(which busybox
) $rootfs/bin
172 if [ $?
-ne 0 ]; then
173 echo "failed to copy busybox in the rootfs"
177 # symlink busybox for the commands it supports
178 # it would be nice to just use "chroot $rootfs busybox --install -s /bin"
179 # but that only works right in a chroot with busybox >= 1.19.0
180 pushd $rootfs/bin
> /dev
/null ||
return 1
181 .
/busybox
--help |
grep 'Currently defined functions:' -A300 | \
182 grep -v 'Currently defined functions:' |
tr , '\n' | \
183 xargs -n1 ln -s busybox
187 ln $rootfs/bin
/busybox
$rootfs/sbin
/init
189 # passwd exec must be setuid
190 chmod +s
$rootfs/bin
/passwd
191 touch $rootfs/etc
/shadow
193 # setting passwd for root
194 CHPASSWD_FILE
=$rootfs/root
/chpasswd.sh
196 cat <<EOF >$CHPASSWD_FILE
197 echo "setting root password to \"root\""
199 mount --bind /lib $rootfs/lib
200 if [ \$? -ne 0 ]; then
201 echo "Failed bind-mounting /lib at $rootfs/lib"
205 chroot $rootfs chpasswd <<EOFF 2>/dev/null
210 if [ \$? -ne 0 ]; then
211 echo "Failed to change root password"
219 lxc-unshare
-s MOUNT
-- /bin
/sh
< $CHPASSWD_FILE
222 # add ssh functionality if dropbear package available on host
223 which dropbear
>/dev
/null
2>&1
224 if [ $?
-eq 0 ]; then
225 # copy dropbear binary
226 cp $
(which dropbear
) $rootfs/usr
/sbin
227 if [ $?
-ne 0 ]; then
228 echo "Failed to copy dropbear in the rootfs"
232 # make symlinks to various ssh utilities
234 $rootfs/usr/bin/dbclient \
235 $rootfs/usr/bin/scp \
236 $rootfs/usr/bin/ssh \
237 $rootfs/usr/sbin/dropbearkey \
238 $rootfs/usr/sbin/dropbearconvert \
240 echo $utils |
xargs -n1 ln -s /usr
/sbin
/dropbear
242 # add necessary config files
243 mkdir
$rootfs/etc
/dropbear
244 dropbearkey
-t rsa
-f $rootfs/etc
/dropbear
/dropbear_rsa_host_key
&> /dev
/null
245 dropbearkey
-t dss
-f $rootfs/etc
/dropbear
/dropbear_dss_host_key
&> /dev
/null
247 echo "'dropbear' ssh utility installed"
259 grep -q "^lxc.rootfs" $path/config
2>/dev
/null ||
echo "lxc.rootfs = $rootfs" >> $path/config
260 cat <<EOF >> $path/config
264 lxc.cap.drop = sys_module mac_admin mac_override sys_time
266 # When using LXC with apparmor, uncomment the next line to run unconfined:
267 #lxc.aa_profile = unconfined
276 for dir
in $libdirs; do
277 if [ -d "/$dir" ] && [ -d "$rootfs/$dir" ]; then
278 echo "lxc.mount.entry = /$dir $dir none ro,bind 0 0" >> $path/config
286 $1 -h|--help -p|--path=<path>
291 options
=$
(getopt
-o hp
:n
: -l help,rootfs
:,path
:,name
: -- "$@")
292 if [ $?
-ne 0 ]; then
296 eval set -- "$options"
301 -h|
--help) usage
$0 && exit 0;;
302 -p|
--path) path
=$2; shift 2;;
303 --rootfs) rootfs
=$2; shift 2;;
304 -n|
--name) name
=$2; shift 2;;
305 --) shift 1; break ;;
310 if [ "$(id -u)" != "0" ]; then
311 echo "This script should be run as 'root'"
315 if [ -z "$path" ]; then
316 echo "'path' parameter is required"
321 config
="$path/config"
322 if [ -z "$rootfs" ]; then
323 if grep -q '^lxc.rootfs' $config 2>/dev
/null
; then
324 rootfs
=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
330 install_busybox
$rootfs $name
331 if [ $?
-ne 0 ]; then
332 echo "failed to install busybox's rootfs"
336 configure_busybox
$rootfs
337 if [ $?
-ne 0 ]; then
338 echo "failed to configure busybox template"
342 copy_configuration
$path $rootfs $name
343 if [ $?
-ne 0 ]; then
344 echo "failed to write configuration file"