首页 > 其他分享 >Buildroot(2022.08-rc1)+busybox(1.35.0)启动流程

Buildroot(2022.08-rc1)+busybox(1.35.0)启动流程

时间:2023-04-27 19:46:55浏览次数:51  
标签:bin Buildroot run busybox etc stop rc1 dev start

 关键词:busybox,inittab,syslogd,klogd,mdev,modprobe,watchdog,telnetd等等。

 

busybox启动流程简单解析:从init到shell login》详细介绍了init对inittab的解析和执行。

下面为buildroot(2022.08-rc1)的启动脚本:

/etc/inittab
    sysinit
        ->/bin/mount -t proc proc /proc
        ->/bin/mount -o remount,rw /
        ->/bin/mkdir -p /dev/pts /dev/shm
        ->/bin/mount -a
        ->/bin/mkdir -p /run/lock/subsys
        ->/sbin/swapon -a
        ->/bin/ln -sf /proc/self/fd /dev/fd
        ->/bin/ln -sf /proc/self/fd/0 /dev/stdin
        ->/bin/ln -sf /proc/self/fd/1 /dev/stdout
        ->/bin/ln -sf /proc/self/fd/2 /dev/stderr
        ->/bin/hostname -F /etc/hostname
        ->/etc/init.d/rcS
            ->S01syslogd
            ->S02klogd
            ->S10mdev
            ->S15watchdog
            ->S50telnet
    respawn
        ->/sbin/getty -L console 0 vt100
    shutdown
        ->/etc/init.d/rcK
        ->/sbin/swapoff -a
        ->/bin/umount -a -r

start-stop-daemon

start-stop-daemon启动或停止守护进程。

Usage: start-stop-daemon [OPTIONS] [-S|-K] ... [-- ARGS...]

Search for matching processes, and then
-K: stop all matching processes
-S: start a process unless a matching process is found

Process matching:
    -u USERNAME|UID    Match only this user's processes
    -n NAME        Match processes with NAME
            in comm field in /proc/PID/stat
    -x EXECUTABLE    Match processes with this command
            in /proc/PID/cmdline
    -p FILE        Match a process with PID from FILE
    All specified conditions must match
-S only:
    -x EXECUTABLE    Program to run
    -a NAME        Zeroth argument
    -b        Background
    -N N        Change nice level
    -c USER[:[GRP]]    Change user/group
    -m        Write PID to pidfile specified by -p
-K only:
    -s SIG        Signal to send
    -t        Match only, exit with 0 if found
Other:
    -o        Exit with status 0 if nothing is done
    -v        Verbose
    -q        Quiet

S01syslogd

S01syslogd启动syslogd服务,执行"syslogd -n"。将pid写入文件中,后面可以通过start-stop-daemon关闭。

syslog用来记录应用程序或者硬件设备的日志;通过syslogd这个进程记录系统有关事件记录,也可以记录应用程序运作事件。

syslogd日志记录器由两个守护进程(klogd,syslogd)和一个配置文件(syslog.conf)组成。

详细参见《Busybox的syslogd认识与使用》。

#!/bin/sh

DAEMON="syslogd"
PIDFILE="/var/run/$DAEMON.pid"

SYSLOGD_ARGS=""

# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"

# BusyBox' syslogd does not create a pidfile, so pass "-n" in the command line
# and use "-m" to instruct start-stop-daemon to create one.

start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/sbin/$DAEMON"-- -n $SYSLOGD_ARGS

start-stop-daemon -K -q -p "$PIDFILE"

S02klogd

klogd首先接收内核的日志,然后将之发送给syslogd。

#!/bin/sh

DAEMON="klogd"
PIDFILE="/var/run/$DAEMON.pid"

KLOGD_ARGS=""

# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/sbin/$DAEMON" -- -n $KLOGD_ARGS start-stop-daemon -K -q -p "$PIDFILE"

S02sysctl

#!/bin/sh
#
# This script is used by busybox and procps-ng.
#
# With procps-ng, the "--system" option of sysctl also enables "--ignore", so
# errors are not reported via syslog. Use the run_logger function to mimic the
# --system behavior, still reporting errors via syslog. Users not interested
# on error reports can add "-e" to SYSCTL_ARGS.
#
# busybox does not have a "--system" option neither reports errors via syslog,
# so the scripting provides a consistent behavior between the implementations.
# Testing the busybox sysctl exit code is fruitless, as at the moment, since
# its exit status is zero even if errors happen. Hopefully this will be fixed
# in a future busybox version.

