亞馬遜虛擬主機(jī)做網(wǎng)站最新清遠(yuǎn)發(fā)布
1.內(nèi)核啟動(dòng)文件系統(tǒng)后,文件系統(tǒng)的工作流程
? ? ? ? 1.參數(shù)的接收
? ? ? ? 2.參數(shù)的解析
? ? ? ? 3.參數(shù)的應(yīng)用
問(wèn)題:
1.????????UBOOT 傳給 KERNEL 的參數(shù)是以tagglist進(jìn)行的
? ? ? ? ? ?KERNEL 傳給 文件系統(tǒng)(busybox)的參數(shù)是以什么進(jìn)行的??
2.? ? ? ? 在整個(gè)文件系統(tǒng)中都需要什么組件?
文件系統(tǒng)初始化流程
parse_inittab()
????????file = fopen(INITTAB, "r");? ? ? ? //#define INITTAB ? ? ?"/etc/inittab"
????????if (file == NULL) {
? ? ? ????????? /* Reboot on Ctrl-Alt-Del */
? ? ? ????????? new_init_action(CTRLALTDEL, "reboot", "");
? ? ? ????????? /* Umount all filesystems on halt/reboot */
? ? ? ? ????????new_init_action(SHUTDOWN, "umount -a -r", "");
? ? ? ????????? /* Swapoff on halt/reboot */
? ? ? ????????? if (ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "swapoff -a", "");
? ? ? ? ????????/* Prepare to restart init when a HUP is received */
? ? ? ????????? new_init_action(RESTART, "init", "");
? ? ? ????????? /* Askfirst shell on tty1-4 */
? ? ? ? ????????new_init_action(ASKFIRST, bb_default_login_shell, "");
? ? ? ????????? new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
? ? ? ? ????????new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
? ? ? ????????? new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
? ? ? ? ????????/* sysinit */
? ? ? ????????? new_init_action(SYSINIT, INIT_SCRIPT, "");
inittab的格式:
????????????????Format for each entry: <id>:<runlevels>:<action>:<process>
文件系統(tǒng)默認(rèn)的參數(shù)解析:
static void new_init_action(int action, const char *command, const char *cons)
{struct init_action *new_action, *a, *last;if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))return;/* Append to the end of the list */for (a = last = init_action_list; a; a = a->next) {/* don't enter action if it's already in the list,* but do overwrite existing actions */if ((strcmp(a->command, command) == 0)&& (strcmp(a->terminal, cons) == 0)) {a->action = action;return;}last = a;}new_action = xzalloc(sizeof(struct init_action));if (last) {last->next = new_action;} else {init_action_list = new_action;}strcpy(new_action->command, command);new_action->action = action;strcpy(new_action->terminal, cons);messageD(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",new_action->command, new_action->action, new_action->terminal);
}struct init_action {struct init_action *next;int action;pid_t pid;char command[INIT_BUFFS_SIZE];char terminal[CONSOLE_NAME_SIZE];
};
默認(rèn)的inittab:? ?
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/sbin/init
::askfirst:/bin/sh
tty2::askfirst:/bin/sh
tty3::askfirst:/bin/sh
tty4::askfirst:/bin/sh
::SYSINIT:/etc/init.d/rcS
參數(shù)使用流程
????????run_actions(SYSINIT);
????????????????waitfor(a, 0);? //運(yùn)行該action對(duì)應(yīng)的命令函數(shù),并且等待其退出
啟動(dòng)流程:
??????????run_actions(SYSINIT);? //運(yùn)行::SYSINIT:/etc/init.d/rcS腳本,并且等待退出
? ? ? ? ??run_actions(WAIT);
? ? ? ? ? run_actions(ONCE);
while (1) {/* run the respawn stuff */run_actions(RESPAWN);/* run the askfirst stuff */run_actions(ASKFIRST);//:/bin/sh/* Don't consume all CPU time -- sleep a bit */sleep(1);/* Wait for a child process to exit */wpid = wait(NULL);while (wpid > 0) {/* Find out who died and clean up their corpse */for (a = init_action_list; a; a = a->next) {if (a->pid == wpid) {/* Set the pid to 0 so that the process gets* restarted by run_actions() */a->pid = 0;message(L_LOG, "process '%s' (pid %d) exited. ""Scheduling it for restart.",a->command, wpid);}}/* see if anyone else is waiting to be reaped */wpid = waitpid(-1, NULL, WNOHANG);}}
一個(gè)文件系統(tǒng)都需要什么?
? ? ? ? 1./dev/console????????
? ? ? ? 2.init_main函數(shù)---->busybox
? ? ? ? 3./etc/init.d/rcS--腳本
? ? ? ? 4.因?yàn)樾枰\(yùn)行shell命令,所以要有shell命令的支持函數(shù)--->busybox
? ? ? ? 5.標(biāo)準(zhǔn)庫(kù)函數(shù),包含glibc