How to get fewer ttys with Systemd?

In the old days I just modified /etc/inittab. Now, with systemd, it seems to start tty[1-6] automatically, how should I disable tty[4-6]?

Looks like there’s only one systemd service file, and it use a %I to discern different tty sessions. I hope I don’t need to remove that service, and create each [email protected] manually.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There is no real need to disable “extra” TTYs as under systemd gettys are generated on demand: see man systemd-getty-generator for details. Note that, by default, this automatic spawning is done for the VTs up to VT6 only (to mimic traditonal Linux systems).

As Lennart says in a blog post1:

In order to make things more efficient login prompts are now started on demand only. As you switch to the VTs the getty service is instantiated to [email protected], [email protected] and so on. Since we don’t have to unconditionally start the getty processes anymore this allows us to save a bit of resources, and makes start-up a bit faster.

If you do wish to configure a specific number of gettys, you can, just modify logind.conf with the appropriate entry, in this example 3:

NAutoVTs=3

1. In fact the entire series of posts—currently numbering 18— systemd for Administrators, is well worth reading.

Method 2

On Debian-based systems, there is a file that causes 5 extra getty’s to be launched on startup if you’ve just built a server (without dbus service):

/lib/systemd/system/getty.target.wants/getty-static.service

In it, it says:

[Service]
Type=oneshot
ExecStart=/bin/systemctl --no-block start <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5828091919ca591919cd7cb968097938c8680">[email protected]</a> <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30575544444970444449031e43554246595355">[email protected]</a> <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ee9ebfafaf7cefafaf7baa0fdebfcf8e7edeb">[email protected]</a> <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cfbf9e8e8e5dce8e8e5a9b2eff9eeeaf5fff9">[email protected]</a> <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bed9dbcacac7fecacac78890cddbccc8d7dddb">[email protected]</a>
RemainAfterExit=true

Just deleting this file will stop the extra getty’s from spawning. Feel free to shorten the list if you want to just spawn one extra getty (for 2 virt consoles). Note that you automatically get one on tty1 so you always have at least one virtual console.

See also: systemd-logind.service fails to start if dbus is missing

Method 3

To disable gettys on particular TTYs 4-6 while possibly leaving 1-3 and 7-9 working, run:

for i in {4..6}; do
  systemctl mask <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65020011111c2511111c">[email protected]</a>${i}.service
done

mask creates symlink /etc/systemd/system/{name} -> /dev/null which effectively disables service. Attempt to run it via systemctl start will display error Failed to start NAME.service: Unit NAME.service is masked.

If you have A.service Wants=masked.service, then start A will succeed but also generate dependency start error in journal.

If you have B.service Requires=masked.service, then start B will also fail.

Yup, necroanswer. Cheers.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x