上次分析了busybox的启动脚本,这次分析一下init.d中一些脚本的内容。

参考链接

http://www.cnblogs.com/helloworldtoyou/p/6169678.html

http://m.blog.chinaunix.net/uid-20678569-id-1574823.html

https://www.ibm.com/developerworks/cn/linux/l-cn-udev/

http://blog.csdn.net/future_fighter/article/details/3862795

mount-proc-sys

#!/bin/sh

# Copyright 2006-2007 Freescale Semiconductor, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. if [ "$1" = "start" -o "$1" = "restart" ]
then
echo "Mounting /proc and /sys
# -t指定文件系统类型, -n不把安装记录在/etc/mtab文件中"
mount -n -t proc proc /proc # 挂载 proc
mount -n -t sysfs sys /sys # 挂载 sysfs
fi

udev

#!/bin/sh
PATH=$PATH:/sbin:/bin if [ ! -x /sbin/udevd ]
then
exit 0
fi case "$1" in # start
start)
echo "" > /proc/sys/kernel/hotplug mount -n -o mode=0755 -t tmpfs tmpfs /dev # 挂载tmpfs到/dev # Create static device nodes in /dev
mknod /dev/console c 5 1 # 创建/dev/console节点
mknod /dev/null c 1 3 # 创建/dev/null节点 echo "Starting the hotplug events dispatcher udevd"
udevd --daemon # 启动udev,监听内核的uevent,自动创建或删除/dev中的文件 echo "Synthesizing initial hotplug events"
udevtrigger # 扫描sysfs文件系统,生成相应的硬件设备hotplug事件
udevsettle --timeout=300 # 查看udev事件队列,等队列内事件全部处理完毕才退出。 mkdir /dev/pts
mount -n -t devpts devpts /dev/pts # 挂载 devpts mkdir /dev/shm
;;
stop) # stop
;;
reload)
udevcontrol --reload_rules
;;
*)
echo "Usage: /etc/rc.d/init.d/udev {start|stop|reload}"
echo
exit 1
;;
esac exit 0

hostname

#!/bin/sh

if [ "$1" = "start" ]
then
if [ -x /bin/hostname -o -x /usr/bin/hostname ]
then
echo Setting the hostname to $HOSTNAME
hostname $HOSTNAME # 设置主机名
fi
fi

depmod

#!/bin/sh

if [ ! -x /sbin/depmod ]
then
exit 0
fi if [ "$1" = "start" -a ! -s /lib/modules/`uname -r`/modules.dep ] # 判断modules.dep内容是否为空
then
echo Running depmod
/sbin/depmod -a # 使用depmod创建modules.dep文件
# depmod读取/lib/modules/`uname -r`中的所有模块一来关系,并记录到modules.dep文件中。
fi

modules

#!/bin/sh

if [ "$1" = "start" -a -x /sbin/modprobe -a "$MODLIST" ]
then
for i in $MODLIST
do
echo Loading module $i
modprobe $i # 根据MODLIST中的列表安装模块
done
fi

filesystems

#!/bin/sh

if [ "$1" = "stop" ]
then
echo Unmounting filesystems
umount -a -r # -a: All of the file systems described in /etc/mtab are unmounted.
# -r: In case unmounting fails, try to remount read-only.
mount -o remount -r %root% / # 重新挂载分区
[ -x /sbin/swapoff ] && swapoff -a # 关闭配置文件/etc/fstab中所有系统交换分区
fi if [ "$1" = "start" ]
then
echo Mounting filesystems
if [ "$TMPFS" = "tmpfs" ]
then
mount -n -t $TMPFS shm /dev/shm
fi
if [ -n "$TMPFS" ]
then
mount -n -t $TMPFS rwfs /mnt/rwfs -o size=$TMPFS_SIZE
fi
if [ "$READONLY_FS" != "y" ]
then
mount -n -o remount -w %root% /
NFSBOOT="`cat /proc/cmdline | grep -q /dev/nfs ; echo $?`"
if [ "$NFSBOOT" == "0" -a -n "$RAMDIRS" ]
then
echo "Booted NFS, not relocating: $RAMDIRS"
RAMDIRS=""
fi
else
# initramfs, ramdisks, others? come up read/write by default
mount -n -o remount -r %root% /
RAMDIRS="$RAMDIRS /tmp /etc /var"
fi
if [ -n "$RAMDIRS" ]
then
for i in $RAMDIRS
do
if [ ! -e /mnt/rwfs/$i ]
then
cp -a $i /mnt/rwfs/
mount -n -o bind /mnt/rwfs/$i $i
fi
done
fi
if [ -e /etc/mtab ]
then
rm -f /etc/mtab
fi
ln -s /proc/mounts /etc/mtab # 创建/proc/mounts软连接 /etc/mtab
if [ ! -d /dev/pts ]
then
mkdir /dev/pts # 创建/dev/pts
fi
mount -a
fi

