openwrt启动过程

上传人:工**** 文档编号:495004258 上传时间:2023-10-29 格式:DOC 页数:7 大小:30.50KB
返回 下载 相关 举报
openwrt启动过程_第1页
第1页 / 共7页
openwrt启动过程_第2页
第2页 / 共7页
openwrt启动过程_第3页
第3页 / 共7页
openwrt启动过程_第4页
第4页 / 共7页
openwrt启动过程_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《openwrt启动过程》由会员分享,可在线阅读,更多相关《openwrt启动过程(7页珍藏版)》请在金锄头文库上搜索。

1、OpenWrt启动过程分析推荐精选总结一下OpenWrt的启动流程:1.CFE-2.linux-3./etc/preinit-4./sbin/init -5./etc/inittab -6./etc/init.d/rcS-7./etc/rc.d/S* -8.OpenWrt是一个开放的linux平台,主要用于带wifi的无线路由上。类似于Ubuntu、Red Hat、之类的linux发行版本,它也有一套自己的启动流程。下面,我就以我的Linksys 的WRT54G为平台介绍一下OpenWrt的启动流程。首先,CFE(common firmware environment)-它就是一个bootlo

2、ader,类似u-boot,redboot之类,有点broadcom公司御用之嫌-最先启动。它的任务只是创造一个简单的环境,让系统先运行起来。除了能够跳转到特定地址上启动操作系统(如Linux)外,它还能让你download东西到上面,比如download一个linux,然后启动它。另外,值得一提的是,CFE在启动之后会有1,2秒的时间等待由tftp上传的内核并烧写到flash上,这就给一些操作系统损坏但CFE还能工作的砖头板一个起死回生的机会。请注意一旦linux启动之后,将由linux全部接管系统,这时候就没CFE什么事情了。唯一的瓜葛是CFE传递给内核一个命令行的参数,这个可以在linu

3、x启动起来之后用下面的命令查看:rootOpenWrt:/# cat /proc/cmdlineconsole=ttyS0,115200 mtdparts=spi_flash:1m(u-boot)ro,3m(kernel),-(rootfs)之后,linux系统启动起来了。它使用类似如下的脚本命令来解析cmdline:for x in $(cat /proc/cmdline); docase $x ininit=*)init=$x#init=;root=*)ROOT=$x#root=case $ROOT inLABEL=*)ROOT=/dev/disk/by-label/$ROOT#LABEL

4、=;UUID=*)ROOT=/dev/disk/by-uuid/$ROOT#UUID=推荐精选;esac;rootflags=*)ROOTFLAGS=-o $x#rootflags=;cryptopts=*)cryptopts=$x#cryptopts=;nfsroot=*)NFSROOT=$x#nfsroot=;nfsopts=*)NFSOPTS=-o $x#nfsopts=;boot=*)BOOT=$x#boot=;resume=*)RESUME=$x#resume=;noresume)NORESUME=y;quiet)quiet=y;ro)readonly=y;rw)readonly=n

5、;debug)debug=yexec /tmp/initramfs.debug 2&1set -x;推荐精选break=*)break=$x#break=;break)break=premount;esacdone对于OpenWrt这个cmdline的意思就是:root=/dev/mtdblock2 文件系统在第三个flash分区上(mtdblock0,1,2);rootfstype=squashfs,jffs2 文件系统类型是squashfs和jffs2(为什么两种类型,目前还不清楚,不过可以确定OpenWrt使用了较为复杂的文件系统,实现了squashfs的压缩和jffs2的可写 );in

6、it=/etc/preinit 执行该初始化,noinitrd console=ttyS0,115200没有initrd和console口设定。init=/etc/preinit 是linux会执行的初始化,具体内容如下:rootOpenWrt:/# cat /etc/preinit#!/bin/sh# Copyright (C) 2006 OpenWrt.orgexport PATH=/bin:/sbin:/usr/bin:/usr/sbin. /etc/diag.shfailsafe_ip() ifconfig $ifname 192.168.1.1 netmask 255.255.255

