VirtualBox headless with serial console
First set up a serial port in VirtualBox. In the Details section for the virtual machine, click Serial Ports, check Enable Serial Port, set Port Mode to Host Pipe, check Create Pipe and put e.g. /tmp/freebsd8vm-socket in Port/File Path.
Now start the virtual machine. Use socat to connect the domain socket created by VirtualBox to a pty.
socat UNIX-CONNECT:/tmp/freebsd8vm-socket PTY,link=/tmp/freebsd8vm-pty &
It should be possible to now connect to the serial port with screen. If you disconnect the screen session the pty will be removed, so the above socat command will need to be run again.
screen /tmp/freebsd8vm-pty
TODO
These instructions apply at least to Debian Lenny, but probably will at least mostly work on other Linux systems as well.
Uncomment/modify this line in /etc/inittab for serial console.
T0:23:respawn:/sbin/getty -L ttyS0 38400 vt100
Tell init to re-read inittab
telinit q
Now we have to tell grub and the kernel (via grub) to use a serial console as well. Add the following to /boot/grub/menu.lst
# Serial console
serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console
Then find the kernel boot options line, which should look like this
# kopt=root=/dev/hda1 ro
and add arguments to use a serial console
# kopt=root=/dev/hda1 ro console=tty0 console=ttyS0,38400n8
Now update the Debian automagic kernel sections
update-grub
I also added noapic to the kernel options to prevent the system from periodically freezing at boot
# kopt=root=/dev/hda1 ro console=tty0 console=ttyS0,38400n8 noapic
Start headless
VBoxManage startvm lenny -type headless
If rebooting the VM is necessary
VBoxManage controlvm lenny reset
It is handy to be able to ssh to the VM. When using the default NAT network configuration for VirtualBox, the only way to make network connections from the host to the guest system is with port forwarding. The following commands will forward port 2222 on the host to 22 on the guest VM. Unfortunately this makes the host listen on 0.0.0.0, and I have not found a way to make it only listen locally.
VBoxManage setextradata lenny "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/Protocol" TCP
VBoxManage setextradata lenny "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/GuestPort" 22
VBoxManage setextradata lenny "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/HostPort" 2222
http://www.howtoforge.com/setting_up_a_serial_console http://download.virtualbox.org/virtualbox/3.1.2/UserManual.pdf
Thanks, It worked for me.