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

标签 linux kernel qemu tty

作为 linux 内核的开发环境,我使用 qemu 并设置了 initramfs,类似于所示 here , 几乎没有额外的可执行文件。基本上,它使用 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

使用以下命令启动虚拟机:

qemu-system-x86_64 -kernel bzImage -initrd initramfs -append "console=ttyS0" -nographic

它抛出以下错误:

/bin/sh: can't access tty; job control turned off

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

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

所有问题的根源似乎是无法访问 tty。我该如何解决这个问题?

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

$cat init
#!/bin/sh

mount -t proc none /proc
mount -t sysfs none /sys
mknod -m 666 /dev/ttyS0 c 4 64

echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
setsid  cttyhack sh
exec /bin/sh

最佳答案

来自 Linux From Scratch Chapter 6.8. Populating /dev

6.8.1. Creating Initial Device Nodes

When the kernel boots the system, it requires the presence of a few device nodes, in particular the console and null devices. Create these by running the following commands:

mknod -m 600 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3

然后您应该继续执行“6.8.2. 安装 tmpfs 和填充/dev”中的步骤。注意 <--下面,我建议您阅读整个 free LFS .

mount -n -t tmpfs none /dev
mknod -m 622 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3
mknod -m 666 /dev/zero c 1 5
mknod -m 666 /dev/ptmx c 5 2
mknod -m 666 /dev/tty c 5 0 # <--
mknod -m 444 /dev/random c 1 8
mknod -m 444 /dev/urandom c 1 9
chown root:tty /dev/{console,ptmx,tty}

关于linux - QEMU:/bin/sh: 无法访问 tty;作业控制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36529881/

相关文章:

具有自定义架构的 Linux VM

linux - Qemu-ARM 用户仿真。使用 Go 时出错

linux - 在 awk 中拆分和比较

regex - AWK - 基于正则表达式添加值

linux - 内核态上下文切换时如何保持原子性?

android - 写安卓驱动?

c++ - const char* 与字符串文字的使用

linux - 将命令输出分配给变量

c++ - 如何让指针的深层拷贝将内部结构发送到内核?

模拟器上的 Android 4.3