啟動shell環境

來源:互聯網
上載者:User
6.3 啟動shell環境

init_post函數來自同一個檔案的814行:

 

811/* This is a non __init function. Force it to be noinline otherwise gcc

 812 * makes it inline to init() and it becomes part of init.text section

 813 */

 814static noinline int init_post(void)

 815        __releases(kernel_lock)

 816{

 817        /* need to finish all async __init code before freeing the memory */

 818        async_synchronize_full();

 819        free_initmem();

 820        unlock_kernel();

 821        mark_rodata_ro();

 822        system_state = SYSTEM_RUNNING;

 823        numa_default_policy();

 824

 825

 826        current->signal->flags |= SIGNAL_UNKILLABLE;

 827

 828        if (ramdisk_execute_command) {

 829                run_init_process(ramdisk_execute_command);

 830                printk(KERN_WARNING "Failed to execute %s/n",

 831                                ramdisk_execute_command);

 832        }

 833

 834        /*

 835         * We try each of these until one succeeds.

 836         *

 837         * The Bourne shell can be used instead of init if we are

 838         * trying to recover a really broken machine.

 839         */

 840        if (execute_command) {

 841                run_init_process(execute_command);

 842                printk(KERN_WARNING "Failed to execute %s.  Attempting "

 843                                        "defaults.../n", execute_command);

 844        }

 845        run_init_process("/sbin/init");

 846        run_init_process("/etc/init");

 847        run_init_process("/bin/init");

 848        run_init_process("/bin/sh");

 849

 850        panic("No init found.  Try passing init= option to kernel. "

 851              "See Linux Documentation/init.txt for guidance.");

 852}

 

 

819行,這就是上面說到的那個釋放init代碼的函數了,它顯然不能是__init打頭:

void free_initmem(void)

{

       free_init_pages("unused kernel memory",

                     (unsigned long)(&__init_begin),

                     (unsigned long)(&__init_end));

}

 

這個函數基本上就是執行init了,失敗就panic了。順便說一句,/dev/console最後被012描述符引用,也就是所有沒有reopen的進程的標準輸入輸出和出錯。

 

到此,核心啟動過程就完成了,init根據根檔案系統的配置在初始化使用者態的進程,啟動系統。我們的瘋狂核心,也就到此告一段落了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.