6

I am preparing an OS image through a combination of bootstrapping and chrooting. Some actions (e.g. building kernel modules) rely on uname output, which reports the host configuration even inside the chroot. And that configuration is different from what is being deployed. As the result kernel headers are not found and other steps get messed up.

One could get creative and replace uname with a shell script that fakes it, but what is a more practical way?

1
  • Example: cross-compiling a kernel: Parts of the build triplet (e.g. x86_64-pc-linux-gnu or arm-none-linux-gnu) may be inferred from uname. For such thing a script would probably work.
    – grochmal
    Aug 11, 2016 at 20:22

1 Answer 1

4

Linux offers a limited way to change the values reported by uname, with the personality system call which can be invoked via the setarch utility (part of the util-linux package available on every non-embedded Linux). For example you can use setarch i386 myprogram or linux32 myprogram on an amd64 machine to make a program believe that it's running on a 32-bit x86 system.

However there's no way to change the version reported by uname to an arbitrary number.

It's also possible to change the host name for a process tree, with UTS namespaces.

schroot can set those parameters according to the configuration of the chroot.

But for compiling software, changing the information reporting by uname is not sufficient. You also need to use the right compiler for the target processor, link with the right code, etc. This is known as cross-compiling, and a cross-compiling environment does not use any information about the host to decide what to build and how to build it. So forget about faking uname and instead read up on, starting with Cross compiling a kernel module, and with the kbuild documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .