8.3. Before Entering the Chroot Environment

8.3.1. Determining if steps need to be taken

Before we can enter the chroot we have to make sure that the system is in the proper state. From this point on the ${CLFS_TARGET} environment variable will no longer exist, so it will have no bearing on the rest of the book - most packages will rely on config.guess provided by Section 10.38, “Automake-1.14.1”. Packages that do not use autotools either do not care about the target triplet, or have their own means of determining its value.

In both cases, the information about the host cpu used to determine the target triplet is gathered from the same place, uname -m. Executing this command outside of the chroot as well as inside the chroot will have the exact same output.

If you're unsure if your host and target have the same target triplet, you can use this test to determine what the host's target triplet is and if you need to take any steps to ensure that you don't build for the wrong architecture. Extract the Section 10.38, “Automake-1.14.1” tarball and cd into the created directory. Then execute the following to see what the detected target triplet is by config.guess:

lib/config.guess

If the output of that command does not equal what is in ${CLFS_TARGET} then you need to read on. If it does then you can safely continue onto Section 8.4, “Entering the Chroot Environment”.

8.3.2. Using Setarch

If your host has a tool called setarch, this may solve your problems, at least if you're building for i686. On an architecture such as x86_64, using setarch linux32 uname -m will only ever output i686. It is not possible to get an output of i486 or i586.

To test if setarch does everything you need it to, execute the following command from inside the Section 10.38, “Automake-1.14.1” directory:

setarch linux32 lib/config.guess

If the output of the command above equals what is in ${CLFS_TARGET} then you have a viable solution. You can wrap the chroot command on the next page with setarch linux32. It will look like the following:

setarch linux32 chroot "${CLFS}" /tools/bin/env -i \
    HOME=/root TERM="${TERM}" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h

If setarch works for you then you can safely continue onto Section 8.4, “Entering the Chroot Environment”. If not, there is one more option covered in this book.

8.3.3. Using a Uname Hack

The Uname Hack is a kernel module that modifies the output of uname -m by directly changing the value of the detected machine type. The kernel module will save the original value and restore it when the module is unloaded.

Uname Hack (20080713) - 4 KB:

Download: http://cross-lfs.org/files/extras/uname_hack-20080713.tar.bz2

MD5 sum: dd7694f28ccc6e6bfb326b1790adb5e9

Extract the tarball and cd into the created directory. To build the Uname Hack you must have the kernel sources for your currently running kernel available. Build the Uname Hack with the following or similar command:

make uname_hack_fake_machine=mips

The meaning of the make and install options:

uname_hack_fake_machine=mips

This parameter sets the value that the uts machine type will be changed to.

In the top level directory of the Uname Hack package you should see a file named uname_hack.ko. As soon as that module is loaded into the running kernel the output of uname -m will be affected immediately system-wide. Load the kernel module with the following command:

insmod uname_hack.ko

To test if the Uname Hack is working properly, execute the following command from inside the Section 10.38, “Automake-1.14.1” directory:

lib/config.guess

The output of the above command should be the same as the ${CLFS_TARGET} environment variable. If this is not the case, you can try and get help on the CLFS Support Mailing List or the IRC Channel. See Section 1.7, “Help” for more information.