LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 11-15-2020, 01:54 PM   #1
gaula92
LQ Newbie
 
Registered: Nov 2020
Location: Extremadura
Distribution: Debian, LFS
Posts: 3

Rep: Reputation: Disabled
[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?

Last edited by gaula92; 11-16-2020 at 06:16 PM.
 
Old 11-16-2020, 12:17 PM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,555
Blog Entries: 19

Rep: Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444Reputation: 4444
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.
 
Old 11-16-2020, 06:15 PM   #3
gaula92
LQ Newbie
 
Registered: Nov 2020
Location: Extremadura
Distribution: Debian, LFS
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hazel View Post
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'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pseudo terminals: /dev/ptmx <-> /dev/pts/ vs. /dev/ptyp <-> /dev/ttyp rtspitz Linux - Software 2 12-02-2011 02:07 PM
/dev/tty vs /dev/pts anshexp Linux - Kernel 1 09-21-2009 09:13 AM
How to reset/restart a tty from another tty? armandino Linux - General 4 02-25-2009 03:09 AM
I it possible to kill a tty or find which tty is being using by which process? geletine Linux - Software 2 01-15-2006 08:40 AM
change tty => system crashes (ati driver/tty resolution) mosca Debian 6 08-05-2004 07:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 03:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration