Init analysis of BusyBox

Source: Internet
Author: User
Tags delete key syslog domain name server ssh nameserver
init analysis of BusyBox

This article turns from: http://blog.csdn.net/linucos/article/details/5352506

Init of 5.5.3 BusyBox

In addition to the basic commands, BusyBox also supports the Init feature, like other init, BusyBox Init is the completion of the system initialization, the work before shutdown, and so on, we know that after the Linux kernel is loaded, the machine will transfer control to the kernel, After Linux kernel starts, do some work, then find the Init program inside the root file system, and execute it, the BusyBox init process will do the following: (reference << build embedded Linux system >> p201)

1. Set up a signal processing procedure for Init

2. Initialize the console

3. Profiling/etc/inittab Documents

4. Execute system initialization command line, use/etc/init.d/rcs by default

5. Perform all inittab commands that cause Init to suspend (action type: Wait)

6. Perform all Inittab only (action type: once)

Once this is done, the init process loops through the following processes:

1. Perform all Inittab commands that must be restarted at termination (action type: once)

2. Inittab command (action type: Askfirst) that must be restarted but must be queried before starting all terminations

After the console is initialized, BusyBox checks to see if the/etc/inittab file exists, and if the file does not exist, BusyBox uses the default Inittab configuration, which is primarily for system reboot, System suspend, and Init reboot to set the default action. It also sets the action to start the shell for four virtual consoles (tty1 to Tty4). If these device files are not established, BusyBox will complain.

