LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   "/dev/tty: No such device or address" on custom tiny Linux w/ BusyBox - WTF? (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/dev-tty-no-such-device-or-address-on-custom-tiny-linux-w-busybox-wtf-4175663339/)

kjensenxz 10-29-2019 01:28 AM

"/dev/tty: No such device or address" on custom tiny Linux w/ BusyBox - WTF?
 
I've been working on a tiny Linux distro running just a minimal Linux kernel, BusyBox, and a custom init for a pseudo-embedded project for use exclusively under QEMU/KVM with serial console on stdio or a socket.

The init isn't that hard of a worker; it just mounts the necessary filesystems and runs /bin/sh as root. Come on now, it's a single-user system for a sandbox!

This project is something I've been working on off and on with little success, mostly because of an error I could not figure out kept getting in my way:
Code:

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

Tonight, I picked back up. Same error. I built strace statically and loaded it into the initramfs. I straced.
Code:

# edited for formatting, /bin/sh printed inside of the strace
openat(AT_FDCWD, "/dev/tty", O_RDWR)    = -1 ENXIO (No such device or address)
ioctl(2, TCGETS, {B9600 opost isig icanon echo ...}) = 0
fcntl(2, F_DUPFD_CLOEXEC, 10)          = 10
ioctl(10, TIOCGPGRP, 0x7ffdb3288af4)    = -1 ENOTTY (Inappropriate ioctl for device)
write(2, "/bin/sh: ", 9)                = 9
write(2, "can't access tty; job control tu"..., 40) = 40
write(2, "\n", 1)

Uhhhh.... cat?
Code:

cat: can't open '/dev/tty': No such device or address
Okay, check the special file attributes. According to LFS, /dev/tty should be a character file with major 5 minor 1.
Code:

# ls -l /dev/tty
crw-rw-rw-    1 0        0          5,  0 Oct 29 05:49 /dev/tty

Okay, my kernel must be misconfigured. After searching for some time how to enable CONFIG_VIRTIO while using make xconfig (just use nconfig or menuconfig, it's so much better), confusing myself with config files, recompiling two or three times, naming & relocating the proper config, I enabled Unix98 and set CONFIG_VIRTIO=y. Oh wait, wrong config.

Also, I couldn't get virtio console to work for an additional half hour. Whatever, it probably won't change anything.

No change. WTF? :banghead:

I was already typing a question here when I noticed the "Click Here to Find Similar Threads" button. Alright, fine. After reading and re-reading 3 of the relevant matches, some inittab and agetty stuff clicked in my head. /dev/tty is getty's job! (I guess.)

I went back to the drawing board, and decided to test getty before I posted. After fumbling over the way BusyBox wants the command line arguments in my fluster, I eloquently typed:

Code:

# getty -n -l /bin/sh 9600 ttyS0
and was greeted by
Code:

#
Almost two years of ignoring this and doing weird hacks to suppress the error from testing and light "production" (mostly using tail -f -n +2), I figured it out: just freaking use getty.

Thanks for being my rubber duck with advice, LQ.org! ...time to rewrite my init.
P.S., special thanks to greenleaf! :jawa:


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