Gentoo image; ttys die

I have been trying to use the gentoo/current image on a gentoo host system. I would like to have virtual consoles. Init is spawing them, but for some reason they die.

After starting the container, this is what I see inside:

$ lxc exec gentooC03 /bin/bash
gentooC03 ~ # ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 13:30 ? 00:00:00 init [3]
root 614 1 0 13:30 ? 00:00:00 /bin/busybox udhcpc -x hostname:gentooC03 --interface=et
root 686 0 0 13:30 ? 00:00:00 /bin/bash
root 705 1 0 13:30 ? 00:00:00 /sbin/agetty 38400 tty1 linux
root 706 1 0 13:30 ? 00:00:00 /sbin/agetty 38400 tty2 linux
root 707 1 0 13:30 ? 00:00:00 /sbin/agetty 38400 tty3 linux
root 708 1 0 13:30 ? 00:00:00 /sbin/agetty 38400 tty4 linux
root 709 1 0 13:30 ? 00:00:00 /sbin/agetty 38400 tty5 linux
root 710 1 0 13:30 ? 00:00:00 /sbin/agetty 38400 tty6 linux
root 711 686 0 13:30 ? 00:00:00 ps -ef

The ttys keep respawning.

In the container console, I see eventually see this:

$ lxc console gentooC03
To detach from the console, press: +a q
INIT: Id “c6” respawning too fast: disabled for 5 minutes
INIT: Id “c4” respawning too fast: disabled for 5 minutes
INIT: Id “c2” respawning too fast: disabled for 5 minutes
INIT: Id “c3” respawning too fast: disabled for 5 minutes
INIT: Id “c1” respawning too fast: disabled for 5 minutes
INIT: Id “c5” respawning too fast: disabled for 5 minutes
INIT: no more processes left in this runlevel
INIT: Id “c6” respawning too fast: disabled for 5 minutes
INIT: Id “c2” respawning too fast: disabled for 5 minutes
INIT: Id “c1” respawning too fast: disabled for 5 minutes
INIT: Id “c5” respawning too fast: disabled for 5 minutes
INIT: Id “c3” respawning too fast: disabled for 5 minutes
INIT: Id “c4” respawning too fast: disabled for 5 minutes

The tty processes disappear from ps output:

gentooC03 ~ # ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 13:30 ? 00:00:00 init [3]
root 614 1 0 13:30 ? 00:00:00 /bin/busybox udhcpc -x hostname:gentooC03 --interface=et
root 686 0 0 13:30 ? 00:00:00 /bin/bash
root 731 1 0 13:31 ? 00:00:00 /sbin/agetty 38400 tty4 linux
root 732 1 0 13:31 ? 00:00:00 /sbin/agetty 38400 tty6 linux
root 733 1 0 13:31 ? 00:00:00 /sbin/agetty 38400 tty5 linux
root 734 1 0 13:31 ? 00:00:00 /sbin/agetty 38400 tty3 linux
root 735 1 0 13:31 ? 00:00:00 /sbin/agetty 38400 tty2 linux
root 736 1 0 13:31 ? 00:00:00 /sbin/agetty 38400 tty1 linux
root 737 686 0 13:31 ? 00:00:00 ps -ef
gentooC03 ~ # ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 13:30 ? 00:00:00 init [3]
root 614 1 0 13:30 ? 00:00:00 /bin/busybox udhcpc -x hostname:gentooC03 --interface=et
root 686 0 0 13:30 ? 00:00:00 /bin/bash
root 828 686 0 13:39 ? 00:00:00 ps -ef

Do you have any ideas what might be going wrong here?

LXD only sets up a single console at /dev/console, the /dev/ttyX devices don’t exist at all, so it’s impossible for getty to ever succeed on those.

I’d normally expect our images to have code in place to avoid such waste of CPU time.

If you’re using a stock image and are getting this behavior out of the box, then @monstermunchkin should be able to figure out the right change to our images to prevent Gentoo from spawning those getty instances.

1 Like

Hi Stéphane,

Is that single console hard coded? How can I set up more virtual consoles?

Yes, LXD only provides a single console which is used for /dev/console, accessing that interactive console is also relatively new and not something we normally would expect our users to use much unless debugging boot issues.

