robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2541
Posted: 10:40am 06 Jan 2025
it will only find ports that are associated with actual hardware - i would be surprised if a motherboard had four onboard serial ports without there being any visible DB9 sockets on the back, or any 2x5 pin headers internally.
the Linux kernel creates the ttySxx entries in /dev, /sys/class/tty and /sys/devices/platform/serial8250/tty without doing any checking that there is real serial port hardware present.
the actual number of ttySxx entries created is hard-coded in the kernel. 32 is a common number, as is 16 and, it would seem 4. the actually number is dependent on whims of the person compiling the kernel!
for instance, on a VM (Linux Mint 19.3 i686, kernel 5.4.0-89-generic) i have here that has no serial ports available to it, one finds:
from the above you can see that in both cases there are 32 ttySxx entries, and also that with kernel 6.8 there is no /sys/devices/platform/serial8250/tty directory - this is because the 6.8 kernel uses a different /sys/devices/ directory layout and file naming convention to earlier kernels.