Friday, November 8, 2013

How To Redirect a ESX Linux VM's Console Output to a File

This How To will redirect the Linux console output to a file.  Especially useful when you want to collect the full boot log, or full stack trace of a Linux Kernel Panic.

Add VM Serial Port

1. Edit VM Settings and select "Add.." to add new hardware:









2. Select "Serial Port" from the Device Type:








3.Select "Output to file" for Serial Port Type:










4. Specify the file name to output as, on the desired Datastore: (I recommend an NFS share for easy access)










5. Finish saving your changes. Now ready to configure the VM.  Example of a finished Serial Port configuration:















Redirect Linux Console to Serial

1. Test serial out with: (should appear in serial output file specified above)
echo "hello" > /dev/ttyS0 
2. Modify Grub to have Linux Kernel also send console output to Serial: (/boot/grub/grub.conf)
  • Comment out splash screen (optional)
  • Add serial and terminal settings below "hidden menu" (optional)
  • Add kernel options (this is the important part)
# splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
serial --unit=1 --speed=19200
terminal --timeout=8 console serial
title CentOS
  ...
  kernel ... console=tty0 console=ttyS0,19200n8
3. (Optional) Create serial virtual console, append to /etc/inittab: (useful for login through serial)
S0:23:respawn:/sbin/agetty -h -L ttyS0 19200 vt100
  • Note: This would be useful if you change the output type from file to something bidirectional (physical serial, pipe, network) that you could login from (if needed)
4. Reboot.  Console output should now appear in the serial output file.

Test a Kernel Panic

To quickly test a kernel panic:
echo c > /proc/sysrq-trigger

Auto Answer Append/Replace Question

To auto answer the append/replace question that occurs when you now power on this VM: (http://kb.vmware.com/kb/1027096http://kb.vmware.com/kb/1027096)
1. Power off the virtual machine.
2. In the vSphere Client, right-click the virtual machine and choose Edit Settings.
3. Click the Options tab.
4. Under Advanced, select General and then click Configuration Parameters.







5. Click Add Row.
6. In the new row, enter "answer.msg.serial.file.open" for the Name and enter a Value of either "Append" or "Replace".
answer.msg.serial.file.open = Append

7 .Click OK in the Configuration Parameters window, then click OK in the Virtual Machine Properties window.

References:

  • Add a Serial Port to a Virtual Machine in the vSphere Client - http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.vsphere.vm_admin.doc_50%2FGUID-A779C84D-4324-4D32-AF43-BBD962ABC9E3.html
  • VMware vSphere 4 - ESX and vCenter Server - Add an Output Serial Port - http://pubs.vmware.com/vsphere-4-esx-vcenter/index.jsp?topic=/com.vmware.vsphere.webaccess.doc_40/adding_hardware_to_a_virtual_machine/t_add_an_output_serial_port.html
  • Linux: Configure / Enable Serial Console By Editing GRUB Boot Loader - http://www.cyberciti.biz/faq/linux-serial-console-howto/
  • VMware KB: Powering on a virtual machine pauses at 95% while waiting for a question to be answered - http://kb.vmware.com/kb/1027096

8 comments:

  1. Trucking Cube provides all type of shifting like moving and packing shifting, goods shifting, transportation services, etc.

    Truck Hire
    Freight Forwarder

    ReplyDelete
  2. Looks easy enough. Thanks for the guide. Hope it's applicable to vSphere replication .

    ReplyDelete
  3. Terrific post thoroughly enjoyed reading the blog and more over found to be the tremendous one. In fact, educating the participants with it's amazing content. Hope you share the similar content consecutively. Primavera Course in Chennai | Primavera online course

    ReplyDelete