Find the answer to your Linux question:
Results 1 to 4 of 4
Hello Everyone, Currently, I am working on Mips Arch using Linux 2.6.18.8. I am looking for a suggestion about removing /init in init() of "linux-2.6.18.8/init/main.c". Currently I have a requirement ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2

    Can I remove /init and replace it with /sbin/init in main.c


    Hello Everyone,

    Currently, I am working on Mips Arch using Linux 2.6.18.8.

    I am looking for a suggestion about removing /init in init() of "linux-2.6.18.8/init/main.c".

    Currently I have a requirement where I need to use either /sbin/init or /init.

    I see that /init is softlink of /sbin/init. Can I remove /init and replace it with /sbin/init.

    In following code, what is the significance of "/sbin/init" and "/init".


    PHP Code:
    static int init(void unused)
    {
        
    lock_kernel();
        
    /*
         * init can run on any cpu.
         */
        
    set_cpus_allowed(currentCPU_MASK_ALL);
        
    /*
         * 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.
         */
        
    child_reaper current;

        
    smp_prepare_cpus(max_cpus);

        
    do_pre_smp_initcalls();

        
    smp_init();
        
    sched_init_smp();

        
    cpuset_init_smp();

        
    /*
         * Do this before initcalls, because some drivers want to access
         * firmware files.
         */
        
    populate_rootfs();

        
    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";
        if (
    sys_access((const char __user *) ramdisk_execute_command0) != 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..
         */
        
    free_initmem();
        
    unlock_kernel();
        
    mark_rodata_ro();
        
    system_state SYSTEM_RUNNING;
        
    numa_default_policy();

        if (
    sys_open((const char __user *) "/dev/console"O_RDWR0) < 0)
            
    printk(KERN_WARNING "Warning: unable to open an initial console.\n");

        (
    voidsys_dup(0);
        (
    voidsys_dup(0);

        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.");


    What will be the impact of doing this change ?

    Could you guys point me in right direction ?


    Thank you,
    MMK

  2. #2
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    280
    Errr...

    static int init() is a function inside another program. It has nothing whatsoever to do with /sbin/init, which is a standalone program residing in the filesystem and critically important during the boot process, after the kernel is done it's thing. /sbin/init takes over to make your system bloom into something useable by humans. The resemblance in name is purely coincidental.

    My best guess: browse the kernel source and learn from it, but don't touch until you understand things a lot better. Get the source for /sbin/init and see what it does.

    source for init (/sbin/init)

    Peace and Cheer.

  3. #3
    Just Joined! Backbone's Avatar
    Join Date
    Jan 2013
    Location
    /dev/null
    Posts
    4
    I don't know much about this, but isn't it that init is a parent process? you need it when the kernel starts up (well boot process), so if this is a parent process, you can't really pull it out, or otherwise, the child processes get's messed up !

  4. #4
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    280
    Yeah. it's true. Kid's getting into gnarly kernel hacking, and the best of luck to him.

    /init, /bin/init, /sbin/init, /etc/init.

    /bin/sh? For init? Ooh. Sounds bad. Isn't that single user mode? That's when the paramedics are showing up and the tow truck guy is shoveling bloody debris into the ditch for the crows to eat tomorrow morning.

    Soft links, Hard links. Black ink Blue ink Red ink. Whatever works.

    Don't let Hazel know, or she'll get out the 2224 page specification manual and beat us all black and blue and red with it.

    Did you know that kernel hacking is now deprecated in favor of reading specification manuals and not learning anything. Or, even better, perusing Windows Help. That always works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •