How to limit number of tty in systemd

systemd, tty

Solution

This is related to the following two settings in the kernel configuration (source):

$ zgrep CONFIG_LEGACY_PTY /proc/config.gz 
CONFIG_LEGACY_PTYS=y
CONFIG_LEGACY_PTY_COUNT=256

I was observing this behavior on a Cubietruck, where apparently this number of legacy PTYs is configured. Thanks to `systemd-analyze plot` I had noticed this as being a major factor in delaying the boot on my device.

Turns out there is a kernel command line option which can restrict the number dynamically:

pty.legacy_count=N

(where `N` is the number you want set)

For me this meant to add a line like this:

extraargs=pty.legacy_count=6

... to `/boot/armbianEnv.txt` (further options can be added, separated by spaces; just do not enclose the right side of the first `=` in double quotes!).

After that I ran:

mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr

... because I was unsure whether the `armbianEnv.txt` gets "compiled" into the script image. I don't think so, but I didn't want to waste any time.

Anyway, a quick look with:

systemctl |grep virtual-tty|wc -l

... confirms that there are now just 6 of those legacy PTYs.

Depending on your particular device the whole setting could also be in the form of `GRUB_CMDLINE_LINUX` (or `GRUB_CMDLINE_LINUX_DEFAULT`) in `/etc/default/grub` or where ever GRUB stores its configuration for your distro (don't forget to `update-grub` after your changes).

Problem

If I run `systemctl` I get a lot of ttys (see above). Is there any way to limit this number and so save some memory because obviously I will not need this bunch of tty never. ``` sys-devices-virtual-tty-ttya0.device loaded active plugged /sys/devices/virtual/tty/ttya0 [...] sys-devices-virtual-tty-ttyzf.device loaded active plugged /sys/devices/virtual/tty/ttyzf ```

Original source