小编use*_*865的帖子

QEMU:/ bin / sh:无法访问tty;作业控制已关闭

作为Linux内核的开发环境,我正在使用qemu进行设置,其设置initramfs类似于此处所示,几乎没有其他可执行文件。基本上,它使用busybox创建最小的环境并使用cpio打包。的内容init如下所示。

$ cat init
mount -t proc none /proc
mount -t sysfs none /sys

echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
exec /bin/sh
Run Code Online (Sandbox Code Playgroud)

使用以下命令启动VM:

qemu-system-x86_64 -kernel bzImage -initrd initramfs -append "console=ttyS0" -nographic
Run Code Online (Sandbox Code Playgroud)

它引发以下错误:

/bin/sh: can't access tty; job control turned off
Run Code Online (Sandbox Code Playgroud)

虽然,在大多数情况下,系统功能正常。但是,我无法创建后台进程:

$ prog &
/bin/sh: can't open '/dev/null'
$ fg
/bin/sh: fg: job (null) not created under job control
Run Code Online (Sandbox Code Playgroud)

所有问题的根源似乎都无法获得tty。我怎样才能解决这个问题?

编辑:除了可以接受的答案,cttyhack还可以使用busybox。

$cat init
#!/bin/sh

mount -t …
Run Code Online (Sandbox Code Playgroud)

linux kernel qemu tty

6
推荐指数
1
解决办法
6887
查看次数

使用函数建议使用bash脚本中的静音输出?

假设有人正在编写bash脚本,其中需要静默stdout,stderr并提供自定义输出.

是否可以使用如下功能:

dump(){
    "$@" > /dev/null 2>&1
}
Run Code Online (Sandbox Code Playgroud)

然后

dump rm filename || echo "custom-message"
Run Code Online (Sandbox Code Playgroud)

它无法按预期运行的可能情况是什么?

unix linux bash shell io-redirection

4
推荐指数
1
解决办法
448
查看次数

标签 统计

linux ×2

bash ×1

io-redirection ×1

kernel ×1

qemu ×1

shell ×1

tty ×1

unix ×1