Home > Article > System Tutorial > Teach you step by step how to build linux rootfs
As we all know, in the Linux environment, everything is a file, and files can represent everything. The file system is a collection of these common components. In the embedded field, rootfs built based on busybox is often used to build file systems.
busybox has been around for nearly 20 years and has now become the mainstream rootfs building tool in the embedded industry.
The code of busybox is completely open source. You can enter the official website and click "Download Source" under "Get BusyBox" to enter the source code download interface.
“
Official website link:
https://busybox.net/”
After downloading the source code, copy the source code to the compilation environment. Busybox needs to be configured before compilation, which mainly involves three aspects:
\1. Compilation tool chain settings
\2. Compile mode setting
\3. Functions supported by the file system
The first two items must be completed, while the third point is formulated according to the user's own needs.
Execute make menuconfig to enter the configuration interface.
Compilation tool chain settings
The set cross-compilation tool chain must be the same as the tool chain used when compiling the kernel. For example, if the cross-compilation tool chain is set to arm-linux-gnueabi-, then enter the build options to set it.
Of course, you can also enter the Makefile file in the root directory to modify the corresponding cross-compilation tool chain and platform information.
Compile mode setting
Set whether the compiled image file is static or dynamic. If it is dynamically compiled, you need to manually copy the lib library under the cross-compilation tool chain to the final _install folder, and vice versa. The configuration of static compilation is as follows. You can see that the prompt in brackets does not include shared libraries. If this option is not enabled, the compilation method will be dynamic.
**Set functions supported by rootfs
**
busybox can support hundreds of command lines and other functions, which can be increased or decreased according to your own needs. For example, if you add a devmem command line, check the corresponding enable box.
Compile
After executing make and make install, the _install folder will be generated in the compilation path, which contains bin, sbin, usr and other files. Check the devmem command just added and find that it has been compiled.
At this time, copy the _install compiled under busybox as the basic framework of rootfs, and then add other necessary components.
Copy out all the files under _install and create the lib and etc folders, and then copy the lib library under the cross-compilation tool chain arm-linux-gnueabi to the created lib folder.
Then create home, opt, run, sys, var, boot, dev, media, proc, tmp, usr
Configure etc directory
Before creating the rcS file, you need to manually create the init.d folder in the etc directory, and create rcS in the init.d folder.
At this point, execute the following command to package and generate a lightweight rootfs.
tar -jcvf rootfs.tar.bz2 *
Use mfgtools to download the compressed rootfs.tar.bz2 to mmc, start the system again, you can see that the created root file system can work normally, and the devmem command we added before can also be executed normally.
The above is the detailed content of Teach you step by step how to build linux rootfs. For more information, please follow other related articles on the PHP Chinese website!