PROGRAM="sysctl"

SYSCTL_ARGS=""

# shellcheck source=/dev/null
[ -r "/etc/default/$PROGRAM" ] && . "/etc/default/$PROGRAM"

# Files are read from directories in the SYSCTL_SOURCES list, in the given
# order. A file may be used more than once, since there can be multiple
# symlinks to it. No attempt is made to prevent this.
SYSCTL_SOURCES="/etc/sysctl.d/ /usr/local/lib/sysctl.d/ /usr/lib/sysctl.d/ /lib/sysctl.d/ /etc/sysctl.conf"

# If the logger utility is available all messages are sent to syslog, except
# for the final status. The file redirections do the following:
#
# - stdout is redirected to syslog with facility.level "kern.info"
# - stderr is redirected to syslog with facility.level "kern.err"
# - file dscriptor 4 is used to pass the result to the "start" function.
#
run_logger() {
    # shellcheck disable=SC2086 # we need the word splitting
    find $SYSCTL_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \
    xargs -0 -r -n 1 readlink -f | {
        prog_status="OK"
        while :; do
            read -r file || {
                echo "$prog_status" >&4
                break
            }
            echo "* Applying $file ..."
            /sbin/sysctl -p "$file" $SYSCTL_ARGS || prog_status="FAIL"
        done 2>&1 >&3 | /usr/bin/logger -t sysctl -p kern.err
    } 3>&1 | /usr/bin/logger -t sysctl -p kern.info
}

# If logger is not available all messages are sent to stdout/stderr.
run_std() {
    # shellcheck disable=SC2086 # we need the word splitting
    find $SYSCTL_SOURCES -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \
    xargs -0 -r -n 1 readlink -f | {
        prog_status="OK"
        while :; do
            read -r file || {
                echo "$prog_status" >&4
                break
            }
            echo "* Applying $file ..."
            /sbin/sysctl -p "$file" $SYSCTL_ARGS || prog_status="FAIL"
        done
    }
}

if [ -x /usr/bin/logger ]; then
    run_program="run_logger"
else
    run_program="run_std"
fi

start() {
    printf '%s %s: ' "$1" "$PROGRAM"
    status=$("$run_program" 4>&1)
    echo "$status"
    if [ "$status" = "OK" ]; then
        return 0
    fi
    return 1
}

case "$1" in
    start)
        start "Running";;
    restart|reload)
        start "Rerunning";;
    stop)
        :;;
    *)
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
esac

S10mdev

mdev配置文件为/etc/mdev.conf,遍历/sys/dev下面的block和char文件夹,创建/dev目录下设备节点。

DAEMON="mdev"
PIDFILE="/var/run/$DAEMON.pid"
start-stop-daemon -S -b -m -p $PIDFILE -x /sbin/mdev -- -df
start-stop-daemon -K -p $PIDFILE

 mdev详细参考《Linux uevent分析、用户接收uevent以及mdev分析》。

 modprobe将搜索到的module插入内核。

# coldplug modules
find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | xargs -0 modprobe -abq

S15watchdog

启动watchdog设备,PERIOD为超时重启时间。。

watchdog -t PERIOD /dev/watchdog

S50telnet

#!/bin/sh
#
# Start telnet....
#

TELNETD_ARGS=-F
[ -r /etc/default/telnet ] && . /etc/default/telnet

start-stop-daemon -S -q -m -b -p /var/run/telnetd.pid -x /usr/sbin/telnetd -- $TELNETD_ARGS
start-stop-daemon -K -q -p /var/run/telnetd.pid -x /usr/sbin/telnetd

标签:bin,Buildroot,run,busybox,etc,stop,rc1,dev,start
From: https://www.cnblogs.com/arnoldlu/p/17360029.html

