Monday, March 7, 2011

Running programs without a chroot

Para versión en español


Warning: This information may not work for you. If while following this instructions, your machine explodes or does not work as it should, is your only responsibility. You should first tested it in a test system and not in a production system. I hope you have a backup. It is not my fault (^_^).

Some time ago, I had to run an 32-bits program in a 64-bits system. Usually you would use a chroot. But this 32-bits program must be ran by another program, this other program does not have root privileges (you should not be root without reason, be safe kid (^_^) ). This impedes the use of chroot (you need root privileges to run chroot), plus I did not want to wrestle with library conflicts (it can be bad for health).

After some googling and man, I found the about ld.so. I only had to set the libraries to use for the program. First set environmental variable LD_LIBRARY_PATH with the libraries path. Sometimes you only need to do this. It did not work for me (;_;) . I got a lot of errors like symbol problems, etc. So I kept reading about ld.so and found a solution. The system was using its loader, not exactly what I needed. The choice besides recompiling, was to call the specific loader. To know which loader to use, first check with: ldd <absolute program path> . Search the line ld-linux, grep is your friend, then you get  ld-linux<something>.so (symbolic link to ld-<version>.so) your program uses.

An example

In a 64-bits system with a 32-bits program

With the folder structure






Running
$ ldd /home/<user>/<program_folder>/bin/<program> | grep ld-linux


You get (this file needs to be copied from the original system to the system where you plan to run the program)
/lib/ld-linux.so.2


Copy this loader to
/home/<user>/<program_folder>/lib/ld-linux.so.2

To run the program
$ env LD_LIBRARY_PATH=/home/<user>/<program_folder>/lib/:$LD_LIBRARY_PATH \
/home/<user>/<program_folder>/lib/ld-linux.so.2 \
/home/<user>/<program_folder>/bin/<program> <arguments>*


A little messy, but you can make a script. You may ask if you have any question


Alejandro