How to Capture the Panic message?
Generate panic
Write a patch to panic the kernel. Capture panic message. generate and send the patch and dmesg output from the module to Shuah Khan skhan@linuxfoundation.org and also upload the file.
when I do sudo insmod panic.ko, kernel is getting panicked and stuck there. how to capture the panic message? Do I need to just make patch for panic.c and Makefile and send it? What do I put in the document in that case? can anybody explain it.
Comments
-
Use QEMU to capture the panic message:
qemu-system-x86_64 \ -kernel arch/x86_64/boot/bzImage \ -nographic \ -append "console=ttyS0" \ -initrd /path/to/initramfs.img \ -m 512 \ --enable-kvm \ -cpu host
Typically, BusyBox is used in the initramfs, so
insmodshould be available to load your kernel module, but you have to include your kernel module in the initramfs image.Note: You don't necessarily need to panic the kernel from a kernel module. You can do the same in
init/main.c, for example.1 -
At the point of a kernel panic, the kernel itself is assumed to be in a bad state, such that it would be unsafe to write to the filesystem and risk corrupting it.
The underlying kernel mechanism you might want to read about is Kdump. Kdump addresses the problem of how you can safely write to the filesystem by keeping a crash kernel loaded in main memory:
https://wiki.archlinux.org/title/KdumpMost Linux distributions configure Kdump by default. You may find a core dump somewhere like
/var/log/crash/, depending on your distribution. Arch and SteamOS are exceptions in that you will have to configure it yourself.1 -
@gvernon said:
At the point of a kernel panic, the kernel itself is assumed to be in a bad state, such that it would be unsafe to write to the filesystem and risk corrupting it.The underlying kernel mechanism you might want to read about is Kdump. Kdump addresses the problem of how you can safely write to the filesystem by keeping a crash kernel loaded in main memory:
https://wiki.archlinux.org/title/KdumpMost Linux distributions configure Kdump by default. You may find a core dump somewhere like
/var/log/crash/, depending on your distribution. Arch and SteamOS are exceptions in that you will have to configure it yourself.Thank you for this insight! Was able to successfully configure kdump and take a look at the logs post-crash.
0 -
I have tried to set it up on Linux mint but unable to get any crash reports? Anyone facing the same issue?
0 -
@saiprasadpatil said:
I have tried to set it up on Linux mint but unable to get any crash reports? Anyone facing the same issue?I case anyone is in this situation, you can check
/var/lib/systemd/pstore. It has the logs saved from a previous panic.0 -
@imanseyed said:
Use QEMU to capture the panic message:qemu-system-x86_64 \ -kernel arch/x86_64/boot/bzImage \ -nographic \ -append "console=ttyS0" \ -initrd /path/to/initramfs.img \ -m 512 \ --enable-kvm \ -cpu host
Typically, BusyBox is used in the initramfs, so
insmodshould be available to load your kernel module, but you have to include your kernel module in the initramfs image.Note: You don't necessarily need to panic the kernel from a kernel module. You can do the same in
init/main.c, for example.I tried to do this and qemu gets stuck with the following output
No EFI environment detected. early console in extract_kernel input_data: 0x0000000002ca12c4 input_len: 0x0000000000d6ff31 output: 0x0000000001000000 output_len: 0x00000000029c7170 kernel_total_size: 0x0000000002830000 needed_size: 0x0000000002a00000 trampoline_32bit: 0x0000000000000000 Physical KASLR using RDRAND RDTSC... Virtual KASLR using RDRAND RDTSC... Decompressing Linux... Parsing ELF... Performing relocations... done. Booting the kernel (entry_offset: 0x0000000001255c70).
Command I used
qemu-system-x86_64 \ -kernel arch/x86/boot/bzImage \ -initrd /boot/initramfs-6.15.8-200.fc42.x86_64.img \ -nographic \ -append "console=ttyS0 earlyprintk=serial" \ -m 512 \ --enable-kvm \ -cpu host
Also I am trying to crash by adding
panic()in init/main.c0 -
@rajeevtapadia said:
Command I usedqemu-system-x86_64 \ -kernel arch/x86/boot/bzImage \ -initrd /boot/initramfs-6.15.8-200.fc42.x86_64.img \ -nographic \ -append "console=ttyS0 earlyprintk=serial" \ -m 512 \ --enable-kvm \ -cpu host
Also I am trying to crash by adding
panic()in init/main.cWhere exactly are you trying to add
panic()? I'd recommend adding it afterconsole_init().1 -
Thanks for the reply @imanseyed
I tried a lot of stuff turns out, I had two problems
First I had cloned the kernel on a external drive and it was causing some problems. I moved it to internal drive and recompiled. It worked.Where exactly are you trying to add
panic()? I'd recommend adding it afterconsole_init().As per your suggestion I moved
panic()afterconsole_init()and I could see the panic message on terminal.Thanks for the help.
0
Categories
- All Categories
- 177 LFX Mentorship
- 177 LFX Mentorship: Linux Kernel
- 750 Linux Foundation IT Professional Programs
- 373 Cloud Engineer IT Professional Program
- 169 Advanced Cloud Engineer IT Professional Program
- 74 DevOps IT Professional Program - Discontinued
- 4 DevOps & GitOps IT Professional Program
- 99 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 1 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 3 Cloud & Containers Training
- 1 Cybersecurity Training
- 2 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 1 Networking Training
- 1 Open Source Best Practice Training
- 1 System Administration Training
- 1 System Engineering Training
- 1 Web & Application Development Training
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 769 Linux Distributions
- 81 Debian
- 68 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 106 Mobile Computing
- 18 Android
- 73 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 955 Programming and Development
- 310 Kernel Development
- 627 Software Development
- 983 Software
- 375 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)