查看小米路由系统启动过程的源代码
←
小米路由系统启动过程
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== /init 启动脚本 == <source lang=bash> #!/bin/sh # Copyright (C) 2006-2012 OpenWrt.org # # klogger(){ local msg="$@" test -z "$msg" && return 1 echo "$msg" >> /dev/kmsg 2>/dev/null } usb_check_for_rescure(){ local gpiobtn gpiobtn=`cat /proc/xiaoqiang/reset` rst=`gpio $gpiobtn | awk '{print $3}'` if [ "$rst" = "<0>" ]; then nvram set flag_reboot_system=2 exec /sbin/init fi } getmtdblockdevbyname(){ local name name="$1" test -z "$name" && return 1 devnum=$(cat /proc/mtd | awk "/\"$name\"/"| awk -F':' '{print $1}' | awk -F'mtd' '{print $2}') test -z "$devnum" && return 1 if [ -e "/dev/mtdblock${devnum}" ] then echo "/dev/mtdblock${devnum}" return 0 else return 1 fi } reboot() { nvram set flag_reboot_system=1 exec /sbin/init } updone() { nvram set flag_package_update=0 nvram set telnet_en=1 nvram commit klogger "Update successfully!!! Reboot the System..." reboot } upnet() { #not vlan support in bootloader and ramfs, using trunk mode #set to "0 1 2 5u" for ramfs network only, do not commit rmmod et 2>/dev/null nvram set vlan1ports="0 2 5u" nvram set vlan2ports="4 5" mac=`nvram get et0macaddr` if [ "$mac" = "00:90:4C:0F:F2:a7" ]; then uuid=`cat /proc/sys/kernel/random/uuid` b1=`echo $uuid | cut -b 1-2` b2=`echo $uuid | cut -b 3-4` b3=`echo $uuid | cut -b 5-6` mac=`echo 00:90:4C:$b1:$b2:$b3` nvram set "pci/1/1/macaddr=$mac" uuid=`cat /proc/sys/kernel/random/uuid` b1=`echo $uuid | cut -b 1-2` b2=`echo $uuid | cut -b 3-4` b3=`echo $uuid | cut -b 5-6` mac=`echo 00:90:4C:$b1:$b2:$b3` nvram set "pci/2/1/macaddr=$mac" uuid=`cat /proc/sys/kernel/random/uuid` b1=`echo $uuid | cut -b 1-2` b2=`echo $uuid | cut -b 3-4` b3=`echo $uuid | cut -b 5-6` mac=`echo 00:90:4C:$b1:$b2:$b3` nvram set "et0macaddr=$mac" fi insmod /lib/modules/et.ko lip=`nvram get flag_local_ip` if [ "$lip" = "auto" ]; then /sbin/udhcpc -t 10 -n if [ $? -eq 1 ]; then lip="192.168.31.1" ifconfig eth0 $lip up fi else [ -n "$lip" ] || lip="192.168.31.1" ifconfig eth0 $lip up fi echo 1 > /proc/sys/net/ipv6/conf/eth0/forwarding ifconfig lo up nvram set vlan1ports="0 2 5*" nvram set vlan2ports="4 5" } uperror() { klogger "SQUASHFS Filesystem Error!!!" klogger "Switch to RAMFS..." upnet exec /sbin/init } squashfs() { klogger "Switch to SQUASHFS..." reboot rescuerootdev=$(getmtdblockdevbyname squashfs) if [ -n "$rescuerootdev" ] then mount -t squashfs $rescuerootdev /mnt if [ $? -ne 0 ] then klogger "ERROR: mount -t squashfs $rescuerootdev /mnt failed." else # boot_status: 1 sata mode # 2 flash mode echo 2 > /sys/power/boot_status upmount if [ -x /mnt/etc/rescueinit ] then klogger "switch to rescue system($rescuerootdev) by /etc/rescueinit ..." exec switch_root /mnt /etc/rescueinit fi if [ -x /mnt/lib/preinit.sh ] then klogger "switch to rescue system($rescuerootdev) by /lib/preinit.sh ..." exec switch_root /mnt /lib/preinit.sh fi umount -f $rescuerootdev fi fi uperror } upmount() { mount -n -o move /tmp /mnt/tmp mount -n -o move /sys /mnt/sys mount -n -o move /proc /mnt/proc mount -n -o move /dev /mnt/dev } [ -d /dev ] || mkdir -m 0755 /dev [ -d /mnt ] || mkdir -m 0700 /mnt [ -d /sys ] || mkdir /sys [ -d /proc ] || mkdir /proc [ -d /tmp ] || mkdir /tmp mkdir -p /var/lock mount -t sysfs -o nodev,noexec,nosuid none /sys mount -t proc -o nodev,noexec,nosuid none /proc klogger "Loading, please wait..." # Note that this only becomes /dev on the real filesystem if udev's scripts # are used; which they will be, but it's worth pointing out if ! mount -t devtmpfs -o mode=0755 none /dev; then mount -t tmpfs -o mode=0755 none /dev mknod -m 0600 /dev/console c 5 1 mknod /dev/null c 1 3 fi mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /tmp klogger "Loading essential drivers..." flag_usb_rootdisk_enable="$(nvram get flag_usb_rootdisk_enable)" for i in `cat /lib/modules/mod.lst`; do [ "$i" = "usb-storage.ko" -a "$flag_usb_rootdisk_enable" != 'true' ] && continue if [ "$i" != "et.ko" ] ; then insmod /lib/modules/$i || nvram set flag_package_update=5 fi done # Check for USB rescure klogger "Check for USB rescure..." usb_check_for_rescure model=`nvram get model` if [ -z "$model" ]; then model=`cat /proc/xiaoqiang/model` fi if [ "$model" = "R1AC" ]; then insmod /lib/modules/usb-storage.ko 2>/dev/null sleep 3 fi #support tftpboot from network if [ "$(nvram get flag_tftp_bootup)" = 'on' -a "$(nvram get flag_tftp_booted)" = 'true' ] then . /tftpboot.init tftpboot_mount_rootfs fi klogger "Press Ctrl+C to enter RAMFS..." rd -w 1 && nvram set flag_package_update=5 if [ ! -b /dev/sda ]; then klogger "Warning: No Hard Disk" nvram set flag_no_hdd=1 nvram commit squashfs fi update=`nvram get flag_package_update` ft_mode=`cat /sys/power/ft_mode` if [ -n "$update" -a "$update" != "0" ]; then # klogger "Prepare the system to update..." upnet if [ $update = "5" ]; then exec /sbin/init else /usr/sbin/autofd if [ $? -eq 1 ]; then gpio 2 1 gpio 3 1 gpio 1 0 if [ "$ft_mode" = "1" ]; then exec /sbin/init else while true do /usr/sbin/update retcode=$? [ $retcode -eq 2 ] && exec /sbin/init [ $retcode -eq 0 ] && updone done fi else updone fi fi else klogger "Bringup the system..." flag_try_sys1=`nvram get flag_try_sys1_failed` flag_try_sys2=`nvram get flag_try_sys2_failed` if [ "$flag_try_sys1" != "1" ] || [ "$flag_try_sys2" != "1" ]; then # default: rootfs1 flag=`nvram get flag_boot_rootfs` if [ "$flag" = "1" ]; then mntdev=/dev/sda2 else mntdev=/dev/sda1 fi [ -b $mntdev ] && mount -o ro $mntdev /mnt # flag_boot_type: 1 system in SATA version # 2 system in SQUASH version # 9 system in tftp version nvram set flag_boot_type=1 if [ -x /mnt/lib/preinit.sh ]; then # boot_status: 1 sata mode # 2 flash mode upmount exec switch_root /mnt /lib/preinit.sh else if [ "$ft_mode" = "1" ]; then # skip failed flag setting in FT mode reboot else if [ "$flag" = "1" ]; then nvram set flag_try_sys2_failed=1 else nvram set flag_try_sys1_failed=1 fi nvram set flag_ota_reboot=0 nvram commit reboot fi fi fi # reset all failed flag in FT mode if [ "$ft_mode" = "1" ]; then nvram set flag_try_sys1_failed=0 nvram set flag_try_sys2_failed=0 nvram commit reboot fi squashfs fi </source> 可以看到正常流程下,/dev/sda1 是作为根文件系统,/dev/sda2 作为一个备份的根文件系统。从 "Bringup the system..." 开始,其流程为: 先将 /dev/sda1 挂载到 ramfs 的 /mnt 目录下,然后 switch_root (类 chroot) 到 /mnt 下,同时执行 /mnt/lib/preinit.sh <br><br>
返回到
小米路由系统启动过程
。
个人工具
3.149.29.112
该IP地址的讨论
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面