开发者

Linux kernel that runs python file for init

Would it be possible and not incredibly difficult to build a linux kernel, wi开发者_如何学JAVAth a python interpreter built in or accessible from the kernel, that could run a python file as it's init process?


Can't you just replace /sbin/init or provide an init=... option to the boot loader? Just make sure you put python + libs on the root filesystem.

edit I didn't feel like thrashing a system, so it is untested, but looking at linux/init/main.c:

static void run_init_process(char *init_filename)
{
    argv_init[0] = init_filename;
    kernel_execve(init_filename, argv_init, envp_init);
}

I see no reason why a (python) script cannot replace the init process; execve is the same call that fires any normal process. And I think stdin and stdout are just connected to /dev/console, for init=/bin/sh also works. (but why on earth would you?!)


I don't think init needs to be a C binary; it can be a script with a #! at the beginning; if that is the case, then you can have it be a python program with little effort.

Having said that, it is pretty trivial to write an inittab where init just runs a single program once (Although it's usually more useful to do other stuff too).

Given that you will probably want to do some things on your system which can't easily be done with python (for example, try mounting filesystems without a "mount" binary), you will probably need a busybox (for example) anyway; adding "init" to a busybox binary increases its size very little.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