You are not logged in.

#1 2009-06-02 22:16:12

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

[solved] Does the `init=...` kernel parameter accept shell scripts?

I ask because I've been messing around with creating my own Linux minidistro. Currently, only bash is installed — I want the kernel to run it (/bin/bash) instead of init (/sbin/init), which doesn't exist. So I added "init=/bin/bash" to the kernel parameters in my lilo.conf. The kernel knows it's there, but something weird happens when it tries to exec it:

bash: root=/dev/root: No such file or directory
<panic message>

(This is where init would kick in.)

I take this to mean the kernel is trying to run bash like so: `/bin/bash root=/dev/root`. Since there's no file called "root=/dev/root", this fails. On to plan B, creating /sbin/init as a shell script that runs /bin/bash:

#!/bin/bash
exec /bin/bash

But after setting the `init` parameter to "/sbin/init", the kernel gives this error instead:

init not found! (or something like that)
<panic message>

This makes me think it can't exec shell scripts. Do I need to write my own init and compile it as a binary?

(I'm using the stock Arch kernel for this.)

Last edited by Peasantoid (2009-06-03 00:01:46)

Offline

#2 2009-06-02 22:44:23

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: [solved] Does the `init=...` kernel parameter accept shell scripts?

Answer: yes. Here's the code for my init stub:

#include <stdio.h>
#include <unistd.h>
#include <errno.h>

int main(int argc, char **argv) {
    printf("Running /bin/bash...\n");
    if(execl("/bin/bash", "/bin/bash", NULL) == -1) {
        perror("execl");
        return 1;
    }

    return 0;
}

(Compile with `gcc init-stub.c -o init --static`.)

# It boots fine, but my keyboard doesn't work. A quick glance at the lights on my hub reveals that the USB subsystem hasn't even been initialized. How can I make it work? (I've tried adding usbcore, usbhid, and hid to $MODULES in /etc/mkinitcpio.conf and regenerating the initramfs, but this had no effect.)

# Solution: load the *hci_hcd modules. Only uhci_hcd and ehci_hcd seem to be necessary, although you may want ohci_hid as well (I didn't need it).

Last edited by Peasantoid (2009-06-02 23:50:01)

Offline

Board footer

Powered by FluxBB