I've got instruments hooked up to /dev/ttyS1 through ttyS9 on a machine running Debian Wheezy. The various instruments communicate at various speeds.

Is there a better way to set the baud rates than to have a bunch of lines like

stty -F /dev/ttyS1 19200 raw -echo
stty -F /dev/ttyS2 4800  raw -echo

in rc.local?

  • The kernel drivers might understand some kernel command line parameters, which you could use by default. Depends on the hardware (read driver), I guess.
    – peterph
    Sep 19, 2013 at 20:01
  • @peterph yeah, but /etc/rc.local seems way more elegant than to screw with the kernel command line. I agree with slm, /etc/rc.local is fine. Sep 19, 2013 at 20:54

3 Answers 3


Install the setserial package. It can save serial port settings and restore them at boot time.

Alternatively, run a program when the port is detected via an udev rule. Put something like this (untested) in /etc/udev/rules.d/zzz_serial.rules:

KERNEL=="ttyS1", RUN+="/bin/stty -F /dev/ttyS1 19200 raw -echo"
  • When using RUN commands, you need to specify the full path, in this case /bin/stty. Otherwise you'll end up with : failed to execute '/lib/udev/stty' No such file or directory. Jul 8, 2015 at 20:13

Not to my knowledge.

The /etc/rc.local file is the best location for creating customization that are specific to the box. It was specifically created for these types of custom changes and is the first place that most system administrators are conditioned to look when dealing with Unix/Linux boxes.

  • One might also create a separate script for that, that will be sourced/executed from within /etc/rc.local
    – peterph
    Sep 19, 2013 at 21:41
  • @peterph - excellent point, yes if it's more elaborate, you might want to source a script with the contents of these commands in them instead.
    – slm
    Sep 19, 2013 at 21:54

The setserial package will restore the serial settings at boot time. Once installed, simply edit the file /var/lib/setserial/autoserial.conf

# If you want to configure this file by hand, use
# dpkg-reconfigure setserial
# and change the configuration mode of the file to MANUAL. 
# If you do not do this, this file may be overwritten automatically the next 
# time you upgrade the package
/dev/ttyS0 uart 16550A port 0x03f8 irq 4 baud_base 115200 spd_normal skip_test
/dev/ttyS1 uart 16550A port 0x02f8 irq 3 baud_base 115200 spd_normal skip_test
/dev/ttyS2 uart 16550A port 0x03e8 irq 0 baud_base 115200 spd_normal skip_test
/dev/ttyS3 uart 16550A port 0x02e8 irq 0 baud_base 115200 spd_normal skip_test
/dev/ttyS4 uart 16550A port 0x02d0 irq 0 baud_base 115200 spd_normal skip_test
/dev/ttyS5 uart 16550A port 0x02c0 irq 0 baud_base 115200 spd_normal skip_test

From my experience, modifying the file directly is ok, even though the comments in the file say otherwise. You can also use setserial 'interactively', by moving the line ###AUTOSAVE-ONCE### at the top of the file. Then calling setserial as many times as needed until you're satisfied with the configuration. Rebooting the machine at that point will save the latest configuration into /setserial/autoserial.conf.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .