【发布时间】:2016-04-10 12:43:32
【问题描述】:
作为 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。我该如何解决这个问题?
编辑:除了已接受的答案外,可以使用忙箱的 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
【问题讨论】: