This article is mainly helpful for kernel developers who would like to access Linux (guest) kernel logs using some tool from windows(host) PC. This is one way to see what is happening to the guest OS when the kernel is booting. Usually this information is passed to and from guest and host via a RS232 serial port. This is most commonly seen in linux embedded systems. So, In real world, guest could be an embedded platform like Beaglebone or Raspberry Pi.
Configuring both guest and host require mainly four steps.
- Make a virtual serial port available to guest from VirtualBox settings page
- Configure linux kernel to redirect the kernel log to the above virtual serial port
- Configure VirtualBox to read back the kernel log into named windows pipe
- Finally read the redirected kernel log using putty
Make a virtual serial port available to Linux guest from VirtualBox settings page
This is the simplest step of all. Just make sure you started VirtualBox with administrator permissions. Then all we need to do is enable the following checkbox in the VirutalBox settings as shown below.
Configure linux kernel to redirect the kernel log to the above virtual serial port
This step requires couple of things to be configured in the guest OS. So we boot the guest linux operating system.
- Open sudo gedit /etc/init/ttyS0.conf
- Add following content in to the file created above
- # ttyS0 – getty
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on stopped rc or RUNLEVEL=
stop on runlevel [!2345]
exec /sbin/getty -L 115200 ttyS0 vt102
- Save the above file and run the command sudo start ttyS0
- The above step creates a service to make the incoming serial connection interactive by running getty.
- Next major step is configure the kernel to make available the kernel log from the system boot
- Run sudo gedit /etc/default/grub
- In that file change GRUB_CMDLINE_LINUX=”” to GRUB_CMDLINE_LINUX=”console=ttyS0,115200n8 ignore_loglevel”
- Also uncomment the line #GRUB_TERMINAL=console to GRUB_TERMINAL=console and add a line below it GRUB_SERIAL_COMMAND=”serial –speed=115200 –unit=0 –word=8 –parity=no –stop=1″
- Save the file and exit and run sudo update-grub2 to update grub
- Now from the next boot the kernel log is made available to any serial program which tries to connect to /dev/ttyS0
Configure VirtualBox to read back the kernel log into named windows pipe
This step configures the windows host to read back the kernel log via windows pipe. You can think of windows pipe as an equivalent mechanism to linux virtual files present in sysfs. Following screenshot will show the required settings to be done in VirutalBox(to make any changes to virutalbox settings the guest should be shutdown first or else the settings will be greyed out)
Finally read the redirected kernel log using putty
Download and Run putty with administrator permissions. And configure it as shown below.
Make sure before clicking open in putty your VM is just started. Once connected to Guest OS, you can get the logs as shown below.
Happy Kernel Hacking!