<menu id="w8yyk"><menu id="w8yyk"></menu></menu>
  • <dd id="w8yyk"><nav id="w8yyk"></nav></dd>
    <menu id="w8yyk"></menu>
    <menu id="w8yyk"><code id="w8yyk"></code></menu>
    <menu id="w8yyk"></menu>
    <xmp id="w8yyk">
    <xmp id="w8yyk"><nav id="w8yyk"></nav>
  • 網站首頁 > 物聯資訊 > 技術分享

    從linux啟動到rootfs的掛載分析

    2016-09-28 00:00:00 廣州睿豐德信息科技有限公司 閱讀
    睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接

    簡單的來說,根文件系統包括虛擬根文件系統和真實根文件系統。在Kernel啟動的初始階段,首先去創建虛擬的根文件系統,接下來再去調用do_mount來加載真正的文件系統,并將根文件系統切換到真正的文件系統,也即真實的文件系統。

    一.什么是根文件系統

    在傳統的Windows機器上目錄結構中,可能會包括C:或者D:盤,而他們一般就稱之為特定邏輯磁盤的根目錄。從文件系統的層面來說,每一個分區都包含了一個根目錄區,也即系統中存在多個根目錄。

    但是,在Linux系統中,目錄結構與Windows上有較大的不同。系統中只有一個根目錄,路徑是“/”,而其它的分區只是掛載在根目錄中的一個文件夾,如“/proc”和“system”等,這里的“/”就是Linux中的根目錄。

    對應根目錄也就存在一個根目錄文件系統的概念,我們可以將某一個分區掛載為根目錄文件系統,如6410公版中就將mtdblk2掛載為根目錄文件系統。程序中可以通過U-Boot給Kernel指定參數或者編譯選項來指定,如目前的開發板中就通過如下的編譯選項來制定根目錄文件系統:

    CONFIG_CMDLINE="console=ttyS0,115200 mem=108M rdinit=/linuxrc root=/dev/mtdblock2"

     

    簡單的來說,根目錄文件系統就是一種目錄結構,包括了Linux啟動的時候所必須的一些目錄結構和重要文件。

    根文件系統有兩種,一種是虛擬根文件系統,另外一種是真實的根文件系統。一般情況下,會首先在虛擬的根文件系統中做一部分工作,然后切換到真實的根文件系統下面。

    籠統的來說,虛擬的根文件系統包括三種類型,即Initramfs、cpio-initrd和image-initrd。

    二.相關重要概念

    1. Initrd

    Initrd是在Linux中普遍采用的一種技術,就是由Bootloader加載的內存盤。在系統啟動的過程中,首先會執行Initrd中的“某一個文件” 來完成驅動模塊加載的任務,第二階段才會執行真正的根文件系統中的/sbin/init。這里提到的第一階段是為第二階段服務的,主要是用來加載根文件系統以及根文件系統存儲介質的驅動程序。

    資料中提到,存在多種類型的Initrd,實際應用中包括無Initrd、Linux Kernel和Initrd打包、Linux Kernel和Initrd分離以及RAMDisk Initrd。

    目前,手中項目采用的就是第四種策略。在系統啟動的時候,U-Boot會將Linux Kernel和Rootfs加載到內存,并跳轉到Linux Kernel的入口地址執行程序。這篇文章將側重對該種情況進行分析。

    三.根文件系統加載代碼分析

    1. VFS的注冊

    首先不得不從老掉牙的Linux系統的函數start_kernel()說起。函數start_kernel()中會去調用vfs_caches_init()來初始化VFS。

    下面看一下函數vfs_caches_init ()的代碼:

    void __init vfs_caches_init(unsigned long mempages)

    {

    unsigned long reserve;

    /* Base hash sizes on available memory, with a reserve equal to

    150% of current kernel size */

    reserve = min((mempages - nr_free_pages()) * 3/2, mempages - 1);

    mempages -= reserve;

    names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,

    SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);

    dcache_init();

    inode_init();

    files_init(mempages);

    [1] mnt_init();

    bdev_cache_init();

    chrdev_init();

    }

     

    代碼【1】:vfs_caches_init()中最重要的函數。函數mnt_init()會創建一個rootfs,這是個虛擬的rootfs,即內存文件系統,后面還會指向真實的文件系統。

    接下來看一下函數mnt_init():

    Void __init mnt_init(void)

    {

    unsigned u;

    int err;

    init_rwsem(&namespace_sem);

    mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct vfsmount),

    0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);

    mount_hashtable = (struct list_head *)__get_free_page(GFP_ATOMIC);

    if (!mount_hashtable)

    panic("Failed to allocate mount hash table/n");

    printk("Mount-cache hash table entries: %lu/n", HASH_SIZE);

    for (u = 0; u < HASH_SIZE; u++)

    INIT_LIST_HEAD(&mount_hashtable[u]);

    err = sysfs_init();

    if (err)

    printk(KERN_WARNING "%s: sysfs_init error: %d/n",

    __func__, err);

    fs_kobj = kobject_create_and_add("fs", NULL);

    if (!fs_kobj)

    printk(KERN_WARNING "%s: kobj create error/n", __func__);

    [1] init_rootfs();

    [2] init_mount_tree();

    }

     

    代碼[1]:創建虛擬根文件系統;

    代碼[2]:注冊根文件系統。

    接下來看一下函數init_mount_tree()的代碼:

    static void __init init_mount_tree(void)

    {

    struct vfsmount *mnt;

    struct mnt_namespace *ns;

    struct path root;

    [1] mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);

    if (IS_ERR(mnt))

    panic("Can't create rootfs");

    ns = kmalloc(sizeof(*ns), GFP_KERNEL);

    if (!ns)

    panic("Can't allocate initial namespace");

    atomic_set(&ns->count, 1);

    INIT_LIST_HEAD(&ns->list);

    init_waitqueue_head(&ns->poll);

    ns->event = 0;

    list_add(&mnt->mnt_list, &ns->list);

    ns->root = mnt;

    mnt->mnt_ns = ns;

    init_task.nsproxy->mnt_ns = ns;

    get_mnt_ns(ns);

    root.mnt = ns->root;

    root.dentry = ns->root->mnt_root;

    set_fs_pwd(current->fs, &root);

    [2] set_fs_root(current->fs, &root);

    }

     

    代碼[1]:創建虛擬文件系統;

    代碼[2]:將當前的文件系統配置為根文件系統。

    可能有人會問,為什么不直接把真實的文件系統配置為根文件系統?

    答案很簡單,內核中沒有根文件系統的設備驅動,如USB等存放根文件系統的設備驅動,而且即便你將根文件系統的設備驅動編譯到內核中,此時它們還尚未加載,其實所有的Driver是由在后面的Kernel_Init線程進行加載。所以需要CPIO Initrd、Initrd和RAMDisk Initrd。另外,我們的Root設備都是以設備文件的方式指定的,如果沒有根文件系統,設備文件怎么可能存在呢?

    2. VFS的掛載

    接下來,Kernel_Start會去調用rest_init()并會去創建系統中的第一個進程Kernel_Init,并由其調用所有模塊的初始化函數,其中ROOTFS的初始化函數也在這個期間被調用。

    函數rest_init代碼如下:

    /*

    * We need to finalize in a non-__init function or else race conditions

    * between the root thread and the init thread may cause start_kernel to

    * be reaped by free_initmem before the root thread has proceeded to

    * cpu_idle.

    *

    * gcc-3.4 accidentally inlines this function, so use noinline.

    */

    static noinline void __init_refok rest_init(void)

    __releases(kernel_lock)

    {

    int pid;

    kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);

    numa_default_policy();

    pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);

    kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);

    unlock_kernel();

    /*

    * The boot idle thread must execute schedule()

    * at least once to get things moving:

    */

    init_idle_bootup_task(current);

    rcu_scheduler_starting();

    preempt_enable_no_resched();

    schedule();

    preempt_disable();

    /* Call into cpu_idle with preempt disabled */

    cpu_idle();

    }

     

    函數Kernel_Init代碼如下:

    static int __init kernel_init(void * unused)

    {

    lock_kernel();

    /*

    * init can run on any cpu.

    */

    set_cpus_allowed_ptr(current, CPU_MASK_ALL_PTR);

    /*

    * Tell the world that we're going to be the grim

    * reaper of innocent orphaned children.

    *

    * We don't want people to have to make incorrect

    * assumptions about where in the task array this

    * can be found.

    */

    init_pid_ns.child_reaper = current;

    cad_pid = task_pid(current);

    smp_prepare_cpus(setup_max_cpus);

    do_pre_smp_initcalls();

    start_boot_trace();

    smp_init();

    sched_init_smp();

    cpuset_init_smp();

    [1] do_basic_setup();

    /*

    * check if there is an early userspace init. If yes, let it do all

    * the work

    */

    [2] if (!ramdisk_execute_command)

    ramdisk_execute_command = "/init";

    [3] if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {

    ramdisk_execute_command = NULL;

    prepare_namespace();

    }

    /*

    * Ok, we have completed the initial bootup, and

    * we're essentially up and running. Get rid of the

    * initmem segments and start the user-mode stuff..

    */

    init_post();

    return 0;

    }

     

    代碼[1]:函數do_basic_setup()調用所有模塊的初始化函數,包括initramfs的初始化函數populate_rootfs。這部分代碼在init/initramfs.c下面,函數populate_rootfs通過如下方式導出:

    rootfs_initcall(populate_rootfs);

     

    代碼[2]:ramdisk_execute_command值通過“rdinit=”指定,如果未指定,則采用默認的值/init。

    代碼[3]:檢查根文件系統中是否存在文件ramdisk_execute_command,如果存在的話則執行init_post(),否則執行prepare_namespace()掛載根文件系統。

    需要特別指出的是initramfs.c模塊的入口函數populate_rootfs()是否執行取決于Kernel的編譯選項。參照linux/init目錄下的makefile文件,如下:

    #

    # Makefile for the linux kernel.

    #

    obj-y := main.o version.o mounts.o

    ifneq ($(CONFIG_BLK_DEV_INITRD),y)

    obj-y += noinitramfs.o

    else

    obj-$(CONFIG_BLK_DEV_INITRD) += initramfs.o

    endif

    obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o

    mounts-y := do_mounts.o

    mounts-$(CONFIG_BLK_DEV_RAM) += do_mounts_rd.o

    mounts-$(CONFIG_BLK_DEV_INITRD) += do_mounts_initrd.o

    mounts-$(CONFIG_BLK_DEV_MD) += do_mounts_md.o

     

    主要完成Initrd的檢測工作,檢查出是CPIO Initrd還是Initramfs還是Image-Initrd還是需要在編譯的時候做如下的配置(General setupàInitramfs/initrd support):

    clip_image002

    該函數的代碼如下:

    static int __init populate_rootfs(void)

    {

    [1] char *err = unpack_to_rootfs(__initramfs_start,

    __initramfs_end - __initramfs_start, 0);

    if (err)

    panic(err);

    [2] if (initrd_start) {

    #ifdef CONFIG_BLK_DEV_RAM

    int fd;

    printk(KERN_INFO "checking if image is initramfs...");

    [3] err = unpack_to_rootfs((char *)initrd_start,

    initrd_end - initrd_start, 1);

    if (!err) {

    printk(" it is/n");

    unpack_to_rootfs((char *)initrd_start,

    initrd_end - initrd_start, 0);

    free_initrd();

    return 0;

    }

    printk("it isn't (%s); looks like an initrd/n", err);

    [4] fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700);

    if (fd >= 0) {

    [5] sys_write(fd, (char *)initrd_start,

    initrd_end - initrd_start);

    sys_close(fd);

    [6] free_initrd();

    }

    #else

    printk(KERN_INFO "Unpacking initramfs...");

    [7] err = unpack_to_rootfs((char *)initrd_start,

    initrd_end - initrd_start, 0);

    if (err)

    panic(err);

    printk(" done/n");

    free_initrd();

    #endif

    }

    return 0;

    }

     

    代碼[1]:unpack_to_rootfs顧名思義,就是解壓包到rootfs,其具有兩個功能,一個是檢測是否是屬于cpio包,另外一個就是解壓cpio包,通過最后一個參數進行控制。1:檢測,0:解壓。其實,Initramfs也是壓縮過后的CPIO文件。

    資料中提到,Linux2.5中開始引入initramfs,在Linux2.6中一定存在,而且編譯的時候通過連接腳本arch/arm/kernel/vmlinux.lds將其編譯到__initramfs_start~__initramfs_end,執行完unpack_to_rootfs后將被拷貝到根目錄。

    代碼[2]:判斷是否加載了Initrd,無論對于那種格式的Initrd,即無論是CPIO-Initrd還是Image-Initrd,U-Boot都會將其拷貝到initrd_start。當然了,如果是initramfs的情況下,該值肯定為空了。

    代碼[3]:判斷加載的是不是CPIO-Initrd。

    通過在這里主要用于檢測,如果是編譯到Linux Kernel的CPIO Initrd,__initramfs_end - __initramfs_start應該是大于零的,否則為零,其實也就是通過這里來判斷是否為CPIO Initrd。

    代碼[4]:如果不是CPIO-Initrd,則就是Image-Initrd,將其內容保存到文件/initrd.image中。在根文件系統中創建文件/initrd.image。

    代碼[5]:這里是對Image-Initrd提供支持的,將內存中的initrd賦值到initrd.image中,以釋放內存空間。

    代碼[6]:釋放Initrd所占用的內存空間。

    另外,如果要支持Image-Initrd的話,必須要配置CONFIG_BLK_DEV_RAM,配置的方法上面已經講過。

    下面接著來分析函數kernel_init

    static int __init kernel_init(void * unused)

    {

    do_basic_setup();

    /*

    * check if there is an early userspace init. If yes, let it do all

    * the work

    */

    if (!ramdisk_execute_command)

    ramdisk_execute_command = "/init";

    [1] if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {

    ramdisk_execute_command = NULL;

    prepare_namespace();

    }

    /*

    * Ok, we have completed the initial bootup, and

    * we're essentially up and running. Get rid of the

    * initmem segments and start the user-mode stuff..

    */

    init_post();

    return 0;

    }

     

    代碼[1]:前面在對函數populate_rootfs進行分析的時候已經知道,對于initramfs和cpio-initrd的情況,都會將文件系統(其實是一個VFS)解壓到根文件系統。如果虛擬文件系統中存在ramdisk_execute_command指定的文件則直接轉向init_post()來執行,否則執行函數prepare_namespace()。

    3. 根文件系統的掛載

    從上面的代碼分析中知道,對于Image-Initrd或者VFS(即InitRamfs或者CPIO-Initrd)中不存在文件ramdisk_execute_command的情況,則執行prepare_namespace()。

    接下來看一下函數prepare_namespace()的代碼:

    /*

    * Prepare the namespace - decide what/where to mount, load ramdisks, etc.

    */

    void __init prepare_namespace(void)

    {

    int is_floppy;

    [1] if (root_delay) {

    printk(KERN_INFO "Waiting %dsec before mounting root device.../n",

    root_delay);

    ssleep(root_delay);

    }

    /*

    * wait for the known devices to complete their probing

    *

    * Note: this is a potential source of long boot delays.

    * For example, it is not atypical to wait 5 seconds here

    * for the touchpad of a laptop to initialize.

    */

    [2] wait_for_device_probe();

    md_run_setup();

    [3] if (saved_root_name[0]) {

    root_device_name = saved_root_name;

    if (!strncmp(root_device_name, "mtd", 3) ||

    !strncmp(root_device_name, "ubi", 3)) {

    [4] mount_block_root(root_device_name, root_mountflags);

    goto out;

    }

    [5] ROOT_DEV = name_to_dev_t(root_device_name);

    if (strncmp(root_device_name, "/dev/", 5) == 0)

    root_device_name += 5;

    }

    [6] if (initrd_load())

    goto out;

    [7] /* wait for any asynchronous scanning to complete */

    if ((ROOT_DEV == 0) && root_wait) {

    printk(KERN_INFO "Waiting for root device %s.../n",

    saved_root_name);

    while (driver_probe_done() != 0 ||

    (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0)

    msleep(100);

    async_synchronize_full();

    }

    is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;

    if (is_floppy && rd_doload && rd_load_disk(0))

    ROOT_DEV = Root_RAM0;

    mount_root();

    out:

    [9] sys_mount(".", "/", NULL, MS_MOVE, NULL);

    [10] sys_chroot(".");

    }

     

    代碼[1]:資料中提到,對于將根文件系統存放到USB或者SCSI設備上的情況,Kernel需要等待這些耗費時間比較久的設備驅動加載完畢,所以這里存在一個Delay。

    代碼[2]:從字面的意思來看,這里也是來等待根文件系統所在的設備探測函數的完成。

    代碼[3]:參數saved_root_name存放的是Kernel參數root=所指定的設備文件,這點不再贅述,可以參照代碼。

    代碼[4]:按照資料中的解釋,這里相當于將saved_root_nam指定的設備進行加載。如下面傳遞給內核的command line:

    CONFIG_CMDLINE="console=ttyS0,115200 mem=108M rdinit=/linuxrc root=/dev/mtdblock2"

     

    實際上就是加載/dev/mtdblock2。

    代碼[5]:參數ROOT_DEV存放設備節點號。

    代碼[6]:掛載initrd,這里進行的操作相當的復雜,可以參照后續關于該函數的詳細解釋。

    代碼[7]:如果指定mount_initrd為true,即沒有指定在函數initrd_load中mount的話,則在這里重新realfs的mount操作。

    代碼[9]:將掛載點從當前目錄(實際當前的目錄在mount_root中或者在mount_block_root中指定)移到根目錄。對于上面的command line的話,當前的目錄就是/dev/mtdblock2。

    代碼[10]:將當前目錄當作系統的根目錄,至此虛擬系統根目錄文件系統切換到了實際的根目錄文件系統。

    接下來看一下函數initrd_load()的代碼:

    int __init initrd_load(void)

    {

    [1] if (mount_initrd) {

    [2] create_dev("/dev/ram", Root_RAM0);

    /*

    * Load the initrd data into /dev/ram0. Execute it as initrd

    * unless /dev/ram0 is supposed to be our actual root device,

    * in that case the ram disk is just set up here, and gets

    * mounted in the normal path.

    */

    [3] if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {

    sys_unlink("/initrd.image");

    [4] handle_initrd();

    return 1;

    }

    }

    sys_unlink("/initrd.image");

    return 0;

    }

     

    代碼[1]:可以通過Kernel的參數“noinitrd“來配置mount_initrd的值,默認為1,很少看到有項目區配置該值,所以一般情況下,mount_initrd的值應該為1;

    代碼[2]:創建一個Root_RAM0的設備節點/dev/ram;

    代碼[3]:如果根文件設備號不是Root_RAM0則程序就會執行代碼[4],換句話說,就是給內核指定的參數不是/dev/ram,例如上面指定的/dev/mtdblock2設備節點肯定就不是Root_RAM0。

    另外這行代碼還將文件initrd.image釋放到節點/dev/ram0,也就是對應image-initrd的操作。

    代碼[4]:函數handle_initrd主要功能是執行Initrd中的linuxrc文件,并且將realfs的根目錄設置為當前目錄。其實前面也已經提到了,這些操作只對image-cpio的情況下才會去執行。

    函數handle_initrd的代碼如下:

    static void __init handle_initrd(void)

    {

    int error;

    int pid;

    [1] real_root_dev = new_encode_dev(ROOT_DEV);

    [2] create_dev("/dev/root.old", Root_RAM0);

    /* mount initrd on rootfs' /root */

    mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);

    [3] sys_mkdir("/old", 0700);

    root_fd = sys_open("/", 0, 0);

    old_fd = sys_open("/old", 0, 0);

    /* move initrd over / and chdir/chroot in initrd root */

    [4] sys_chdir("/root");

    sys_mount(".", "/", NULL, MS_MOVE, NULL);

    sys_chroot(".");

    /*

    * In case that a resume from disk is carried out by linuxrc or one of

    * its children, we need to tell the freezer not to wait for us.

    */

    current->flags |= PF_FREEZER_SKIP;

    [5] pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);

    if (pid > 0)

    while (pid != sys_wait4(-1, NULL, 0, NULL))

    yield();

    current->flags &= ~PF_FREEZER_SKIP;

    /* move initrd to rootfs' /old */

    sys_fchdir(old_fd);

    sys_mount("/", ".", NULL, MS_MOVE, NULL);

    /* switch root and cwd back to / of rootfs */

    [6] sys_fchdir(root_fd);

    sys_chroot(".");

    sys_close(old_fd);

    sys_close(root_fd);

    [7] if (new_decode_dev(real_root_dev) == Root_RAM0) {

    sys_chdir("/old");

    return;

    }

    [8] ROOT_DEV = new_decode_dev(real_root_dev);

    mount_root();

    [9] printk(KERN_NOTICE "Trying to move old root to /initrd ... ");

    error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);

    if (!error)

    printk("okay/n");

    else {

    int fd = sys_open("/dev/root.old", O_RDWR, 0);

    if (error == -ENOENT)

    printk("/initrd does not exist. Ignored./n");

    else

    printk("failed/n");

    printk(KERN_NOTICE "Unmounting old root/n");

    sys_umount("/old", MNT_DETACH);

    printk(KERN_NOTICE "Trying to free ramdisk memory ... ");

    if (fd < 0) {

    error = fd;

    } else {

    error = sys_ioctl(fd, BLKFLSBUF, 0);

    sys_close(fd);

    }

    printk(!error ? "okay/n" : "failed/n");

    }

    }

     

    代碼[1]:real_root_dev為一個全局變量,用來保存realfs的設備號。

    代碼[2]:調用mount_block_root將realfs加載到VFS的/root下。

    代碼[3]:提取rootfs的根文件描述符并將其保存到root_fd,資料中提及其用處就是在后續調用sys_chroot到initrd的文件系統后,處理完init請求后,還能夠再次切回到rootfs,這一點在一份IBM官方有關cpio-initrd和image-initrd的執行流程圖中可以看到,如下:

    clip_image004

    代碼[4]:sys_chroot到initrd文件系統,前面已經掛載initrd到VFS的root目錄下;

    代碼[5]:執行initrd中的linuxrc,并等待執行結束;

    代碼[6]:initrd執行結束后,切回到rootfs,不知道為什么直接用節點切呢?

    代碼[7]:如果real_root_dev直接配置為Root_RAM0,也即直接使用直接使用initrd作為realfs,改變當前目錄到initrd中,并直接返回。

    代碼[8]:執行完Linuxrc后,realfs已經確定,則調用mount_root將realfs掛載到VFS的/root目錄下,并將當前的目錄配置為VFS的/root。

    代碼[9]:收尾的工作,例如釋放內存等。

    4. 真實根文件系統掛載后的操作

    下面回過頭來再看上面提到的init_post,該函數實際上是在Kernel_init中最后執行的函數。其代碼如下:

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

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

    */

    static noinline int init_post(void)

    {

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

    async_synchronize_full();

    free_initmem();

    unlock_kernel();

    mark_rodata_ro();

    system_state = SYSTEM_RUNNING;

    numa_default_policy();

    if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)

    printk(KERN_WARNING "Warning: unable to open an initial console./n");

    (void) sys_dup(0);

    (void) sys_dup(0);

    current->signal->flags |= SIGNAL_UNKILLABLE;

    if (ramdisk_execute_command) {

    run_init_process(ramdisk_execute_command);

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

    ramdisk_execute_command);

    }

    /*

    * We try each of these until one succeeds.

    *

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

    * trying to recover a really broken machine.

    */

    if (execute_command) {

    run_init_process(execute_command);

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

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

    }

    run_init_process("/sbin/init");

    run_init_process("/etc/init");

    run_init_process("/bin/init");

    run_init_process("/bin/sh");

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

    }

     

    可以看到,在該函數的最后,以此會去搜索文件并執行ramdisk_execute_command、execute_command、/sbin/init、/etc/init、/bin/init和/bin/sh,如果發現這些文件均不存在的話,則通過panic輸出錯誤命令,并將當前的系統Halt在那里。

    RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成
    最近免费观看高清韩国日本大全