📜 ⬆️ ⬇️

NAS Cross Compilation

I want to tell how you can extend the functionality of NAS devices running Linux with uClibc. It is quite possible that manipulations with symlinks and environment variables will succeed where there is no uClibc.

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

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

Before you start breaking spears, visit the site dedicated to your device - it can be found in the list of NAS hacking communities . There can 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. The second is the uClibc and kernel versions.
')

Collection of sources.


Go to the manufacturer's website. There, you can most likely 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 source files of toolchain, the compilation environment for your device. In my cases, the source toolchain was not. Moreover, it is impossible to download the toolchain of the uClibc version (0.9.26) I need on the site of this wonderful environment . 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 kernel.org . 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 collect toolchain. Under Linux this will not work, under BSD you will need gmake. They say that you can compile under cygwin, I have not tried. Please note that in the Makefile you need to put down 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 the programs that will run on NAS.

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

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

Note! My NAS has i386 architecture, yours is probably different.

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. Do not forget to specify gcc from toolchain as CC. And be careful, the module must be compiled with the same gcc version as the kernel. Accordingly, a situation may arise when you need two toolchains - one with gcc for the kernel and the other with your favorite gcc version for userland.

All is ready


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

I first wanted to make a nuclear NFS server. I assembled the kernel module and nfs-utils, but I didn’t manage to launch it all. 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 give any useful information, including a warning about different versions of gcc.

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

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

Source: https://habr.com/ru/post/50937/


All Articles