Chrooting Python in OpenBSD 4.5

Published: October 01, 2009
Tags: openbsd python sysadmin chroot

Just a quick technical entry today, on the off chance that this helps somebody, somewhere.

For reason's I'll go into another time, I've recently been trying to chroot a Python installation into the directory /srv/www on an OpenBSD 4.5 machine. I took the standard approach to this, which is to examine the output of ldd /usr/local/bin/python2.5:

/usr/local/bin/python2.5:
    Start    End      Type Open Ref GrpRef Name
    1c000000 3c004000 exe  1    0   0      /usr/local/bin/python2.5
    05432000 2547c000 rlib 0    1   0      /usr/local/lib/libpython2.5.so.1.0
    05dc3000 25dc7000 rlib 0    1   0      /usr/lib/libutil.so.11.0
    0df1e000 2df44000 rlib 0    1   0      /usr/lib/libstdc++.so.47.0
    0d543000 2d54d000 rlib 0    1   0      /usr/lib/libm.so.5.0
    02a7c000 22a85000 rlib 0    1   0      /usr/lib/libpthread.so.11.1
    06a56000 26a8f000 rlib 0    1   0      /usr/lib/libc.so.50.1
    08db8000 08db8000 rtld 0    1   0      /usr/libexec/ld.so

and copy each of these files over to the corresponding location in the chroot directory (i.e. stuff from /usr/lib/ goes in /srv/www/usr/lib). But after doing this, testing the setup with chroot /srv/www python2.5 yielded the error: /usr/bin/local/python2.5: can't load library 'libpython2.5.so.1.0'.

I went near mad trying to figure out why this wasn't working. The libpython file was clearly in the correct location. A PHP installation that I had chrooted into the very same place using the very same procedure worked flawlessly. There seemed to be no scope for rational explanation of why this wasn't working.

In the end, I managed to solve this problem by copying the file /var/run/ld.so.hints into the corresponding location in the chroot directory. Everything worked perfectly after that. I don't profess to have any idea why you need to do this (I discovered that it worked after much trial and error, based on random permutations of stuff found on the web), but you do. Hopefully this post saves some other poor hacker from wasting a few frustrated hours.

I note that the ld.so.hints file exists in the same location on recent NetBSD releases, so I assume this advice ports over to NetBSD as well. However, there is no such file in my install of Arch Linux, so things are probably different in Linux land. Linux distros do seem to have a file /etc/ld.so.conf which serves a similar purposes - it was actually reading about this that gave me the idea to look for something similar in my situation.

Feeds
Archives
Top tags