inetd

#!/bin/sh

if [ ! -x /usr/sbin/inetd ]
then
exit 0
fi if [ "$1" = "stop" -o "$1" = "restart" ]
then
echo "Stopping inetd: "
killall inetd
fi if [ "$1" = "start" -o "$1" = "restart" ]
then
echo "Starting inetd: "
/usr/sbin/inetd $INETD_ARGS
fi

Tony Liu

2016-12-18, Shenzhen

busybox rootfs 启动脚本分析(二)的更多相关文章

  1. busybox rootfs 启动脚本分析(一)

    imx6文件系统启动脚本分析.开机运行/sbin/init,读取/etc/inittab文件,进行初始化. 参考链接 http://blog.163.com/wghbeyond@126/blog/st ...

  2. Linux内核启动代码分析二之开发板相关驱动程序加载分析

    Linux内核启动代码分析二之开发板相关驱动程序加载分析 1 从linux开始启动的函数start_kernel开始分析,该函数位于linux-2.6.22/init/main.c  start_ke ...

  3. Hadoop启动脚本分析

    Hadoop启动脚本分析 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 能看到这篇博客的你估计对Hadoop已经有一个系统的了解了,最起码各种搭建方式你应该是会的,不会也没有关系, ...

  4. HBase配置&启动脚本分析

    本文档基于hbase-0.96.1.1-cdh5.0.2,对HBase配置&启动脚本进行分析 date:2016/8/4 author:wangxl HBase配置&启动脚本分析 剔除 ...

  5. Spark配置&启动脚本分析

    本文档基于Spark2.0,对spark启动脚本进行分析. date:2016/8/3 author:wangxl Spark配置&启动脚本分析 我们主要关注3类文件,配置文件,启动脚本文件以 ...

  6. 4. hadoop启动脚本分析

    4. hadoop启动脚本分析 1. hadoop的端口 ``` 50070 //namenode http port 50075 //datanode http port 50090 //2name ...

  7. hadoop启动脚本分析及常见命令

    进程------------------ [hdfs]start-dfs.sh NameNode NN DataNode DN SecondaryNamenode 2NN [yarn]start-ya ...

  8. Uboot启动流程分析(二)

    1.前言 在前面的文章Uboot启动流程分析(一)中,链接如下: https://www.cnblogs.com/Cqlismy/p/12000889.html 已经简单地分析了low_level_i ...

  9. linux系统 initrd.img中init启动脚本分析

    概述:这篇文章主体内容来源于网上转载.前面几篇文章倾向于制作initrd.img,这篇文章更倾向于initrd.img的运行过程:加载framebuff驱动 ide驱动和文件系统驱动,最后进入到真正的 ...

随机推荐

  1. 如何解决自动加载与模板中(如Smarty)的自动加载冲突的问题

    function aotuman($class){  include('./'.$class.'.class.php'); } spl_autoload_register('automan');  / ...

  2. Maven搭建 Spring环境

    http://www.cnblogs.com/huaizuo/p/4920308.html http://mvnrepository.com/artifact/commons-logging/comm ...

  3. C++ 系列:C++ 基础 001

    Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

  4. SQL中exists、not exists以及in、not in的区别和使用

    exists : 强调的是是否返回结果集,不要求知道返回什么, 比如:   select name from student where sex = 'm' and mark exists(selec ...

  5. TextView链接点击和长按冲突

    1.重写 import android.text.Layout; import android.text.Selection; import android.text.Spannable; impor ...

  6. jquery Ajax 案例

    html <div class="data"><ul></ul></div> <div id="load" ...

  7. 2012 Multi-University #9

    计算几何 A Farmer Greedy 题意:n个点选3个组成三角形,问m个点在三角形内的数字是奇数的这样的三角形个数. 分析:暴力O(N^3*M)竟然能过!我写的搓,加了优化才过掉.正解是先处理出 ...

  8. 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree

    Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...

  9. 非常详细的/etc/passwd解释

    root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nol ...

  10. 从零开始山寨Caffe·零:必先利其器

    工作环境 巧妇有了米炊 众所周知,Caffe是在Linux下写的,所以长久以来,大家都认为跑Caffe,先装Linux. niuzhiheng大神发起了caffe-windows项目(解决了一些编译. ...