Skip to main content

Running new programs on old linuxes with incompatible glibc. Or putting lipstick on a pig

 I'm back trying to run new programs on ancient linuxes, but this time I'm not going through the recompiling hassles I described here: https://adrianpopagh.blogspot.com/2021/06/installing-borg-backup-on-old-fedora.html

Since I'm getting an error while compiling python3 as described above:

# make
gcc -pthread -Wl,-rpath /usr/local/lib    -Xlinker -export-dynamic -o python Programs/python.o -L. -lpython3.9 -lcrypt -lpthread -ldl  -lutil -lrt -lm   -lm
Programs/python.o(.text+0x1): In function `main':
./Programs/python.c:15: undefined reference to `Py_BytesMain'
collect2: ld returned 1 exit status
make: *** [python] Error 1


... I'm trying to move the compiled code directly on this RHEL4 machine. Without success, sadly:

# /opt/python3/bin/python3
/opt/python3/bin/python3: /lib64/tls/libc.so.6: version `GLIBC_2.7' not found (required by /opt/python3/lib/libpython3.9.so.1.0)
/opt/python3/bin/python3: /lib64/tls/libc.so.6: version `GLIBC_2.6' not found (required by /opt/python3/lib/libpython3.9.so.1.0)
/opt/python3/bin/python3: /lib64/tls/libc.so.6: version `GLIBC_2.4' not found (required by /opt/python3/lib/libpython3.9.so.1.0)


RHEL4's glibc version is 2.3.

In my steps I needed 3 systems:

- the donor (FC8) from which I took /lib and the /opt/python3 directories. This is the original system where I could run python3 on.

- the target (RHEL4). This is the system I want to run python3 on

- the development system (Ubuntu20.04). This is where I'm doing my compiling and patching

So, the plan is to take /lib from the donor to the target and place it in a different directory (/glibc). Then, relink python3 to use the new glibc, so that we don't break existing programs.

1. Copy over /lib:

donor# scp -r /lib/* root@target:/glibc/

2. Compile patchelf (https://github.com/NixOS/patchelf/releases/tag/0.12), so we can change the hardcoded interpreter in the python3 binary. Because of build requirements, this step should be done on a newer linux system, not on the target:

ubuntu# git clone https://github.com/NixOS/patchelf

ubuntu# cd patchelf

ubuntu# ./bootstrap.sh

ubuntu# ./configure

ubuntu# make

ubuntu# make check

ubuntu# make install

3. Copy over the python3 to be patched to the development system

ubuntu# rsync -avht donor:/opt/python3 .

4. Look for binary executables

ubuntu# find python3 -type f -exec file '{}' \; 2>&1 | grep "LSB executable"
python3/bin/python3.9: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.9, BuildID[sha1]=d544c6c7ec7a57aecd5a184ad5cfeb20d3706fae, with debug_info, not stripped

5. For each executable, change the path to the loader from /lib64/ld-linux-x86-64.so.2 to /glibc/ld-linux.so.2, and also change the path to the default libraries

ubuntu# patchelf --set-interpreter /glibc/ld-linux.so.2 --set-rpath /glibc/ python3/bin/python3.9

6. Copy back the patched files to the target:

ubuntu# rsync -avht python3 target:/opt/
7. Profit?

target# LD_LIBRARY_PATH=/glibc:/opt/python3/lib:/lib:/usr/lib:/usr/local/lib /opt/python3/bin/python3
-bash: /opt/python3/bin/python3: Accessing a corrupted shared library


# To be continued...

 

Comments

Popular posts from this blog

Home Assistant + Android TV = fun

Here's a quick setup guide for controlling your Android TV from within Home Assistant. I've used it to control a genuine Android TV (Philips 7304) and an Odroid N2 running Android TV. For this to work you need ADB access. It can usually be enabled from within Developer Settings. The great part is - you don't need root access! The most important things are described in the androidtv component for Home Assistant: https://www.home-assistant.io/integrations/androidtv/ Make sure you go through the adb setup. My configuration is simple (inside configuration.yaml): media_player:   - platform: androidtv     name: TV Bedroom ATV     host: 192.168.1.61     device_class: androidtv Once Home Assistant restarts, your TV might require you to accept the connection (adb authentication). This happens only once (or until you reset your ATV to factory settings). Once running the integration will show you the current ATV state (on or off) and allows you to turn it on or off.

SmokePing + InfluxDB export + docker + slaves + Grafana = fun

I've been working for a while on this project - with the purpose of getting SmokePing measurements from different hosts (slaves) into InfluxDB so that we can better graph them with Grafana. The slaves run multiple Smokeping instances inside Docker so that they have separate networking (measure through different uplinks, independently). This will not be a comprehensive configuration guide, but a quick "how to" to handle setup and basic troubleshooting. It assumes you already know how to set up and operate a regular Smokeping install with or without slaves and that you are fluent in Smokeping configuration syntax, know your way around Docker and aren't a stranger from InfluxDB and Grafana (sorry, there's a lot of information to take in). 1. Getting Smokeping with InfluxDB support - you can get it either from the official page (most changes have been merged) - https://github.com/oetiker/SmokePing (PR discussion here: https://github.com/oetiker/SmokePing/issues/

Installing Home Assistant Supervised on an old 32bit HP laptop

 I've received a challenge from my former boss: an old HP laptop that was born in 2005:  an HP-Compaq NC6220 ( https://www.pocket-lint.com/laptops/reviews/hp/68181-hp-compaq-nc6220-notebook-laptop/ ). The specs are abysmal: So, i386, 1.7GHz single-core CPU (remember those?), 1G of DDR2 RAM (2x512M) and a 40GB ATA (not SATA!) drive. But hey, at least it has a serial port!  The challenge is to install HomeAssistant ( https://www.home-assistant.io/ ) on it so that he can monitor some Zigbee temperature sensors and relays (via a gateway). The first hurdle was to remove the BIOS password - following this nice guide: https://www.youtube.com/watch?v=ZaGKyb0ntSg Next-up - install HASSOS. Unfortunately, it doesn't support i386, but only x86_64... So, I went the Home Assistant Supervised route, and installed Debian 11 i386 edition from a netinstall USB ( https://cdimage.debian.org/debian-cd/current/i386/iso-cd/debian-11.6.0-i386-netinst.iso ).   Once Debian was up and running (didn't