Serial port in VirtualBox

While installing Solaris on VirtualBox on Linux host, I was slightly annoyed by the graphical interface. I had to go out of my screen session, use mouse, click the virtual machine window, let it steal the input and then press right ctrl key to go out, and use mouse again to go back to my screen session.

Solaris x86 supports installation over a serial port. Why not use it?

VirtualBox supports attaching a serial device to a guest machine. By default, serial ports are disabled. If you go to the details tab, and see ‘Serial Ports’, you can click it and get a dialog box. Enable serial port COM1 (IRQ 4 I/O port 0x3F8). There are two port modes. One of them is ‘Host Device’. It would be very nice to use it, but VirtualBox run as a normal user lacks permissions to create devices. The other option is ‘Host Pipe’. Normal user permssions are sufficient to create a pipe, but when you run VirtualBox and examine the file type, you’ll find out that what has been actually created is a unix domain socket rather than a pipe.

How do you access serial port exposed as a socket? Use socat!

I’ve worked out two ways of accessing the serial port: by converting to TCP and by converting to a pty (pseudo teletype device). First, TCP solution. Let’s say, that the path to the socket is “/tmp/foo-socket”. We’ll use socat to convert it to a TCP server.

socat UNIX-CONNECT:/tmp/foo-socket TCP-LISTEN:8040

This command shouldn’t return to prompt. If it does, your serial port device on the guest virtual machine isn’t ready yet. If it doesn’t return, go to a different terminal window and type:

telnet localhost 8040

Voila! Another solution is to create a pty.

socat UNIX-CONNECT:/tmp/foo-socket PTY,link=/tmp/foo-pty

…and on another terminal:

screen /tmp/foo-pty

If socat returns immediately, it means your guest system doesn’t use the serial port at the moment. If you’re installing Solaris 10, you’ll have to select a serial port (ttya) installation mode first, in the bootloader.

Tags: ,

9 Responses to “Serial port in VirtualBox”

  1. Fat Bloke Says:


    Your issues with the mouse will go away if you install the Guest Additions into the Solaris guest.


  2. carton Says:

    I found this has two problems. First, it’s impossible to capture the first few boot messages because you cannot start ‘socat’ and ‘screen’ until after you’ve started the VM. Second, the messages VirtualBox emits before anything is attached to the socket will *loop back* and be treated as input (why?!). I fixed both problems by modifying your invention very slightly:

    VBoxManage modifyvm “gentoo 64bit” –uartmode1 client /home/guest/gentoo64-console
    VBoxManage modifyvm “gentoo 64bit” –uart1 0x3f8 4
    socat PTY,link=/home/guest/gentoo64-pty UNIX-LISTEN:/home/guest/gentoo64-console &
    screen /home/guest/gentoo64-pty
    [c-a c-d to detach from screen]
    nohup bash -c ‘VBoxHeadless -s “gentoo 64bit” -v on > vbox.out 2>&1 &’
    screen -d -r

    The modifications are: VirtualBox in client mode instead of server mode, socat in UNIX-LISTEN mode instead of UNIX-CONNECT mode, and give socat the PTY argument first (because it opens the first argument, then the second, and opening the LISTEN socket blocks until something connects to it).

    An analagous tweak lets you see the first few messages of a booting zone. This was given in some blog post about zone cloning:

    zoneadm -z thezone ready
    zlogin -C thezone
    [in another window] zoneadm -z thezone boot

    Anyway this is much better than rdesktop if you are a sneaker-wearing douchebag in a cafe doing sa work over wifi or cdma. also it lets you log the messages. and with a little more goo it might even be scriptable. Thank you for this. here’s hoping the PHP blogware will not corrupt all my ampersands and greater-than’s. [submit!]

  3. carton Says:

    oh my god. utf8 quotes, justified text, indentation-trimming. It is not right we are using this kind of software to discuss technical things. Why are we still putting up with this? Why would a programmer, who wrote wordpress to begin with, deliver soemthing like this? I guess PHP developers do not indent their code at all, or distinguish one kind of quote from another. could be worse, though.

  4. Cameron Kerr Says:

    Hi, I found this post some years ago and have since found it occassionally useful. However, in the last while (at least a year or so), I find that the output is very unreliable, to such an extent that you can’t do a serial-terminal install anymore. I’m not sure yet if this is my Linux guest (tried recent Ubuntu, Debian and Redhat), VirtualBox (numerous 3.2.x series), Mac OS X 10.5/10.6 host or socat.

    Have you any recent success using this technique?

  5. user Says:

    If you want to avoid using screen, simply run:

    socat UNIX-CONNECT:/tmp/foo-socket STDIO,raw,echo=0

  6. jedreynolds Says:

    Reblogged this on Bitratchet and commented:
    Don’t forget about “socat”. Pretty handy for those VM serial ports!

  7. nass Says:

    hi there. it is not clear HOW you start the virtual machine on virtualbox.I presume you start it first. Do you choose “Host pipe” and give the location: “/tmp/foo-socket” ? Because when I do and I try to start the vm, it whine’s that it can’t find /tmp/foo-socket! Thanks

  8. automatthias Says:

    Hi nass, I’ve written a separate post about headless VirtualBox setup:

  9. aroha Says:

    Great article! Thanks. I used the TCP approach to access the Android console running in VBox.

Comments are closed.

%d bloggers like this: