ILD

Hyper-V enable serial and capture linux panic
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2026-7-1 站点:Inside Linux Development

最近开发了一个内核模块,想在ubuntu上做压力测试。ubuntu运行在Hyper-V上。

正常显示的是GUI页面。内核的消息只能通过dmesg查看。发生panic的时候。看不到内核日志。

将ubuntu切换成命令行模式,在Hyper-V控制窗口,发现tty是/dev/tty0。正常内核日志,也不会输出到tty0


1 开启COM1

打开powershell。


查看:

PS C:\Windows\system32> Get-VMComPort -VMName ubuntu26

VMName   Name  Path
------   ----  ----
ubuntu26 COM 1
ubuntu26 COM 2


设置COM1

windows管道路径:\\.\pipe\ubuntu26-com1

PS C:\Windows\system32> Set-VMComPort -VMName ubuntu26 -Path \\.\pipe\ubuntu26-com1 -Number 1


再次查看:

PS C:\Windows\system32> Get-VMComPort -VMName ubuntu26

VMName   Name  Path
------   ----  ----
ubuntu26 COM 1 \\.\pipe\ubuntu26-com1
ubuntu26 COM 2


2 开启内核命令行参数

重启虚拟机,dmesg,确认tty设备是哪个:

yuanjp@vm:~$ sudo dmesg | grep tty
[    0.062406] printk: legacy console [tty0] enabled
[    0.149590] 00:00: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    0.172912] 00:01: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A


修改grub配置:

$ sudo vim /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash console=ttyS0"


生效

$ sudo update-grub


3 打开串口

重启虚拟机ubuntu,然后使用putty打开串口,地址填:\\.\pipe\ubuntu26-com1,波特率填115200


可以看到,输出了内核日志:



参考

https://superuser.com/questions/1274294/capture-serial-console-text-from-a-hyper-v-guest


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.