Home > System Tutorial > LINUX > Teach you step by step how to build linux rootfs

Teach you step by step how to build linux rootfs

王林
Release: 2024-02-05 15:51:16
forward
663 people have browsed it

busybox overview

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/

手把手教你构建linux rootfs

2. Configuration and compilation of busybox

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.

手把手教你构建linux rootfs

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. 手把手教你构建linux rootfs

Of course, you can also enter the Makefile file in the root directory to modify the corresponding cross-compilation tool chain and platform information. 手把手教你构建linux rootfs

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. 手把手教你构建linux rootfs

**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.

手把手教你构建linux rootfs手把手教你构建linux rootfs

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. 手把手教你构建linux rootfs

At this time, copy the _install compiled under busybox as the basic framework of rootfs, and then add other necessary components.

3. Build rootfs

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.

手把手教你构建linux rootfs

Then create home, opt, run, sys, var, boot, dev, media, proc, tmp, usr

手把手教你构建linux rootfs

Configure etc directory

  • Create fstab file
手把手教你构建linux rootfs
  • Create inittab file
手把手教你构建linux rootfs
  • Create rcS file

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.

手把手教你构建linux rootfs

At this point, execute the following command to package and generate a lightweight rootfs.

tar -jcvf rootfs.tar.bz2 *
Copy after login
手把手教你构建linux rootfs

4. File system verification

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.

手把手教你构建linux rootfs

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!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template