Get two Linux (virtual) boxes talking over the serial port

What is the best way to configure a single Linux block to listen on its serial port for incoming connections? I have done a lot of searches, but I can’t find the right combination of commands to make them speak!

My main goal is to provide a consistent interface for running instances of kvm / qemu virtual machines. Currently they only have a VNC interface (they are on mute servers, without X). I can force the virtual machine to create a serial device by running it with the -serial file: flag, but how to talk to it is another problem. Both boxes work with Ubuntu 8.04.

+4
source share
3 answers

The Linux Serial HOWTO contains a lot of detailed information about serial communication in general. The more specific Linux Remote Serial Console HOWTO is what you are really looking for if you want to be able to log into your virtualized systems using the serial port, as if you were on the console. As Hein pointed out, you need a null modem cable and you need to run the minicomputer on the remote terminal.

The Linux console is used in two ways, each of which must be configured separately for sequential use. You can configure the kernel to copy your messages through the serial port, which is sometimes interesting to observe when the system boots and is almost indispensable if you are debugging the kernel. (This requires kernel support and updating boot parameters, so the kernel knows that you need serial output, see chapter 5 of the second). you are probably more interested in entering through the serial port, which requires running getty on the serial port after booting (just like your system already runs getty on virtual terminals after booting), which is described in detail in Chapter 6 .

+5
source

I assume that you are connecting two serial ports using a null modem cable.

Use a program such as minicom to talk to a remote system - you probably need to configure communication settings and possibly turn off hardware flow control (if your cable does not have flow control lines connected).

0
source

Say you are doing this on / dev / tty 1.

in the shell

chown *youruser* /dev/tty1 

and then in a Perl script called example.pl

 open PORT, "</dev/tty1" || die "Can't open port: $!"; while (defined ($_ = <PORT>)) { do_something($_); } close PORT; 

Obviously, you need to do more if you want it to start automatically, and reborn on error, and so on. But the main idea is to read from the serial port as a file.

0
source

Source: https://habr.com/ru/post/1276729/


All Articles