8

I've created a Debian-based chroot environment using debootstrap under Arch Linux, and fill it with life like this:

#!/bin/sh

mount -t proc proc $CHROOT/proc
mount -t devpts devpts $CHROOT/dev/pts

chroot $CHROOT /bin/bash --login -c "/etc/init.d/ssh start"

The problem is that after executing the script above, I'm not able to open new terminals on the host system anymore:

urxvt: can't initialize pseudo-tty, aborting.

Shutting down the chroot (stopping sshd, unmounting proc and dev/pts) does not bring back new terminals on the host.

What am I missing here?

Anthon
  • 78,313
  • 42
  • 165
  • 222
lynix
  • 83
  • 1
  • 3
  • 1
    Please post the output of `ls -l /dev/pts` before and after. Stab in the dark: is `mount --bind /dev/pts $CHROOT/dev/pts` any better? You'll probably save a lot of effort by using [schroot](https://wiki.archlinux.org/index.php?title=Schroot&redirect=no) instead of building your own. – Gilles 'SO- stop being evil' Sep 11 '13 at 23:33
  • `mount --bind` did the trick, thanks! ;) Outputs of `ls -l /dev/pts` did not differ. – lynix Sep 13 '13 at 12:48

1 Answers1

5

When you run mount -t devpts devpts $CHROOT/dev/pts, this mounts a separate instance of the devpts filesystem in the chroot. An alternative way of making devpts available in the chroot is to use a bind mount, which makes the same instance of the filesystem available at a new location. Bind mounts are like making a hard link, only for mount points instead of files.

mount --bind /dev/pts "$CHROOT"/dev/pts

Separate instances of devpts shares the same files (if you create or remove a terminal or change its metadata, it's reflected in all instances). However there is evidently some difference under the hood which makes it not work. A bind mount ensures that everything that needs to be synchronized is synchronized since it's the same filesystem and not merely an identical one.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 1
    I just had the opposite problem with a Debian chroot running on QNAP's QTS Linux-based OS. I'd used a bind mount which caused screen to fail and switching to a devpts mount instead fixed it. – markshep Apr 21 '16 at 21:24
  • I tried the bind mount and then mounting -t devpts - both go wrong in some cases. – Florian Heigl May 26 '22 at 23:37