Some days ago I needed to connect two virtual machines with a virtual serial cable on a Linux KVM host. Interestingly it seems that there is no straight forward way for doing this, but here is a nice little workaround, using unix domain sockets. If you are using libvrit and virsh, you can add something like the following to your vm’s configuration:

1
2
3
4
5
6
7
<serial type='unix'>
    <source mode='bind' path='/var/run/libvirt/vm1-serial.sock'/>
    <target type='isa-serial' port='0'>
    <model name='isa-serial'/>
    </target>
    <alias name='serial0'/>
</serial>

After that you can use a program called socat to connect two unix domain sockets:

# socat UNIX-CLIENT:/var/run/libvirt/vm1-serial.sock UNIX_CLIENT:/var/run/libvirt/vm2-serial.sock

To connect to a serial unix domain socket from the host system, use minicom:

$ minicom -D unix\#/var/run/libvirt/vm1-serial.sock