Making embedded Linux file system with busybox

  
 

Abstract Busybox is a must-have for building embedded Linux file systems. This article takes the latest version 1.00 of busybox as an example to introduce the configuration and installation of this software, as well as the preparation of other script files necessary to build the file system.

Keywords busybox Embedded Linux file system Startup script

1busybox Introduction People who are familiar with embedded Linux will not be familiar with busybox. It is very much called "Swiss Army Knife" in embedded Linux systems because it combines many common UNIX commands and tools into a single executable. Although compared to the corresponding GNU tools, busybox provides slightly less functionality and parameters, but in smaller systems (such as boot disks) or embedded systems, it is sufficient. The busybox is designed with a special working environment limited by hardware resources. It uses a clever way to reduce its size: all commands are grouped into an executable file by means of "plug-ins", which are determined by different symbolic links in the actual application process. . For example, the final generated executable file is busybox. When a symbolic link ls is created for it, the function of the column directory can be implemented by executing this new command. Using a single executable file to maximize the sharing of program code, even the file header, memory control block and other operating system
resources are shared, for systems with tight resources, it is really The most suitable. In the compilation process of busybox, it is very convenient to add or subtract its "plug-in", the last symbolic link can also be automatically generated by the compiler system. Here's a step by step to build a brand new Linux file system from scratch with busybox. 2 Compiling busybox In mid-October 2004, the stable version of busybox 1.00 was finally released. The complete source code can be downloaded from http://www.busybox.net, and the compressed package size is about 1.3 MB. After unzipping the source code, go to the busybox1.00 directory and run make menuconfig to open its build interface. This interface is somewhat similar to the Linux kernel compilation, as shown in Figure 1. In addition to the choice of commands that are ultimately compiled into the executable, there are many other settings that are important in this menu interface. The following three directories are of interest to many people: Build Options --->Installation Options --->Login/Password Management Utilities --->In Build Options, there is an option to use cross-compilation (Do you Want to build BusyBox with a Cross Compiler). If you want to compile other platforms, you should select it and set the corresponding compiler prefix. In the Installation Options you can set the installation path, which is set to the root directory of the new file system. Of course, you can also use the default _install directory, and then copy it to the new file system after installation. When setting up Login/Password Management Utilities, in order to avoid the trouble of configuring glibc, it is best to use the use of password and group functions rather than system functions. The commands provided by busybox are undoubtedly comprehensive, but its default configuration does not constitute a fully functional file system. The commands that must be added are getty, login, and passwd in the Login/Password Management Utilities, which were previously provided by another package, tinylogin. Of course, these commands can also be removed if you do not need an interactive login interface. By setting the kernel parameter init=/bin/sh, you can get a shell directly after the system starts to compile the configuration interface of 1busybox. The tlenetd command is a remote login service program. Compiling it into the busybox will provide a lot of convenience for future debugging. Of course, the embedded device can also be managed through the serial terminal, but the way of network login is more convenient. After setting, save, exit, execute make; make install command, busybox will create /usr, /bin, /sbin and other directories in the future root file system. You can see the symbolic link between the compiled busybox executable and other application commands. The typical busybox file size is about 300 KB in the case of dynamic linking, and about 800 KB in static linking. The file system implemented by it can be controlled to less than 1 MB. But so far, what is not a complete usable file system, we must add some necessary files on this basis to make it work. 3 improve the file system 3.1 need to increase the file reference to a normal Linux system will find that the file system created by busybox is still missing a lot of files. The following three lines of commands establish some of the directories included in common UNIX systems. Although they are not all required, it is more standard to build them. These commands are executed in the root directory of the new file system, and the execution of the third command must also have root privileges. Mkdir mnt root var tmp proc boot etc libmkdir /var/{lock,log,mail,run,spool}chown 0:0R *If busybox is compiled with dynamic linking, you also need the dynamic library required by busybox: libcrypt. So.1, libc.so.6, ldlinux.so.2 are placed in the lib directory. It is best to create the appropriate files and links in a standard way. See the following list: -rwxrwxrwx 192519ld-2.3.2.solrwxrwxrwx 111ld-linux.so.2 -> ld-2.3.2.so-rwxrwxrwx 1 1190032libc- 2.3.2.solrwxrwxrwx 113libc.so.6 -> libc-2.3.2.so-rwxr-xr-x 118348libcrypt-2.3.2.solrwxrwxrwx 117libcrypt.so.1 -> libcrypt-2.3.2.so3.2 Writing files in the etc folder The etc folder is where many system configuration files are saved. These files are very important and can affect system startup if they are misconfigured. The file in the busybox source code example/bootfloopy/etc directory is a simple example, and the files can be copied as a basis. (Some scripts and documentation in the example /bootfloopy directory are also worth reading.) First, the inittab file is the first script file accessed after the system is started, and subsequent files are specified by it. The format of this file is different from that of ordinary computer Linux inittab. The specific meaning can refer to the busybox documentation. Here's a simple example: ::sysinit:/etc/init.d/rcStty0::respawn:/sbin/getty 38400 tty0tty2::askfirst:/bin/sh::ctrlaltdel:/sbin/reboot::shutdown: /bin/umount ar::shutdown:/bin/mount /o remount, where the first line specifies the system startup script as /etc/init.d/rcS; the second line specifies that the first virtual terminal opens Login session; the third line specifies that a third virtual terminal opens a shell without login authentication; the fourth line specifies the execution command when the ctrl+alt+del key combination is pressed; the last two lines specify the execution when the shutdown is performed. operating. The fstab file defines the various "mount points" of the file system that need to be matched with the actual system. A simple fstab file is as follows: proc/procprocdefaults00/dev/hda1/ext2rw, noauto01devpts/dev/ptsdevptsdefaults00 The third line is for UNIX PTYs, and telnetd is used.

Copyright © Windows knowledge All Rights Reserved