We expect the vast majority of interactions to be through lxc exec instead which supports an unlimited number of sessions. Getting an interactive login prompt through it can be done with lxc exec NAME login.

We need to modify the /etc/inittab to prevent TTYs from being created. This PR should fix the issue.

1 Like

Great, thanks. Does this mean that the automatically generated images are no longer affected as of the point of the merge into master?

That is correct. Enjoy the new Gentoo image :slight_smile:

Ok, it works – mostly.

When I log in as root, I get the following output:

gentooC04 login: root
Password:
Last login: Thu Jul 4 11:35:32 -00 2019 on console
-bash: cannot set terminal process group (875): Inappropriate ioctl for device
-bash: no job control in this shell

Based on this I presume that either bash is being invoked non-interactively, or that /dev/console is not behaving like a real tty.

I tried doing a stack trace from outside the container. The relevant bit of the stack trace for ‘-bash’ looks like this:

execve("/bin/bash", ["-bash"], 0x55690600a2b0 /* 8 vars /) = 0
brk(NULL) = 0x5562baa17000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, “/etc/ld.so.cache”, O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=22049, …}) = 0
mmap(NULL, 22049, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f52f3f59000
close(3) = 0
openat(AT_FDCWD, “/lib64/libreadline.so.7”, O_RDONLY|O_CLOEXEC) = 3
read(3, “\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360l\1\0\0\0\0\0”…, 832) = 832
fstat(3, {st_mode=S_IFREG|0555, st_size=308888, …}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f52f3f57000
mmap(NULL, 2409704, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f52f3d0a000
mprotect(0x7f52f3d4d000, 2097152, PROT_NONE) = 0
mmap(0x7f52f3f4d000, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x43000) = 0x7f52f3f4d000
mmap(0x7f52f3f55000, 5352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f52f3f55000
close(3) = 0
openat(AT_FDCWD, “/lib64/libc.so.6”, O_RDONLY|O_CLOEXEC) = 3
read(3, “\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p?\2\0\0\0\0\0”…, 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1885656, …}) = 0
mmap(NULL, 1898344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f52f3b3a000
mprotect(0x7f52f3b5c000, 1720320, PROT_NONE) = 0
mmap(0x7f52f3b5c000, 1417216, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f52f3b5c000
mmap(0x7f52f3cb6000, 299008, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17c000) = 0x7f52f3cb6000
mmap(0x7f52f3d00000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c5000) = 0x7f52f3d00000
mmap(0x7f52f3d06000, 14184, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f52f3d06000
close(3) = 0
…skipping…
getpgrp() = 905
dup(2) = 3
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=4
1024}) = 0
fcntl(255, F_GETFD) = -1 EBADF (Bad file descriptor)
dup2(3, 255) = 255
close(3) = 0
ioctl(255, TIOCGPGRP, 0x7fff8f9e4644) = -1 ENOTTY (Inappropriate ioctl for device)
getpid() = 906
setpgid(0, 906) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD TSTP TTIN TTOU], [], 8) = 0
ioctl(255, TIOCSPGRP, [906]) = -1 ENOTTY (Inappropriate ioctl for device)
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
setpgid(0, 905) = 0
fstat(2, {st_mode=S_IFCHR|0600, st_rdev=makedev(0x88, 0), …}) = 0
write(2, “-bash: cannot set terminal proce”…, 79) = 79
write(2, “-bash: no job control in this sh”…, 36) = 36
fcntl(255, F_SETFD, FD_CLOEXEC) = 0
rt_sigaction(SIGCHLD, {sa_handler=0x5562b920b730, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f52f3b730d0}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f52f3b730d0}, 8) = 0
ioctl(255, TIOCGPGRP, 0x7fff8f9e4624) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(255, TCGETS, {B38400 opost isig icanon echo …}) = 0
prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=31556, rlim_max=31556}) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
ioctl(255, TIOCGPGRP, 0x7fff8f9e4764) = -1 ENOTTY (Inappropriate ioctl for device)
openat(AT_FDCWD, “/etc/profile”, O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1661, …}) = 0
read(3, “# /etc/profile: login shell setu”…, 1661) = 1661
close(3) = 0

Is there any way to fix this? (I did find this: https://unix.stackexchange.com/questions/382747/should-i-try-to-get-rid-of-inappropriate-ioctl-for-device-in-strace-output-for )