bash 如何从 /etc/inittab 启动 linux shell

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3150425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 22:16:39  来源:igfitidea点击:

How to start a linux shell as from /etc/inittab

bashinteractiveinitjob-control

提问by siebert

We used to have two entries in our /etc/inittab:

我们曾经在 /etc/inittab 中有两个条目:

::sysinit:/etc/init.d/rcS
ttyS0::respawn:-/bin/sh

rcS is a shell script which normally starts our application, but in a special case we called "return" to terminate it which apparently lets the /bin/sh take over the tty as we got a shell prompt where we could do some maintenance.

rcS 是一个 shell 脚本,它通常会启动我们的应用程序,但在特殊情况下,我们调用“return”来终止它,这显然让 /bin/sh 接管了 tty,因为我们得到了一个 shell 提示,我们可以在其中进行一些维护。

Now the inittab looks like this:

现在 inittab 看起来像这样:

::once:/etc/init.d/rcS

We now start the shell by executing "/bin/bash -i" in the rcS script, as we don't want to always run a second shell (due to memory constraints) which is normally never used.

我们现在通过在 rcS 脚本中执行“/bin/bash -i”来启动 shell,因为我们不想总是运行通常从未使用过的第二个 shell(由于内存限制)。

But the created bash doesn't feature job control, which is very limiting.

但是创建的 bash 没有工作控制功能,这是非常有限的。

So my question is, can I create a shell (and maybe terminate the rcS script) the same way the init processed did in our previous solution so that I get again a shell with job control?

所以我的问题是,我可以像在我们之前的解决方案中处理的 init 一样创建一个 shell(并且可能终止 rcS 脚本),以便我再次获得一个带有作业控制的 shell?

回答by Seth Robertson

This depends on exactly what OS you are running. Here is an example which works on RHEL/CentOS.

这完全取决于您正在运行的操作系统。这是一个适用于 RHEL/CentOS 的示例。

6:2345:respawn:/sbin/mingetty --autologin root tty6

Here is what someone else did for a similar trick.

这是其他人为类似的技巧所做的。

openvt -f -c 12 -w -- sh -c "unicode_start; echo -e '$NORPT'; exec $LOGINSH" >/dev/tty1