From LedHed's Wiki
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 10: Line 10:
 
== Instructions ==
 
== Instructions ==
  
To redirect a Linux Console to a serial port edit /etc/inittab
+
To redirect a Linux Console to a serial port edit /etc/inittab and add this line at the end of the '# Run gettys in standard runlevels' section.
  
  6:12345:respawn /usr/sbin/agetty -hL ttyS0 38400 vt100
+
  S0:2345:respawn /usr/sbin/agetty -h ttyS0 38400 vt100
  
 
When done issue this command to make the changes take effect:
 
When done issue this command to make the changes take effect:
Line 27: Line 27:
  
 
== General Notes ==
 
== General Notes ==
1) There will most likely already be a 6:12345, if that is the case comment out the old 6:12345 with a # like this #6:12345.<br>
+
1) In this HowTo I used 'agetty' but there are other getty packages such as 'getty', 'mgetty', and 'mingetty' use whichever is the default on your distribution. If you use one of the other getty packages keep in mind that the syntax will most likely be different.<br>
2) I prefer to redirect TTY6 so that if I do login locally TTY1 (the default console) is available.<br>
+
2) ttyS0 = COM1, ttyS1 = COM2 etc...
3) In this HowTo I used 'agetty' but there are other getty packages such as 'getty', 'mgetty', and 'mingetty' use whichever is the default on your distribution. If you use one of the other getty packages keep in mind that the syntax will most likely be different.<br>
+
 
 +
 
 +
 
 +
==Modern Distros using Systemd==
 +
If you're on a distro that uses systemd, here is another method (in this case Ubuntu 22.04):
 +
 
 +
cat <<EOF > /lib/systemd/system/ttyS0.service
 +
[Unit]
 +
Description=Serial Console Service
 +
 +
[Service]
 +
ExecStart=/sbin/getty -L 115200 ttyS0 vt102
 +
Restart=always
 +
 +
[Install]
 +
WantedBy=multi-user.target
 +
EOF
 +
 
 +
Then reload, enable, and start the service
 +
systemctl daemon-reload
 +
systemctl enable ttyS0
 +
systemctl start ttyS0
  
  
Line 37: Line 58:
 
[http://www.linuxjournal.com/article/2040 Linux Journal - Serial as a Console]<br>
 
[http://www.linuxjournal.com/article/2040 Linux Journal - Serial as a Console]<br>
 
[http://www.netadmintools.com/html/5inittab.man.html inittab Man Pages]<br>
 
[http://www.netadmintools.com/html/5inittab.man.html inittab Man Pages]<br>
[http://www.netadmintools.com/html/8agetty.man.html agetty Man Pages]<br>
+
[http://www.netadmintools.com/html/8agetty.man.html agetty Man Pages]
 +
<br>
 +
[https://ubuntuforums.org/showthread.php?t=2343595 Serial Console connection on Ubuntu 16.04 or higher]
 +
 
  
  

Latest revision as of 15:01, 8 June 2022

Serial Console HowTo

Overview

Sometimes it is handy to be able to redirect a TTY Console to a serial port. One such example might be that your server is headless (No VGA, Keyboard, or Monitor) The info on this page will help you enable console access via a serial port.


Instructions

To redirect a Linux Console to a serial port edit /etc/inittab and add this line at the end of the '# Run gettys in standard runlevels' section.

S0:2345:respawn /usr/sbin/agetty -h ttyS0 38400 vt100

When done issue this command to make the changes take effect:

init q


Explanation

TTY-ID:RUN-LEVELS:respawn COMMAND -SWITCHES PORT TERMINAL-EMULATION (For greater detail on inittab or agetty see the References Section below)


General Notes

1) In this HowTo I used 'agetty' but there are other getty packages such as 'getty', 'mgetty', and 'mingetty' use whichever is the default on your distribution. If you use one of the other getty packages keep in mind that the syntax will most likely be different.
2) ttyS0 = COM1, ttyS1 = COM2 etc...


Modern Distros using Systemd

If you're on a distro that uses systemd, here is another method (in this case Ubuntu 22.04):

cat <<EOF > /lib/systemd/system/ttyS0.service
[Unit]
Description=Serial Console Service

[Service]
ExecStart=/sbin/getty -L 115200 ttyS0 vt102
Restart=always

[Install]
WantedBy=multi-user.target
EOF

Then reload, enable, and start the service

systemctl daemon-reload
systemctl enable ttyS0
systemctl start ttyS0


References

Linux Serial Console HowTo
Linux Journal - Serial as a Console
inittab Man Pages
agetty Man Pages
Serial Console connection on Ubuntu 16.04 or higher