0

I am trying to debug a module for the Linux kernel. I heard that it is possible to send the console output to a serial port. I'm running Ubuntu on vmware and want to send printk message to the host. I have managed to set up a serial Connection and can send an echo to the host by typing echo > simething /dev/ttyS1 But I can't figure out how to send the output on the console to ttyS1.

My main problem is that when the module/kernel crashes the last printk-messages are lost and not even displayed, it just buffers.

Dave
  • 341
  • 1
  • 4
  • 13

2 Answers2

5

On Guest Linux Kernel

sudo vim /etc/default/grub  
GRUB_CMDLINE_LINUX="console=ttyS1,115200n8 console=tty0 ignore_loglevel"
sudo update-grub  

NOTE:- kernel parameter "ignore_loglevel" will print all kernel messages to the console. Useful for debugging.

Now Enable getty On Console ttyS1
For Upstart System
1) Create a file called /etc/init/ttyS1.conf containing the following:

# ttyS0 - getty
#
# This service maintains a getty on ttyS1 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[12345]
stop on runlevel [!12345]

respawn
exec /sbin/getty -L 115200 ttyS1 vt102  

2) Ask upstart to start the getty

sudo start ttyS1  

For Systemd Systems

$ sudo systemctl enable serial-getty@ttyS1.service
$ sudo systemctl start serial-getty@ttyS1.service
$ sudo systemctl daemon-reload
Tauqeer
  • 71
  • 1
  • 3
2

Try booting your kernel with the command line 'console=ttyS1,<baud>', where <baud> is the baud rate you configured for that port in the VM settings. The kernel will then use /dev/ttyS1 as the main console, and that's where printk will send all of its output to.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Kumba
  • 2,390
  • 3
  • 33
  • 60
  • I added `GRUB_CMDLINE_LINUX="console=ttyS1,115200n8"` to /etc/default/grub and then ran update-grub and rebooted. However nothing is going to the serial port. I did check cmdline.txt to see if console=ttyS1 was added and it was. I dont know if the baud rate is wrong or something. – Dave Apr 15 '16 at 15:46