Article Title: proficient in building initramfs stepbystep (4 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
11. automatically generate Device Files under/dev
In the previous section, when we used the chroot method to test busybox, we used the "bind" method to map the device files in/dev of the host to the dev directory under the image directory for simplicity. On init ramfs, this method is obviously unavailable.
The device files generated by the system are usually generated dynamically using udev, while the init ramfs is required to generate dynamically for general purposes. There is an mdev command in busybox, which is used to dynamically generate device files and fill them in the/dev directory.
When the system is started
Mdev-s
The command can automatically generate the corresponding device file in the/dev directory according to the sysfs File System of the kernel. Before executing the command, you must first mount the proc and sysfs Virtual File Systems of the kernel.
12. Initial skill
After solving the problem of Automatic Generation of device files, we can try to make a simple and runable linux system:
(1) write the simplest init script in the image directory.
#! /Bin/sh
Mount-t proc/proc
Mount-t sysfs/sys
Mdev-s
/Bin/sh
(2) set the executable permission for the init script, otherwise the kernel will not execute it.
Chmod + x init
(3) In some busybox configurations, the mdev Command needs to read the/etc/mdev. conf file. To avoid errors, we create an empty file. The mdev. conf file is used to control the read and write permissions of the device files generated by mdev. Here we do not need to set special permissions for the device files, so we can use the default 660 permission settings of mdev. For more information about control over mdevs' file permissions, see the mdev.txt file in the docsdirectory of the busyboxsource code tree.
Touch etc/mdev. conf
(4) Run
Make
Command to recompile the kernel and generate a new init ramfs.
Okay. Start the new kernel in the QEMU simulation environment. After the system is initialized, it will enter the SHELL environment. In this SHELL environment, test some common commands to see if they can run normally.
Thirteen, can't access tty
When the simple linux system created in the previous step enters the SHELL environment, the following error message is displayed:
/Bin/sh: can't access tty; job controll off
Although it does not affect the use, it is not perfect.
The cause of this error is that our SHELL runs directly on the kernel console, and the console cannot provide the terminal function, therefore, you must run the SHELL on the tty device to eliminate this error. The solution is to use the regular init mechanism to open the tty device before executing the SHELL.
In addition, the reboot, halt, and other commands of this simple system do not work and must be resolved through init.
[1] [2] [3] Next page