Replacing getty with ngetty on Debian

This article was originally posted back in October 2013. As such, I’ve updated it, since the current Debian release, Debian 9, no longer uses init, but instead uses systemd. Systemd is a system and service manager for Linux. It is the default init system for Debian since Debian 8 (Jessie).  ngetty or mingetty may be useful for tiny cloud servers with < 1GB of memory, if you have no need for serial lines or if you prefer the way they can be configured. Feel free to send in your suggestions, comments or questions.

ngetty –  is a single-process getty replacement, so instead of running 6 getty processes consuming up to 2MB of memory each, you can instead use a single getty process using < 1MB total.

mingetty –  is a minimal getty for use on virtual consoles. Unlike the getty in the util-linux or mgetty packages, mingetty – like ngetty – is not suitable for serial lines, which is why it’s smaller.

 

ngetty (or mingetty) on Debian 8 and newer releases – systemd

getty

First login to your Debian box and run the below commands.
You may use ngetty if you prefer. I’m using mingetty below, because ngetty isn’t available in Debian 9 repositories, but available in Debian 8 and Debian SID.

# apt install mingetty

To tell debian to start using you the new getty, update the /sbin/getty symbolic-link to:

# cd /sbin
# rm getty
# ln -s mingetty getty

If in a cloud-based environment, you really shouldn’t care about multiple consoles, you should reduce the # of consoles to just 1. To do this, edit /etc/default/console-setup and replace:

ACTIVE_CONSOLES=/dev/tty[1-6]

with…

ACTIVE_CONSOLES=/dev/tty[1-1]

 

ngetty Debian 7 and older releases – init

Once you install ngetty: apt-get install ngetty, edit /etc/inittab. The end of it should be edited to look like this:

# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
#  <id>:<runlevels>:<action>:<process>
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
#1:2345:respawn:/sbin/getty 38400 tty1
#2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6
ng:2345:respawn:/sbin/ngetty 1 2 3 4 5 6

# Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

# Example how to put a getty on a modem line.
#
#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3

So basically commented out the 1 – 6 getty lines, then add

ng:2345:respawn:/sbin/ngetty 1 2 3 4 5 6

…which replaces the six getty lines.

I was stripping down a Debian 7 server for a client (back in 2013) and some of the steps were included here. However, there were no instructions for replacing getty with ngetty or mingetty on that Debian wiki page, so decided to write this brief guide. Debian has since added the section “Replace the getty processes with the ngetty single process daemon” to that page.

To avoid updates breaking your custom getty setup. You can use for example:

dpkg-divert --add /sbin/getty

 

Also read: Best Linux Distro 2019, for Desktop and/or Choosing the Best Linux Server Distro 2019.

 

Other getty replacement options

fgetty – very small, efficient, console-only getty and login.
mgetty – Smart Modem getty replacement.
rungetty – minimal console getty that can run any process.

Posted: October 11th 2013 | Last updated: May 31st 2019

Tags: , ,



Top ↑