Tuesday, September 22, 2020

Fix Linux kernel booting error ( invalid magic number)

 This morning, I compiled Linux kernel and copied the kernel to /boot/vmlinz, then reboot. But I got the following error:

error: invalid magic number.
error: you need to lead the kernel first

What could go wrong? I searched online and find this article https://bbs.archlinux.org/viewtopic.php?id=178314.
It is very helpful. I run the cmd : file /boot/vmlinz and noticed that it does recognize it as a kernel.
Then I checked file size and realized that I copied the wrong file. I copied the big vmlinx instead of arch/x86/boot/bzImage file.

Then I copied the correct file and I can boot to my new kernel again. :)

Btw, I manually copied the kernel file because it is much faster.  I just need to run "make bzImage" and then copy the new kernel. Save me lots of time for compiling and building.