Cross Compilation for NAS

    I want to tell you how you can expand the functionality of NAS devices running Linux with uClibc. It is possible that manipulating symlinks and environment variables will succeed where uClibc is not.

    I will not consider ways to get the root shell. There are too many mechanisms, it all depends on the specific model. The site dedicated to hacking NASs discusses various methods for obtaining root shell and provides links to sites of hacking communities of specific models.

    The purpose of this article is to show how easy it is to add missing functionality to the NAS and point out some pitfalls.

    Before you start breaking spears, visit the site dedicated to your device - it can be found in the list of communities for hacking NAS. There may be not only important information, but also ready-made binaries, useful tips, etc. First of all, we are interested in how to get the root shell. In the second - versions of uClibc and the kernel.

    Source collection.

    We go to the manufacturer’s website. There, with a high probability, you can download a file like GPL_sources.tgz in which there will be a kernel with a config for your NAS. If you are even more lucky, there will be sources of toolchain, compilation environment for your device. In my case, there were no toolchain sources. Moreover, on the site of this wonderful environment it is impossible to download the toolchain of the version of uClibc I need (0.9.26). However, there is a note where there is not only the source address, but also the necessary patches. If there was no kernel on the manufacturer’s website, you can always download it from . We also need module-init-tools or modutils if the kernel is version 2.6 or 2.4, respectively.

    Preparing the environment.

    First you need to build a toolchain. Under Linux, this will not be difficult; under BSD, gmake is needed. They say that you can compile under cygwin, I have not tried it. Please note that in the Makefile you need to put ARCH: = XXX, where XXX is the architecture of your NAS and LINUX_SOURCE: = kernel-headers-K.KK.KK.tar.bz2, where K.KK.KK is the kernel version.

    Now you can compile programs that will run on the NAS.

    To do this, firstly, add the path to the toolchain binaries to PATH, for example,
    $ export PATH=$PATH:~/uclibc-toolchain-src-20040609/gcc-3.3.x/toolchain_i386/bin

    Secondly, when you run ./configure, you need to add the key --host = XXX-linux, where XXX is the architecture of your NAS, for example,
    $ ./configure --host=i386-linux

    Please note! My NAS has an i386 architecture, yours most likely has a different one.

    If you want to add kernel modules (for example, a file system driver or an NFS server), you need to compile module-init-tools or modutils and the kernel itself. Remember to specify gcc from the toolchain as CC. Moreover, be careful, the module must be compiled with the same gcc version as the kernel. Accordingly, a situation may arise when you need two toolchain - one with gcc for the kernel and the other with your favorite version of gcc for userland.

    All is ready

    Now you can compile the programs you need and run them on the NAS. No additional manipulations are required.

    First of all, I wanted to make a nuclear NFS server. I put together a kernel module and nfs-utils, but I couldn’t start all of this. After much fruitless research, I realized: I compiled the module with the wrong version of gcc. This was told to me by insmod from modutils. Before that, I used insmod, which provides busybox. The worst thing, I must say. It does not provide any useful information, including a warning about different versions of gcc.

    Therefore, I highly recommend using modutils. When I compiled the module correctly everything worked!

    The game is worth the candle: on my NAS, the loser-space sama gives 5 MB / s, the loser-space nfs gives 4.5 MB / s, and the nuclear nfs 7 MB / s. I suspect that the load is not 100%.

    Also popular now: