0

I have a script that runs on startup, but it wont launch a application in chroot.

#!/bin/sh 
/usr/sbin/chroot /root/chrootdir/ /bin/sh -c "lighttpd -f /etc/lighttpd.conf -m /lib" 
echo "script activated" >> /log/www.log

the log file is written/appended on startup, but the lighttpd server is not starting. Running the script when the box is running works fine and launches lighttpd. This is a embedded system running a linux kernel and busybox. inittab triggers /etc/init.d/rcS that in turn run my start_www script. the start_www script is the last thing rcS launches.

Update:

/bin/sh: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory

but libm.so.6 is located in /root/chrootdir/lib/libm.so.6 what to do now? how do i specify the libm.so path? tried the command "export LD_LIBRARY_PATH=/lib; lighttpd -f /etc/lighttpd.conf -m /lib" without success.

Update 2: . when i run the command:

chroot /root/chrootdir/ /sbin/lighttpd -f /etc/lighttpd.conf -m /lib

it launches the webserver without any warning or error. But when I launch the same script during startup, the script suddenly is unable to find the libs. Inside my chrootdir i got a .profile file containing:

export LD_LIBRARY_PATH=/lib

my guess is that the .profile settings file is not used during startup how do i set the library path?

Maidenone
  • 103
  • 1
  • 6
  • Append `> /log/lighttpd.log 2>&1` to the end of second line, then try again to see what happens. – quanta Aug 21 '12 at 09:48
  • i have /log/lighttpd/error.log and access.log, no errors where generated during startup. it is like it never runs at all. – Maidenone Aug 21 '12 at 10:01
  • No. I mean append it to the end of `/usr/sbin/chroot /root/chrootdir/ /bin/sh -c "lighttpd -f /etc/lighttpd.conf -m /lib"` in your script to redirect both stdout and stderr to a file to see what's going on. – quanta Aug 21 '12 at 10:03
  • /bin/sh: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory and: /root/chrootdir/lib/libm.so.6 thats strange.. – Maidenone Aug 21 '12 at 10:13
  • `ldd /root/chrootdir/bin/sh`? – quanta Aug 21 '12 at 10:46
  • ldd does not exist. the root system is built with uClibc and the chrootdir is built with glibc. – Maidenone Aug 21 '12 at 11:24
  • Can you execute this commands? : `ldd /tools/bin/bash` and `ldd /bin/bash` – dave Aug 21 '12 at 11:26
  • i do not have ldd – Maidenone Aug 21 '12 at 14:38
  • @Maidenone, `LD_DEBUG=files` is ur friend. See `man ld.so` – poige Aug 21 '12 at 14:58
  • setting `LD_DEBUG=files` does not give any more debug info. the only output i get is : `/sbin/lighttpd: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory`. This file is only located in /lib in the chroot dir. the lighttpd MUST use the /root/chrootdir/lib, or it wont work because of different versions of libc. – Maidenone Aug 22 '12 at 12:08

3 Answers3

0

Instead of chroot-issuing /bin/sh -c "lighttpd -f /etc/lighttpd.conf -m /lib" try running the same command inside shell-script put into chroot, kinda:

/sbin/chroot /root/chrootdir/ /start_it_up.sh

UPD.: Well, accumulating everything I've suggested in my comments to that answer:

  1. mount --bind your parent system libs into chroot's lib dirs — at least to test whether it would work at all
  2. Use ld's flag LD_DEBUG=files to find out what dependencies could some libraries have, since they also influence in overall failure to preload the target
poige
  • 9,171
  • 2
  • 24
  • 50
  • Good idea, but the default terminal is still /bin/sh, which gives the same error. /bin/sh: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory – Maidenone Aug 21 '12 at 11:54
  • @Maidenone, default what? Default shell? Well, have you tried running just `chroot /root/chrootdir/` — what's the output? + U can use `"#!/any/exec` in header, you know? – poige Aug 21 '12 at 13:05
  • @Maidenone, also, according to `man chroot` you should be able to give all the args w/o shell: `chroot /root/chrootdir/ /path2/lighttpd -f /etc/lighttpd.conf -m /lib` — just like that – poige Aug 21 '12 at 13:10
  • `chroot /root/chrootdir/ /sbin/lighttpd -f /etc/lighttpd.conf -m /lib` gives the following error: `/sbin/lighttpd: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory` and the libpcre.so.1 file is located in /root/chrootdir/lib/ the same error but another program. So i still need to define the path in some way. – Maidenone Aug 21 '12 at 14:44
  • @Maidenone, u still need to have every needed libs inside chroot, that's it. – poige Aug 21 '12 at 14:46
  • @Maidenone, easiest way to accomplish it it `mount --bind` ur outside lib dir into chroot — at least for testing. If you need tight setup, u can copy needed libs by hands, but that's kinda tedious. – poige Aug 21 '12 at 14:49
  • @Maidenone, and you can use `LD_DEBUG=files` to track what files are missing for those libs, ur program try to load, for e. g.: `LD_DEBUG=files chroot /wher2chroot /bin/false` – poige Aug 21 '12 at 14:57
  • Thanks a lot for the help, will test this soon. Every lib i need exists in the chroot (and outside). when i run the command: `chroot /root/chrootdir/ /sbin/lighttpd -f /etc/lighttpd.conf -m /lib` it launches the webserver without any warning or error. It is when I launch the same script during startup that the script suddenly is unable to find the libs. I got a `.profile` file containing "export LD_LIBRARY_PATH=/lib" inside the chroot. my guess is that the .profile settings file is not used during startup. – Maidenone Aug 22 '12 at 06:38
  • @Maidenone, according to the `man ld.so` `/lib` should be searched by default: «In the default path /lib, and then /usr/lib. If the binary was linked with the -z nodeflib linker option, this step is skipped.» If u think the problem is with search path, then inspect `/etc/ld.so.conf` in chroot env, or populate it accordingly (`man ldconfig`) and make sure cache file is being created as well. – poige Aug 22 '12 at 14:29
0

Can you rebuild glibc with that?

./configure --prefix=/usr --enable-add-ons --libexecdir=/lib
dave
  • 303
  • 3
  • 16
  • this would have worked, but I ended up with the lazy solution. I creatied (in my chroot dir) a symlink from my /lib to /lib in the prefix path I used when I cross compiled glibc. – Maidenone Aug 22 '12 at 12:59
0

You may create init script for lighttpd and then pass during exection LD_LIBRARY_PATH at command line, so you won't care about .profile and so on. Syntax, for example

# LD_LIBRARY_PATH=/lib/:/usr/local/lib/ myCommand

You may also use 'ldd' command to check linked libraries.

adoado0
  • 101
  • 7