Start the shell Environment

Source: Internet
Author: User
6.3 start the shell Environment

The init_post function comes from the 814 rows of the same file:

 

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 */

814 static 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}

 

 

Line 3: This is the function used to release the init Code mentioned above. It obviously cannot start with _ init:

Void free_initmem (void)

{

Free_init_pages ("unused kernel memory ",

(Unsigned long) (<__ init_begin ),

(Unsigned long) (<__ init_end ));

}

 

Basically, this function is to execute init. If it fails, it will be panic. By the way, the/dev/console is finally referenced by the 012 descriptor, that is, the standard input/output and error of all processes without reopen.

 

At this point, the kernel startup process is complete. init starts the system according to the configuration of the root file system in the initialization user State process. Our crazy kernel has come to an end.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.