site  contact  subhomenews

Fix for /dev/tty in initrd

August 09, 2020 — BarryK

This is an ancient problem. When we drop out to shell in the initrd (initramfs), there is this message:

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

As far as I know, it means that certain keystrokes, such as CRTL-C won't work. Um ,yes, this page explains:

https://www.gnu.org/software/bash/manual/html_node/Job-Control-Basics.html

We have had this message from the very early puppies right until now. I have finally decided to track down the cause, and found this:

https://unix.stackexchange.com/questions/529935/how-to-avoid-cant-access-tty-job-control-turned-off-when-boot-to-initramfs

In the 'init' script in the initrd of EasyOS, there is a function that will dropout to a shell:

exit_to_initrd() {
[ ! "${1}" ] && set -- " Have exited from init script at this line number"
echo -e '\033[1;31m' #bright red
echo -n 'Line '
grep -n -o "${1}" ${0}
#echo -en '\033[0;39m' #reset foreground color to default.
echo -en '\033[1;35m' #1;35 foreground bright magenta
echo 'Note 1: Type "exit", the init script will attempt to continue.'
echo 'Note 2: On some PCs the keyboard does not work at this stage of bootup.'
echo 'Note 3: if "ctrl-alt-del" not work, hold down power button to poweroff.'
echo 'Note 4: Console text editor "mp" is available.'
echo 'Note 5: Console file manager "shfm": Navigate with arrow keys, "!" to spawn'
echo ' a shell, "?" popup help, "q" to quit. Help file is "/shfm.txt"'
if [ -f /bin/nnn ];then
echo 'Note 6: Console file manager "nnn": Same keys. Help file "/nnn.txt"'
if [ ! -f /bin/nnn.bin ];then
mv -f /bin/nnn /bin/nnn.bin
echo -e '#!/bin/sh\nexec nnn.bin -c -d' > /bin/nnn
chmod 755 /bin/nnn
fi
export XDG_CONFIG_HOME=/etc/nnn
#note, i think if append /etc/nnn/plugins to $PATH, then can just have "simple" here...
export NNN_OPEN=/etc/nnn/plugins/simple
fi
echo -en '\033[0;39m' #reset foreground color to default.
export EDITOR=mp
export SHFM_OPENER=/sbin/xdg-open #200807 for shfm file manager.
/bin/sh
}

The fix is to replace that last line "/bin/sh" with this:

setsid cttyhack sh

Yay, fixed! 

Tags: easy