title: QEMU: /bin/sh: can't access tty; job control turned off
body: <p>As a development environment for linux kernel, I'm using qemu with setting up <code>initramfs</code> as similar to what is shown <a href="http://mgalgs.github.io/2015/05/16/how-to-build-a-custom-linux-kernel-for-qemu-2015-edition.html" rel="noreferrer">here</a>, with few additional executable. Basically, it uses busybox for creating minimal environment and package it up using cpio. Content of <code>init</code> is shown below.</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>Using following command to start VM:</p>
  
  <pre><code>qemu-system-x86_64 -kernel bzImage -initrd initramfs -append "console=ttyS0" -nographic
  </code></pre>
  
  <p>It throws following error:</p>
  
  <pre><code>/bin/sh: can't access tty; job control turned off
  </code></pre>
  
  <p>Although, system functions normal in most cases. But, I'm not able to create background process:</p>
  
  <pre><code>$ prog &amp;
  /bin/sh: can't open '/dev/null'
  $ fg
  /bin/sh: fg: job (null) not created under job control
  </code></pre>
  
  <p>Root of all problems seem to be not having access to <code>tty</code>. How can I fix this?</p>
  
  <p>EDIT: Apart from Accepted answer, as a get around <code>cttyhack</code> of busybox can be used.</p>
  
  <pre><code>$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
  </code></pre>