LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   [SOLVED] Failing to open() /dev/tty (https://www.linuxquestions.org/questions/linux-from-scratch-13/%5Bsolved%5D-failing-to-open-dev-tty-4175685290/)

gaula92 11-15-2020 01:54 PM

[SOLVED] Failing to open() /dev/tty
 
Hi there,

I am trying to build a small system that uses a simple boot script as init process. Yes, I pass init=myscript to the Linux kernel, crazy thing to do but it works.

However, trying to open() on a tty fails on device not found, even if /dev/tty exists.

Here's the small script I use to the basic things like mount tmpfs, sysfs and procfs, start the udev daemon, configure the console...
Code:

#!/bin/sh

mount -t sysfs sysfs /sys
mount -t proc proc /proc

/etc/init.d/udev start >> /dev/null

setupcon

# Run sh now
/bin/sh

/etc/init.d/udev stop
umount -a

reboot -f

I know I should also add these, from the LFS manual here: http://www.linuxfromscratch.org/lfs/...6/devices.html

Code:


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}

But added these and still open() fails on /dev/tty.

I have also tried deleting /dev/tty and re-creating it again with
Code:

mknod -m 666 /dev/tty c 5 0
But still open() fails on /dev/tty.

I don't understand if /bin/sh is running on a TTY or not, because
Code:

ps -a
output is empty in this enviroment, or if that is a problem at all.
Any ideas on what am I missing here, please?

hazel 11-16-2020 12:17 PM

You need some actual tty devices as well as tty itself. For example I have
Code:

crw-rw-rw- 1 root  tty    5,  0 Nov 16 10:39 /dev/tty
crw--w---- 1 root  tty    4,  0 Nov 16 10:33 /dev/tty0
crw------- 1 hazel tty    4,  1 Nov 16 18:13 /dev/tty1
crw--w---- 1 root  tty    4,  2 Nov 16 17:36 /dev/tty2
...

Of course those were created by udev. You will probably need to create them by hand.

gaula92 11-16-2020 06:15 PM

Quote:

Originally Posted by hazel (Post 6185922)
You need some actual tty devices as well as tty itself. For example I have
Code:

crw-rw-rw- 1 root  tty    5,  0 Nov 16 10:39 /dev/tty
crw--w---- 1 root  tty    4,  0 Nov 16 10:33 /dev/tty0
crw------- 1 hazel tty    4,  1 Nov 16 18:13 /dev/tty1
crw--w---- 1 root  tty    4,  2 Nov 16 17:36 /dev/tty2
...

Of course those were created by udev. You will probably need to create them by hand.

Yep! creating the nodes in /dev (with the correct magic numbers and permissions), and sending sh to tty1 with setsid exec made the job!

Code:

mknod -m 666 /dev/tty c 5 0
mknod -m 660 /dev/tty1 c 4 1
setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'



All times are GMT -5. The time now is 06:20 PM.