相关文章

  • 铠侠 RC10 固态硬盘寿命暴力写入测试:1100pe 毫发无损
    一直很好奇固态硬盘的寿命有多久,从来也没有用坏过。怀着强烈的好奇心,开始了这一马拉松测试。直接对固态做暴力写入,一直到写坏为止看看到底写入量多少。从五月份到现在,断断续续写入。现在已经写入1100tb,还没有任何坏的迹象(保修是肯定没有了)。目前缓外写入400-500m/s,与新盘差不多没有......
  • Buildroot使用记录
     关键词:rootfs、BR2_EXTERNAL等等。 记录buildroot使用各种方法,以及解决的问题。1定制文件系统方法1.1根文件系统覆盖(BR2_ROOTFS_OVERLAY)将BR2_ROOTFS_OVERLAY指向的目录覆盖到output/target根文件系统。还可以通过都好间隔,指定多个目录。配置方式:Systemconfigurati......
  • [ARC138D] Differ by K bits 题解
    小清新构造题。首先\(K=1\)的情况是trival的,直接格雷码即可。对于\(K>1\),我们发现题目的约束相当于\(\operatorname{popcount}(P_i\oplusP_{(i+1)\bmod2^N})=K\),考虑\(P_i\)的差分序列\(D_i\),那么\(D_i\)一定是一个恰好有\(K\)位\(1\)的二进制数,记\(S=\{i\mid......
  • ARC159F Good Division【性质,DP,线段树】
    定义一个序列是好的当且仅当其可以通过每次删去一对相邻的不同的数把序列删空。给定一个长度为\(2n\)的序列\(a\),求有多少种划分方式使得每一段都是好的。答案对\(998244353\)取模。\(n\leq5\times10^5\),时限\(\text{5.0s}\)。先考虑什么样的数列是合法的,显然必要条......
  • ARC159解题报告
    比赛传送门A.CopyandPasteGraph题意:给定一个\(n\timesn\)的邻接矩阵,将其复制\(k^2\)遍(行和列各\(k\)个),得到一个\(nk\)个点的有向图。有\(q\)次询问,每次询问\(s\tot\)的最短路长度(或不可达)。\(n,q\le100,k\le10^9\)。考察一个点\(x\)在新图上能到达哪......
  • [ARC127E] Priority Queue 题解
    首先我们每次加入的数必定是一个\(1\sima\)的排列,但从排列角度考虑的话非常复杂,因为\(s\)是一个集合。所以我们考虑最后能剩下哪些数。考虑最后剩下的集合为\(\{a_i\}\),其中\(a_i<a_{i+1}\),显然这个集合里面的元素个数为\(A-B\)。那么我们会发现一件事情:我们按上升序依......
  • arc159b
    题目链接:https://atcoder.jp/contests/arc159/submissions/40436772苦思冥想搞好几个小时终于给我过了哈哈哈哈。(虽然比赛的时候没调出来。。)思路:\(当A,B的gcd>1时,递归搜索。当等于1时,先求出d=A-B,然后枚举d的约数,找一个最小的余数,可以使得gcd(A-x,B-x)>1。特......
  • ARC130D ZigZag Tree 题解
    题目链接考虑这棵树在满足条件下是什么样子的?我们发现如果对于一棵树黑白染色,白色表示周围的点大于自身,黑色的点反之,是满足条件的。同时,将黑白点反色也是满足条件的。我们考虑进行\(\text{dp}\),设\(dp_{i,j,0/1}\)表示以点\(i\)为根的子树,\(i\)点权值的排名是\(j\),且......
  • 内核实验(二):自定义一个迷你Linux ARM系统,基于Kernel v5.15.102, Busybox,Qemu
    原文:https://blog.csdn.net/yyzsyx/article/details/129576582文章目录一、篇头二、内核部分2.1源码下载2.1.1官网2.1.2镜像站点2.1.3代码下载2.2编译2.2.1设置工具链2.2.2配置2.2.3make2.2.4编译成功三、busybox部分3.1源码下载3.2编译3.2.1配置3.2.3编译3.2.4查......
  • EasyARM i.MX283A 完整系统制作指南(Linux 4.13.2+U-Boot 2017.09+BusyBox 1.27.2+Qt5
    原文:https://www.taterli.com/3213/标题老长呢.反正什么都是新的,所有都是开源的,除了下载工具以外,所有源码都有(据说下载工具也有,我懒得找了.),编译器源码自己也能做,但是没必要了.代码下载地址:https://github.com/nickfox-taterli/imx283a-new/releases/tag/v0.1首先有一个U......