I’m running Ubuntu 12.04 as host, with VirtualBox 4.2.22. This tutorial should cover guests including Windows XP, CentOS and Ubuntu.
1. Settings in VirtualBox
In the settings page, Check “Enable Serial Port”, set “Port Number” to “COM1”. This is the port number in the guest. If the guest is a Linux, COM1 is shown as /dev/ttyS0
, and COM2 is shown as /dev/ttyS1
.
Set “Port Mode” to “Host Pipe”, check “Create Pipe” and set “Port/File Path” to “/tmp/vbox”. Seems it utilizes a named pipe. These settings work even if the host does not have a physical serial device.
2. Install minicom
The second command setups minicom
with an interactive menu. Select “Serial port setup”, and set “Serial Device” as “unix#/tmp/vbox”(without quotes). “Save setup as dfl” and “Exit from Minicom”.
3. Verity the serial device in guest
Now boot your Linux guest. Run the following command, and it should output something like:
The guest here is CentOS5, and the serial device is /dev/ttyS0
.
4. Communication via serial device
Start minicom
on your host:
Echo something from your guest and redirect to /dev/ttyS0
. You host should get the message in minicom
.
To read from the host, cat the device in guest so that you can do the input in minicom
:
5. Kernel configuration
CentOS5 comes with grub1, /etc/grub.conf
is modified directly to allow the boot information to also be sent to our serial device. The original boot entry looks like:
Change to add console=
parameter:
That’s all for CentOS 5/6. There’s no need to modify /etc/inittab
or /etc/securetty
file as required in ArchLinux. These OS will do it for you.
Now, reboot your guest CentOS. The boot information should now displayed in your minicom
. Finally, it will provide you with a login shell.
You can verify that there’s a new line added into /etc/inittab
to enable getty(8) and execute a login shell:
And ttyS0
is also added into /etc/securetty
.
6. Ubuntu guest settings
Ubuntu 12.04 come with grub2. We do not modify /boot/grub/grub.cfg
, we modify /etc/default/grub
instead, so that the serial console parameters will remain even after you update your kernel. Open it, modify the following line to:
And update grub:
One additional step for Ubuntu, is to enable getty(8) for serial console by your own. Ubuntu uses upstart init system, we need to create a file called /etc/init/ttyS0.conf
containing the following:
Reboot you Ubuntu guest, and the serial device should work as it is with CentOS. More info, please refer to the official wiki.
7. Windows guest settings
The serial device shows as COM1 in Windows XP as previously set. With a simple echo and redirect, our host can receive the message.
8. Windows as host
Settings of VirtualBox under Windows is almost the same as that under Linux. But we set “Port/File Path” to “\\.\pipe\vbox”, instead of “/tmp/vbox”. After the configuration of kernel and getty(8), we can use PuTTY to connect. Simply set “Connection type” to “Serial”, and “Serial line” to “\\.\pipe\vbox”.
Thanks for the post. It was very useful for me!
Pingback: [VirtualBox] 在 Mac 上使用 minicom 連上 VirtualBox 的 serial port – EPHRAIN 亂打一通的心情日記
Thanks for this post. It was really really useful for me. I was struggling with debugging of kernel panic when running my scripts in Initramfs.