Nothing is stored in /dev/pts
. This filesystem lives purely in memory.
Entries in /dev/pts
are pseudo-terminals (pty for short). Unix kernels have a generic notion of terminals. A terminal provides a way for applications to display output and to receive input through a terminal device. A process may have a controlling terminal — for a text mode application, this is how it interacts with the user.
Terminals can be either hardware terminals (“tty”, short for “teletype”) or pseudo-terminals (“pty”). Hardware terminals are connected over some interface such as a serial port (ttyS0
, …) or USB (ttyUSB0
, …) or over a PC screen and keyboard (tty1
, …). Pseudo-terminals are provided by a terminal emulator, which is an application. Some types of pseudo-terminals are:
- GUI applications such as xterm, gnome-terminal, konsole, … transform keyboard and mouse events into text input and display output graphically in some font.
- Multiplexer applications such as screen and tmux relay input and output from and to another terminal, to decouple text mode applications from the actual terminal.
- Remote shell applications such as sshd, telnetd, rlogind, … relay input and output between a remote terminal on the client and a pty on the server.
If a program opens a terminal for writing, the output from that program appears on the terminal. It is common to have several programs outputting to a terminal at the same time, though this can be confusing at times as there is no way to tell which part of the output came from which program. Background processes that try to write to their controlling terminal may be automatically suspended by a SIGTTOU signal.
If a program opens a terminal for reading, the input from the user is passed to that program. If multiple programs are reading from the same terminal, each character is routed independently to one of the programs; this is not recommended. Normally there is only a single program actively reading from the terminal at a given time; programs that try to read from their controlling terminal while they are not in the foreground are automatically suspended by a SIGTTIN signal.
To experiment, run tty
in a terminal to see what the terminal device is. Let's say it's /dev/pts/42
. In a shell in another terminal, run echo hello >/dev/pts/42
: the string hello
will be displayed on the other terminal. Now run cat /dev/pts/42
and type in the other terminal. To kill that cat
command (which will make the other terminal hard to use), press Ctrl+C.
Writing to another terminal is occasionally useful to display a notification; for example the write
command does that. Reading from another terminal is not normally done.
You need to add mount --make-rslave /mnt/"$i"
after your first mount command, to set the correct propagation flags for those mount points.
They protect the host from changes made inside the chroot environment, and help prevent blocking situations like yours.
Best Answer
Thanks to the comment by @mikeserv I've found out how to revive it.
I have only tested this on Linux 4.0.7, so for much earlier or much later versions it may not work.
Mounting a
devpts
filesystem in achroot
without using thenewinstance
option caused it to mount the same "instance" of/dev/pts
, containing the same ptys. Passing nogid
argument, according to the man page, causes new ptys to be created with the same gid as the process that spawned it. Apparently this (lack of) mount option affects the entiredevpts
instance, so the original/dev/pts
is no longer reassigning ptys to thetty
group. I still don't know why urxvt needs its ptys to be in that group while xterm doesn't.Some more notes on this:
/dev/pts/ptmx
has mode 000 (root:root) while/dev/ptmx
has mode 666 (root:tty). They do however point to the same block device, so settingptmxmode
seems unnecessary but harmless.mode
(600) seems to work, but the tty gets created with mode 620 anyway. Something might be changing its mode. When my system boots it passesmode=620
, overriding the defaultmode
, so I've put that in the command line above in the interest of better restoring the default functionality of /dev/pts.uid
. It will lead you either to security problems or to the same problem of terminals not spawning.newinstance
is optional, but can improve security. With this option, containers can't mount the "real"/dev/pts
because the host system isn't using it. If this is used, you should ensureptmxmode=666
and that/dev/ptmx
is a symlink topts/ptmx
. Mounting a newdevpts
instance over/dev/pts
may cause strange behaviours in existing terminals (e.g.gpg
not working), so you should restart those if you use this option.