7、.0 broadcast 192.168.1.2 55 upfailsafe() -n $ifname & grep $ifname /proc/net/dev /dev/null & failsafe_ipnetmsg 192.168.1.255 Entering Failsafe!telnetd -l /bin/login /dev/null 2&1lock /tmp/.failsafeash -loginmount proc /proc -t procmount sysfs /sys -t sysfs推荐精选size=$(awk /MemTotal:/ l=5242880;mt=($2*

8、1024);print(s=mt/2)l)?mt-l:s /proc/meminfo)mount tmpfs /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777if grep devfs /proc/filesystems /dev/null; thenmount devfs /dev -t devfsM0=/dev/pty/m0M1=/dev/pty/m1HOTPLUG=/sbin/hotplug-callelif -x /sbin/hotplug2 ; thenmount -t tmpfs tmpfs /dev -o size=512Kmk

9、nod /dev/console c 5 1/sbin/hotplug2 -coldplug -set-rules-file /etc/hotplug2-init.rules/sbin/hotplug2 -no-coldplug -persistent -set-rules-file /etc/hotplug2 -init.rules &M0=/dev/ptmxM1=/dev/ptmxHOTPLUG=elif -x /sbin/udevd ; thenmount -n -t tmpfs -o mode=0755 udev /dev/sbin/udevd -daemon/sbin/udevtri

10、gger/sbin/udevsettleM0=/dev/pty/ptmxM1=/dev/pty/ptmxHOTPLUG=fimkdir -p /dev/pts /dev/shmmount devpts /dev/pts -t devpts# the shell really doesnt like having stdin/out closed# thats why we use /dev/pty/m0 and m1 as replacement# for /dev/console if theres no serial console availabledd if=/dev/console

11、of=/dev/null bs=1 count=0 /dev/null 2/dev/null & M0=/dev/console推荐精选M1=/dev/consoleexec $M1 2&0echo - preinit -echo Press CTRL-C for failsafetrap FAILSAFE=true INTtrap FAILSAFE=true USR1 -e /etc/preinit.arch & . /etc/preinit.archset_state preinitecho $HOTPLUG /proc/sys/kernel/hotplugeval $FAILSAFE:+

12、failsafelock -w /tmp/.failsafeif -z $INITRAMFS ; thenmount_root -f /sysupgrade.tgz & echo - config restore -cd /mv sysupgrade.tgz /tmptar xzf /tmp/sysupgrade.tgzrm -f /tmp/sysupgrade.tgzsyncecho - init -exec /sbin/initfi可见,它主要是挂载一些系统需要的文件系统,例如tmpfs,proc和sysfs(是否真正挂载取决于内核是否2.6的)。并且会准备设备节点和故障恢复(failsa

13、fe)的准备。(这里还没看懂 )最后,exec /sbin/init启动文件系统,在OpenWrt上也就是busybox的init程序。它会自动分析/etc/inittab这个文件,其内容解释详见busybox网站的cmd help。/etc/inittab的内容:推荐精选:sysinit:/etc/init.d/rcS S boot:shutdown:/etc/init.d/rcS K stoptts/0:askfirst:/bin/ash -loginttyS0:askfirst:/bin/ash -logintty1:askfirst:/bin/ash -login运行/etc/init

14、.d/rcS:#!/bin/sh# Copyright (C) 2006 OpenWrt.orgrun_scripts() for i in /etc/rc.d/$1*; do -x $i & $i $2 2&1done | $LOGGERLOGGER=cat -x /usr/bin/logger & LOGGER=logger -s -p 6 -t sysinitif $1 = S ; thenrun_scripts $1 $2 &elserun_scripts $1 $2fi将执行/etc/rc.d/S*这些脚本:rootOpenWrt:/# ls /etc/rc.d/S*/etc/rc.d/S10boot /etc/rc.d/S50cron /etc/rc.d/S60led/etc/rc.d/S20fstab /etc/rc.d/S50dropbear /etc/rc.d/S95done/etc/rc.d/S39usb /et

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号