A script that overrides the kernel release string output by uname
command inside a container.
When compiling libs/apps, which refer kernel header in their source code, the configure script first invokes uname -r
command to obtain kernel release string, and uses that string to generate path to kernel header.
However, when compiling inside a container (like docker or singularity), the output of uname -r
changes with host's kernel version because uname -r
gets kernel release string from uname()
system call and containers share the same kernel with their host.
If host kernel is updated but the kernel header inside containers is not updated at the same time, compiling these libs/apps gets errors due to kernel header not found.
Hence, we need to find a way to cheat the configure script.
- Create a folder in your home and copy the
uname
script of this project to the folder. It is suggested not to use a folder that is already in your command search path. For example,
$ mkdir ~/.local/fakeuname
$ cp uname ~/.local/fakeuname/uname
- Set the
FAKE_KERNEL_RELEASE
macro in theuname
script to the version of kernel header installed in the container. For example,
# vim ~/.local/fakeuname/uname
$ FAKE_KERNEL_RELEASE="4.15.0-112-generic"
- Include the fakeuname folder in your
PATH
env when running a container. Here is an example for bash,
# vim ~/.bashrc
if test -f "/.dockerenv" || [[ ! -z "${SINGULARITY_NAME+x}" ]]; then
export PATH=${HOME}/.local/fakeuname:${PATH}
fi
- Mount
.bashrc
andfakeuname
folder when running containers.
- For Docker
$ docker run -v ${HOME}/.bashrc:/root/.bashrc:ro -v ${HOME}/.local/fakeuname/uname:/root/.local/fakeuname/uname --rm -it DOCKER_IMAGE
- For Singularity
$ SINGULARITY_SHELL=/bin/bash singularity shell SINGULARITY_IMAGE