0

A busybox system comes with a rpm command on glibc-2.24. How can programs from Fedora Core (FC) and/or later versions get run on this system?

I've figured out FC25 comes with the same glibc version. If I download FC25 rpm packages and install them, sometimes they'll just run. Some others will fail. I'd like to run FC30 or other versions, too.

The problem comes with FC packages overwrite existing libraries in the same directory. I've figured out to run a bash, you only need to install bash, glibc, glibc-common, ncurses-base, ncurses-libs, libgcc. Bash would run after installing these packages. Since these are a small number of libries, installing them with FC versions should bring in minor differences that does not affect bash. But the minor difference might affect other programs, or installing more packages may bring in more differences thus to impact more programs.

How this can be solved?

I've read about linux namespaces. Thus one path to start with is to create a namespace thus to isolate the host filesystems. I tried this to create a namespace filesystem:

cd /root
mkdir root-fc30
cd root-fc30
mkdir dev proc tmp var
cp -a /bin /sbin /lib /usr ./
mount -o bind /proc proc
mount -o bind /dev dev
mkdir root-old

Then get into the namespace:

unshare -m --propagation slave
pivot_root . root-old

After this point, the new packages can be installed. But still it will overwrite existing libraries. How further steps can be taken to solve this in the isolated namespace?

What other cleaner solutions exist?

minghua
  • 5,981
  • 6
  • 45
  • 71
  • 1
    Just use `docker`. Or other container technology. They exists just to solve this problem. – KamilCuk Jan 27 '20 at 18:08
  • How to install the docker host package on a busybox system? Or can you point to any other container technology that is easy to start with on a busybox system? – minghua Jan 28 '20 at 00:38
  • I am sorry sir, don't really get it, what is a "busybox system"? You compiled all your programs yourself? Do you have any startup manager? Pivot_root changes current process root dir. Before `docker` days, ppl used `chroot` - you had the whole distribution installed/copied into a directory. Then you `for i in sys proc dev; do mount -o bind /$i /dir_with_fedora/$i; done` mounted needed filesystems and just `chroot /dir_with_fedora` to run the shell. Docker just automates that (and much more). I think you may want to just read up about `chroot` then. – KamilCuk Jan 28 '20 at 01:40
  • You are on the right track. I'm thinking about the same thing, but I'd like to figure out how to load a base fedora to the system first. To load a base fedora, I need to run programs for a different glibc and other lib version. A [busybox](https://busybox.net/), is a very simple sh/coreutils/etc for embedded, using sysv init to bring the system up, usually on a very limited hardware resource. – minghua Jan 28 '20 at 01:48
  • You just search for `fedora chroot download` and find one ; ) Or search for something like `fedora chroot installation`. [Looks like](https://nmilosev.svbtle.com/quick-and-easy-fedora-minimal-chroot) you can download and unpack docker images even – KamilCuk Jan 28 '20 at 02:37
  • Thanks for looking it up and sharing the link. I saw that back a few days ago. The image is the same as I later found on the docker hub official fedora link. But I did not realize it can be used. Yes, it shall be one of the solutions I'm going to give a try. Would you put your comments into an answer? – minghua Jan 28 '20 at 02:44

1 Answers1

1

The easier answer is to use the matching ld-linux.so to run the corresponding application and point PATH and LD_LIBRARY_PATH accordingly. The ld-linux.so usually points to a solid dynamic loader .so file.


As an example, continue to use the namespace in my question above to illustrate how this will work:

When being seen in the namespace, we will keep the binaries for the old system at /opt directory, and install everything new for a FC30 system to the normal root.

Change the above copy command cp -a /bin /sbin /lib /usr ./ into:

mkdir opt
cp -a /bin /sbin /lib /usr ./opt/

Inside the namespace, all the old version binaries are still available by prepending the modified PATH and LD_LIBRARY_PATH, and ld-*.so.

The first step is to start a shell using the old version in the namespace:

LD_LIBRARY_PATH=/opt/lib:/opt/usr/lib PATH=/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin \
/opt/lib/ld-2.24.so /opt/bin/sh

In this usable shell, install packages for bash to run for the FC25 version:

/opt/lib/ld-2.24.so /opt/bin/rpm -i bash-4.3.43-4.fc25.armv7hl.rpm
/opt/lib/ld-2.24.so /opt/bin/rpm -i file-5.28-4.fc25.armv7hl.rpm
/opt/lib/ld-2.24.so /opt/bin/rpm -i file-libs-5.28-4.fc25.armv7hl.rpm
/opt/lib/ld-2.24.so /opt/bin/rpm -i glibc-2.24-10.fc25.armv7hl.rpm
/opt/lib/ld-2.24.so /opt/bin/rpm -i glibc-common-2.24-10.fc25.armv7hl.rpm
/opt/lib/ld-2.24.so /opt/bin/rpm -i ncurses-base-6.0-6.20160709.fc25.noarch.rpm
/opt/lib/ld-2.24.so /opt/bin/rpm -i ncurses-libs-6.0-6.20160709.fc25.armv7hl.rpm
/opt/lib/ld-2.24.so /opt/bin/rpm -i libgcc-6.4.1-1.fc25.armv7hl.rpm

After these packages are installed the FC25 version of bash can be used normally after the following command:

LD_LIBRARY_PATH=/lib:/usr/lib PATH=/bin:/sbin:/usr/bin:/usr/sbin /usr/bin/bash

The procedure to install FC30 binaries and other packages are the same. Once enough tools packages have been installed, the FC version tools can be used to install more packages. The old version under /opt in namespace can be removed.

minghua
  • 5,981
  • 6
  • 45
  • 71
  • Chroot is a bit easier with a command which should be `chroot /opt /lib/ld-2.24.so /bin/sh`. – minghua Feb 29 '20 at 22:20
  • Later I figured the same can be [achieved using a docker image](https://unix.stackexchange.com/questions/219253/the-most-minimal-debian-sid-installed-with-debootstrap). That will be bigger in size, but you'll not need the rpm command to start with. – minghua Jul 24 '20 at 16:17