3

I am trying to setup virtio-serial to communicate between a virtual machine and its host. For this, I am following the instructions given here:

I understand that there is a port on the host at tmp/foo on the host which is exposed as a special character device at /dev/hvc0 on the guest. The instruction manual asks to use socat on the host and agetty on the guest to spawn the console ports.

However, on using agetty, I do not get any console port, whereas, on using socat on the guest as well, I can communicate with the host.

I would like to know what are the primary differences between socat and agetty and whether this is the correct way to use socat, considering /dev/hvc0 is a special character device.

I have given a look at the manual pages of both and would like a detailed description.

1 Answer 1

4

Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them. Because the streams can be constructed from a large set of different types of data sinks and sources, and because lots of address options may be applied to the streams, socat can be used for many different purposes.nixCraft

socat can do serial line stuff, and it can do fairly advanced functionality, like having multiple clients listen on a port, or reusing connections. The life cycle of a socat instance typically consists of four phases.

  • In the init phase, the command line options are parsed and logging is initialized.
  • During the open phase, socat opens the first address and afterwards the second address. These steps are usually blocking; thus, especially for complex address types like socks, connection requests or authentication dialogs must be completed before the next step is started.
  • In the transfer phase, socat watches both streams' read and write file descriptors via select() , and, when data is available on one side and can be written to the other side, socat reads it, performs newline character conversions if required, and writes the data to the write file descriptor of the other stream, then continues waiting for more data in both directions.
  • When one of the streams effectively reaches EOF, the closing phase begins. Socat transfers the EOF condition to the other stream, it tries to shutdown only its write stream, giving it a chance to terminate gracefully. For a defined time socat continues to transfer data in the other direction, but then closes all remaining channels and terminates.

agetty opens a tty port, prompts for a login name and invokes the /bin/login command. It is normally invoked by init(8). agetty has several non-standard features that are useful for hard-wired and for dial-in lines:ManPage

  • Adapts the tty settings to parity bits and to erase, kill, end-of-line and uppercase characters when it reads a login name. The program can handle 7-bit characters with even, odd, none or space parity, and 8-bit characters with no parity. The following special characters are recognized: @ and Control-U (kill); #, DEL and back space (erase); carriage return and line feed (end of line).
  • Optionally deduces the baud rate from the CONNECT messages produced by Hayes(tm)-compatible modems.
  • Optionally does not hang up when it is given an already opened line (useful for call-back applications).
  • Optionally does not display the contents of the /etc/issue file.
  • Optionally displays an alternative issue file instead of /etc/issue.
  • Optionally does not ask for a login name.
  • Optionally invokes a non-standard login program instead of /bin/login.
  • Optionally turns on hard-ware flow control
  • Optionally forces the line to be local with no need for carrier detect.
  • Supports ringback, if desired. The actual procedure that getty uses is as follows: Initially, getty parses its command line. If no errors are found, and the tty type from the command line is set to "unknown" (the default value), or not set, getty checks for the tty type in /etc/ttytype if the program was compiled with TTYTYPE defined. If a tty type is found, either on the command line or in the /etc/ttytype file, then it is placed into the TERM environment variable. Next, getty scans the defaults file, normally /etc/default/getty, to determine certain runtime values (/etc/conf.getty if compiled with FSSTND option). The values in the defaults file (whose compiled-in name can be altered with the optional -d defaults_file argument) take precedence to those on the command line. Getty then opens the port for reading and writing, and disables stdio buffering. If an initialization was specified, it is performed.

Extra Sources: Socat, agetty MP

6
  • I would appreciate a more detailed explaination, Mitch.
    – jobin
    Jan 24, 2014 at 7:11
  • I have an important task to finish at work, but I will.
    – Mitch
    Jan 24, 2014 at 17:11
  • I have added more detail. I hope that's sufficient enough.
    – Mitch
    Jan 29, 2014 at 7:53
  • Let me know if this explanation is sufficient. Thanks
    – Mitch
    Jan 31, 2014 at 6:33
  • I am afraid I do not get a console to login when I am using socat to communicate between the host and a guest virtual machine, which I don't think are socks address. Can you please explain why this is happening or am I doing something wrong?
    – jobin
    Jan 31, 2014 at 7:57

You must log in to answer this question.

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