Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

As a development environment for linux kernel, I'm using qemu with setting up initramfs as similar to what is shown here, with few additional executable. Basically, it uses busybox for creating minimal environment and package it up using cpio. Content of init is shown below.

$ 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

Using following command to start VM:

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

It throws following error:

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

Although, system functions normal in most cases. But, I'm not able to create background process:

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

Root of all problems seem to be not having access to tty. How can I fix this?

EDIT: Apart from Accepted answer, as a get around cttyhack of busybox can be used.

$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
like image 875
user148865 Avatar asked Apr 10 '16 12:04

user148865


1 Answers

From 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

You should then continue with the steps in "6.8.2. Mounting tmpfs and Populating /dev". Note the <-- below, and I suggest you read the entire 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}
like image 100
Elliott Frisch Avatar answered Oct 24 '22 15:10

Elliott Frisch