Change the number of generated /dev/tty devices

5,764

I'm not sure exactly how the device nodes are created (i.e. the exact sequence of events that lead to their creation), but I'm pretty sure the kernel creates the underlying devices for the 63 /dev/ttyN devices (plus /dev/tty) internally, and udev does the work of making them available inside /dev (except for /dev/tty and /dev/tty1 which are created by /etc/init.d/udev-mount with mknod).

I don't think you can limit the number of kernel devices via configuration.

Here is a workaround if you want to limit the number of devices that appear in your /dev though. Create a /etc/udev/rules.d/99-my-tty-rules.rules file and put something like the following in it:

KERNEL=="tty[2-9][0-9]", RUN="/bin/rm /dev/%k", OPTIONS+="ignore_device"

This will get rid of tty device files numbered 20 and above.

Notes:

  • Using rm in there looks really strange, but I can't find a way to not create the node in the first place
  • Playing with these entries a bit too enthusiastically can lead to interesting problems - use with caution.
Share:
5,764

Related videos on Youtube

Rob van Wijk
Author by

Rob van Wijk

Updated on September 18, 2022

Comments

  • Rob van Wijk
    Rob van Wijk over 1 year

    I'm building an embedded Linux system, based on Gentoo. Using udev, all tty devices are probed with a PROGRAM stanza to determine if they are a modem.

    Right now the system boots up with 64 /dev/tty*. When udev probes the tty devices, the system runs out of memory.

    How can I reduce the number of produced tty devices to 4? Is this an OS setting or a kernel setting?

  • Rob van Wijk
    Rob van Wijk over 12 years
    Does ignore_device prevent future rules? If so, I could just put a rule without the rm in a file named 01-my-tty-rules.rules to prevent further processing (and node creation).
  • Mat
    Mat over 12 years
    I'm not sure actually, I thought it was more of an "ignore future events related to this device" thing. Worth a shot though. Edit: that doesn't seem to work, I get the ttyXX devices recreated when trying that and restarting udev.