martes, 13 de agosto de 2013

Accessing a virtual Box VM using telnet and serial port

alright alright alright, I am updating with steps that do the same and might can be easier to follow:
On behalf of my dear friend Sergio Pena.

There are some critical kernel panics that may freeze your system leaving you without a clue about what happened.
These kernel panics display a partially kernel stack trace on your system console, but not enough to do a complete debug of the error.
In order to get the complete kernel stack trace, we can get those kernel messages through the Linux serial port.

Let's follow these steps to configure your Linux system and a VirtualBox machine to get those kernel messages. 

Step 1: Configure the Linux Boot (Grub) to send kernel messages to the Serial Port

Edit the /boot/grub/menu.lst file, and add the following two lines before hiddenmenu config options:
serial --unit=0 --speed=9600
terminal --timeout=5 serial console
Scroll down and find out kernel line and append the following config options:
console=tty0 console=ttyS0,9600
At the end, your menu.lst should looks like this:
serial --unit=0 --speed=9600
terminal --timeout=5 serial console
title CentOS (2.6.32-358.11.1.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-358.11.1.el6.x86_64 ro root=/dev/mapper/vg_centos63-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos63/lv_swap rd_LVM_LV=vg_centos63/lv_root rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM console=tty0 console=ttyS0,9600
 initrd /initramfs-2.6.32-358.11.1.el6.x86_64.img

Now reboot your system.
Every kernel message will be sent to the serial port after boot.

Step 2: Configure VirtualBox to connect to Linux over a Serial Port

The next part is to enable the serial port on the virtual machine running on VirtualBox.
Open the settings for the machine on Virtualbox. Go to "Serial Ports". In the Port 1 tab enable the "Enable Serial Port" option. Use the following settings:
Port Number : COM1
Port Mode : Host Pipe
Create Pipe (Enabled)
Port/File Path : /tmp/vserial

Click on the OK button.
Now start the target machine. 

Step 3: Use 'socat' & 'telnet' commands to connect to Linux through the Serial Port

Now it is time to connect to your Linux serial port in order to catch those kernel messages.
We'll use the socat command to convert a Unix socket to a TCP port, and then connect to the serial port through telnet. 
Install the 'socat' utility package.
apt-get install socat
Then, in a terminal session, execute the following socat command to convert the Unix socket stream to a TCP port stream.
socat UNIX-CONNECT:/tmp/vserial TCP-LISTEN:7000
If everything goes fine, the socat command will be stuck. So, open another terminal session to execute your telnet command.
telnet localhost 7000
If the connection is successful, then you'll see an output like this:
Connected to localhost.
Escape character is '^]'.
That's it. You can start now seeing any kernel message that appears after your telnet session.



This is an easy way to connect to a VM by telnet using the serial port

For example, I have a  Centos 6.2 VM installed with Virtual Box.

Instead of using ssh because you would loose connection on a kernel panic

You can use telnet to see the stack trace.

Once the VM is started - Go to your local host and in a terminal type:

# socat UNIX-CONNECT:/tmp/centos62 TCP-LISTEN:7000

Notice that /tmp/centos62 is my VM (virtual Box) virtual serial port

Open a new terminal and type:

$ telnet localhost 7000

You will be asked for login/password; go ahead and start navigating on your VM

Do all operations you want over telnet or ssh and if a kernel oops happen then it will be shown on your local terminal where 'telnet localhost 7000' was issued. You will see the entire stack trace instead just part of it.


P.S. Which is the prettiest flag?

No hay comentarios:

Publicar un comentario en la entrada