The format of each line in the Inittab file is as follows: (there is a detailed Inittab file example under the example folder under BusyBox's root directory)

Id:runlevel:action:process

Although this format is similar to the traditional sytem V init, IDs have different meanings in busybox init. For BusyBox, the ID is used to specify the control of the start process TTY. If you start a process that is not an interactive shell, such as BusyBox sh (ASH), you should have a control TTY, and if the control TTY does not exist, BusyBox SH will complain. BusyBox will completely ignore the RunLevel field, so just leave it on, and you might ask if it's useless to keep it, I think it's probably for the same format as the traditional sytem V init. The process field is used to specify the path of the program being executed, including command-line options. The action field is used to specify one of the 8 actions that can be applied to a process in the following table.

Action

Results

Sysinit

Provides the path to initialize the command line for Init

Respawn

Restarts whenever the corresponding process terminates execution

Askfirst

Similar to respawn, but its main purpose is to reduce the number of terminal applications executed on the system. It will cause Init to display the "please press Enter to active this console" message on the console and wait for the user to press ENTER before restarting

Wait

Tells Init that it must wait until the appropriate process completes before continuing

Once

Only execute the appropriate process once, and will not wait for it to complete

Ctratldel

Executes the corresponding process when the Ctrl+alt+delete key is pressed

Shutdown

When the system shuts down, perform the appropriate process

Restart

When Init restarts, the corresponding process is executed, and the process usually executed here is the Init itself

Here's my usblinux inittab file.

:: Sysinit:/etc/init.d/rcs

:: Respawn:/sbin/getty 38400 tty1

Tty2::askfirst:-/bin/sh

Tty3::askfirst:-/bin/sh

:: Restart:/sbin/init

:: Ctrlaltdel:/bin/umount-a-R

This inittab performs the following actions

1. Set the/ETC/INIT.D/RCS as a system initialization file

2. Start a login session on the virtual terminal tty1 of 38400 bps (note getty usage)

3. The shell that initiates the Askfirst action on the virtual terminal tty2 and Tty3

4. If init restarts, set/sbin/init to the program it will execute

5. Tell Init to perform the umount command to uninstall all file systems when the system shuts down, and to flush the new installation with read-only mode when the uninstall fails to protect the file system.

5.6 Configuration files for the system

5.6.1. /etc/init.d/rcs file

The configuration file is generally placed in the/etc/directory, 5.5.3 says the init initialization command line file is/etc/init.d/rcs, and here's my RcS file

#!/bin/sh

/bin/mount-n-T Proc/proc/proc

/bin/mount-n-O REMOUNT,RW/

/bin/mount-av

/bin/hostname Usblinux

/etc/init.d/rc.nic

/etc/init.d/rc.network

/etc/init.d/rc.usb

/etc/init.d/rc.local

1. Install proc file system, but do not write/etc/mtab file (mtab file is a file read by DF command)

2. Mount the root file system in read-write mode (requires/etc/fstab file)

3. Mount-av mount all file systems listed in/etc/fstab

4. Host name is named Usblinux

5. Execute rc.nic (Automatically detect network card), Rc.network (Configure network), RC.USB (load USB module), rc.local (perform some local services)

5.6.2. /etc/fstab

When the Mount command was used, the Fstab file was already involved, and the following is my fstab file

/DEV/RAM0/EXT2 Defaults 0 0

PROC/PROC proc Defaults 0 0

The syntax for fstab configuration files can be man fstab

In fact, there is no need to add the RCS inside the Mount-av.

5.6.3. /etc/mtab

The contents of this file are dynamically changing, and when you mount a file system, if the mount does not add the-n parameter, the installation information is written to the mTAB file, and the DF command reads the file.

5.6.4. /etc/profile

This file is used for SH, when the user obtains a shell, SH will configure the user's landing environment according to this file, below is my profile file.

Path=/bin:/sbin:/usr/bin:/usr/sbin

ps1= ' [/u@/h/w]/$ '

Hostname= '/bin/hostname '

Export PATH HOSTNAME PS1

Alias L.= ' ls-d. [A-za-z]*--color=tty '

Alias rm= ' Rm-i '

Alias cp= ' Cp-i '

Alias mv= ' Mv-i '

Export Path=/usr/local/bin: $PATH

Export Path=/usr/local/sbin: $PATH

Where the PATH environment variable specifies that sh looks for the path to this command when the user types a command.

PS1 specify the format of the SH prompt

The other export commands, the alias command, needless to say, ash and bash inside the busybox are very similar, so it's no problem to be familiar with bash.

5.6.5. /etc/ld.so.conf and/etc/ld.so.cache

These two files are related to Lib libraries, and they are used to specify the path where the application looks for the Lib library.

The contents of my ld.so.conf file are as follows.

/lib

/usr/lib

/usr/local/lib

The content inside the Ld.so.cache is generated by the Ldconfig command, Ldconfig generates Ld.so.cache contents according to the ld.so.conf configuration file. The application reads the Ld.so.cache file, so if the ld.so.conf file is changed, it needs to be run once Ldconfig can be the new one, and if the Lib library file is added, the ldconfig is required.

5.6.6/etc/passwd,/etc/shadow,/etc/group

The group contains information about the user groups.

The contents of my group file are as follows:

Root:x:0:root

FTP:X:50:

passwd contains information about the user.

The contents of my passwd file are as follows:

Root:x:0:0:root:/root:/bin/sh

Ftp:x:14:50:ftp User:/var/ftp:/sbin/nologin

Sshd:x:74:74:piviledge-separated Ssh:/var/empty/sshd:/sbin/nologin

Note that each row within the group and passwd is not redundant.

Shadow file is the password file used for Pam authentication

5.6.7./etc/services

Standard service port mapping tables used by network applications

My services file is as follows:

Tcpmux 1/tcp

Tcpmux 1/UDP

Ftp-data 20/tcp

FTP 21/tcp

SSH 22/tcp

SSH 22/udp

Telnet 23/tcp

NameServer 42/tcp Name

Syslog 514/UDP

Auth 113/TCP authentication Tap ident

Because I need to open the SSHD,SYSLOGD service and use the Ftp,ssh,telnet application. So it adds the above, but note that not all Web applications are dependent on services files, such as Telnet, but perhaps telnetd needed.

5.6.8./etc/nsswitch.conf

The function of this file is very big, without it many programs can not run normally, regarding its concrete function or use man nsswitch.conf to see.

The contents of my nsswitch.conf file are as follows:

Passwd:files

Shadow:files

Group:files

Hosts:files DNS

Ethers:files

Netmasks:files

Networks:files

Protocols:files

Services:files

Netgroup:files

Publickey:files

Automount:files

Aliases:files

Note hosts this line must add DNS, otherwise even if there are resolv.conf files, domain name can not be resolved, note that nsswitch.conf is corresponding to a group of Lib library, where we used the files,dns, so we need to copy the corresponding Lib library to/lib directory.

#cd/mnt/rootfs

#cp-dpr/lib/libnss_files*./lib

#cp-dpr/lib/libnss_dns*./lib

5.6.9. /etc/hosts,/etc/host.conf,/etc/resolv.conf

The contents of my Hosts file are as follows, needless to say, it should be clear what the meaning is, not clear man hosts

127.0.0.1 localhost:localdomain localhost

Host.conf and resolv.conf is the domain name resolution when used in the configuration file, where resolv.conf is the IP address of the domain name server, host.conf inside put is the search rules of the host. What you don't know is man host.conf and man resolv.conf.

The contents of my host.conf and resolv.conf files are as follows:

#cat/mnt/rootfs/etc/host.conf

Order Hosts,bind

#cat/mnt/rootfs/etc/resolv.conf

NameServer 202.112.20.131

5.6.10./etc/syslog.conf

SYSLOGD the configuration file read by the service program.

The contents of my file are as follows:

# Log all kernel messages to the console.

# Logging Much else clutters up the screen.

#kern. */dev/console



# Log anything (except mail) of level info or higher.

# Don ' t log private authentication messages!

*.info;mail.none;authpriv.none;cron.none/var/log/messages



# The Authpriv file has restricted access.

authpriv.*/var/log/secure



# Save Boot messages also to Boot.log

local7.*/var/log/boot.log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.