Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Append > /log/lighttpd.log 2>&1 to the end of second line, then try again to see what happens. –  quanta Aug 21 '12 at 9: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

2 Answers 2

up vote 0 down vote accepted

Can you rebuild glibc with that?

./configure --prefix=/usr --enable-add-ons --libexecdir=/lib
share|improve this answer
    
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

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
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.