2. Make the smallest root file system

In the last blog , I explained that making a root file system is actually creating directories in partitions and the files necessary to start the system in each directory. Busybox is usually used to make root file systems in embedded systems. Because busybox gathers a lot of commands and various files, it is very convenient to help developers realize some necessary files. The download address of busybox .

Hundreds of commands are integrated in busybox, and they do not need to be used in general systems, so you can select these commands by configuring busybox, specify the functions of certain commands, specify the connection method of busybox, and specify the installation path of busybox.

① Configure busybox, enter the configuration interface by executing the “make menuconfig” command in the top-level directory of busybox.

busybox setting----->

        busybox liarary tuning --->

                [*] tab completion / * Set up TAB key completion * /

archival utilities -----> Various compression and decompression tools.

Linux module utilities ----> Use loadable modules.

Linux system utilities ----> Support mdev, this can easily construct / dev directory, and can support hot-plug devices.

② Compile and install busybox. After the above configuration, execute make ARCH = ARM CROSS_COMPILE = arm-linux- (without gcc suffix) to compile and install in the specified directory. If you do not specify the installation path during configuration, you need to execute make ARCH = arm CROSS_COMPILE = arm-linux- CONFIG_PREFIX = dir (specify the directory). After the compilation is successful, all the files except the bin / busybox will be symbolically connected to the bin / busybox in the specified directory .

③ Use the glibc library to build the root file system, and there is a glibc library in the cross-compilation tool chain. The location of the glibc library in the cross-compilation tool chain is: * / libc / usr / lib, and the files stored in it can be divided into: ① Loaders, such as ld-2.3.6.so, ld-linux.so.2, Before starting dynamic programs, they are used to load dynamic libraries . ② Target files (.o), such as ctrl.o, are connected like normal target files when generating applications. ③ Static library files (.a), which will be linked when compiling static programs. ④Dynamic library files (.so, .so. [0-9] *), these files will be used when compiling dynamic programs . ⑤ libtool library files (.la), these files will be used when linking library files, these files are not needed when the program is running. ⑥ Inside gconv is a dynamic library with character set ⑦ ldscripts directory, which stores various connection scripts and is used when compiling applications.

Only the loader and dynamic library are needed on the development board, so when building the lib library, you only need to copy the dynamic library file and loader. The dynamic library selects the library file according to the application's dependence on the library. You can use the arm-linux-readelf -a "your binary" | grep "Shared" command to query the dependent library files or use the ldd.host program name to find the dependent library files.

Busybox will generate / bin, / sbin, / usr / bin /, / usr / sbin directory files, plus the above transplanted / lib library files, basically most of the minimum root file system file directories and files have been built. There are still configuration files, device files, and other directory files.

④ Build the etc directory (the main files are inittab, init.d / rcS, fstab), and the init process creates other subprocesses based on the / etc / inittab file.

inittab can imitate the example / inittab file in busybox. The init.d / rcS file is a script file in which you can add automatically executed commands, such as configuring the IP address and mounting the file system specified by / ect / fstab (mount -a). The fstab file format is as follows:

#device             mount-point          type              options                 dump             fsck order

proc                   /proc                        proc                defaults                 0                      0 

tmpfs                 /tmp                         tmpfs               defaults                 0                      0

  • type: File system type, such as proc, jffs2, yaffs, ext2, nfs can also be auto, indicating that the file system type is automatically detected.
  • dump: dump is a program used to back up files. The dump program determines whether the file system needs to be backed up according to the value of the dump field. 0 means ignore this file system.
  • The fsck program determines the disk check order based on the fsck order field. 0 means ignore this file system.

⑤ Construct the dev directory, you can use the most primitive method to deal with the device, statically create various nodes in the / dev directory. You can also use mdev to create device files. Mdev is a simplified version of udev, which creates device files by reading kernel information . There are two main uses of mdev: initializing the / dev directory and dynamically updating. Support hot swap. To use mdev, the kernel needs to support the sysfs file system. In order to reduce the reading and writing of flash, the tmpfs file system must also be supported. First make sure that the kernel has set CONFIG_SYSFS, CONFIG_TMPFS configuration options.

  • mount -t tmpfs mdev / dev #Use the memory file system to reduce the reading and writing of flash
  • mount -t sysfs sysfs / sys #mdev obtains device information through the sysfs file system
  • echo / bin / mdev> / proc / sys / kernel / hotplug #Set the kernel, call / bin / mdev when a device is plugged
  • mdev -s #Generate the nodes of all devices supported by the kernel in the / dev directory

To automatically run mdev when the kernel starts, you need to modify etc / fstab to automatically mount the file system:

  • ++ sysfs / sys sysfs defaults 0 0 #Automatically mount sysfs
  • ++ tmpfs / dev tmpfs defaults 0 0 #Automatically mount tmpfs

You also need to modify init.d / rcS to add the auto-run command:

  • ++ mount -a #Mount the file system specified in the fstab file
  • ++ echo / sbin / mdev> / proc / sys / kernel / hotplug #support hot plug
  • ++ mdev -s                                                                                    

⑥ Create the directories you need such as mnt root home tmp sys proc, etc.

note: mdev is started by the init process. Before using mdev to construct / dev, the init process must at least use the device files / dev / console and / dev / null, so these two device files need to be created manually.

After the root file system is made, it needs to be made into a file, that is, an image file, before it can be burned to the storage device.

Published 35 original articles · Like1 · Visits 1870

Guess you like

Origin blog.csdn.net/lzj_linux188/article/details/102795851