How do I build an app for an old linux distribution, and avoid the FATAL: kernel too old error?
The easiest way is to simply install VirtualBox (or something similar, e.g. VMWare),Install CentOS 3 or any suitable old distro with a 2.4 kernel and build/test your app on that.
Since you're getting a "kernel too old", chances are you're relying on some features not present in 2.4 kernels so you'll have to trace down and rework that.
The error might simply be caused by linking statically to glibc, you could try linking to glibc dynamically and all your other libs statically, though to be backwards compatible you'd have to build your app on an old glibv system. Using the lsb tools to build could help too
Compiling program for old kernel
The easiest option is to always build on the older system.
Alternatively, copy the glibc headers and static libraries from the old system to the new and link against those.
If that doesn't work, you'll have to rebuild glibc with --enable-kernel=2.6.9
or something like that.
Anticipate kernel too old errors between 2.6.16 and 2.6.26 kernel versions
One way you can determine the minimum kernel version for a given ELF file is to run file
on it, like so:
$ echo 'int main(){}' > test.c
$ gcc -o test test.c
$ file test
test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.38, not stripped
The important part here is the "for GNU/Linux 2.6.38
", which indicates the minimum kernel version.
Is there any workaround for glibc (2.28) compilation for very old kernel (older than 3.2.0) using --enable-kernel=VERSION?
Is there any workaround to set kernel version to the one older than 3.2.0?
No. Support for kernels below 3.2 was dropped in glibc-2.24, and you can't bring it back (short of reverting the commits that did it).
You will need to build glibc-2.23 or older.
How to build a static binary for GNU/Linux installations with old kernel?
You need to configure glibc to target the older kernel version. Per http://www.gnu.org/software/libc/manual/html_node/Configuring-and-compiling.html glibc accepts the configure option --enable-kernel=version
where version
is in the form 2.4.20
to target older kernel versions.
You can then link your program statically with gcc -static -nodefaultlibs [...] /path/to/my/libc.a
.
Related Topics
Getting Sudo and Nohup to Work Together
Opening a .Tar.Gz File with a Single Command
How to Stop a Running R Command in Linux Other Than with Ctrl + C
How to Execute an Local Script in Remote Server with Parameters
How to Send a Sequence of at Commands to a Serial Port in Bash
How to Get Cmake to Use the Default Compiler on System Path
What Are Meanings of Fields in /Proc/Net/Dev
Ffmpeg Split Avi into Frames with Known Frame Rate
Generate Random Float Number in Given Specific Range of Numbers Using Bash
Error: Could Not Find Tiller' When Running 'Helm Version'
Concurrency of Posix Threads in Multiprocessor MAChine
How to Remove Dir Background in 'Ls -Color' Output
How to Export Database Schema in Oracle to a Dump File
Grep with Continuous Pipe Does Not Work
Linux Newbie: Linux VS Posix Manual
How to Make One Linux Kernel Module Depend on Another External Module with Depmod