# [SOLVED] Rebuilt kernel: invalid magic number

## Dylanus

Hi all,

I have recently got my Gentoo installation working, but I configured the wireless drivers as built-in, not modules, which is giving me problems setting up libvirtd. Since these drivers are built-in, my understanding is that I have to recompile the kernel, I can't simply compile the modules and load them. So I recompiled the kernel and copied the vmlinux file to /boot. I did not run make install, as I did not want to remove the working kernel, which turns out to be a good decision, as this one is not working. Then I ran genkernel --luks --lvm initramfs, followed by grub-mkconfig. The new kernel was discovered, along with a second initramfs. Then when I rebooted and selected the new kernel, it told me there was an invalid magic number and I needed to load the kernel first.If I return to Grub and select the old kernel, everything boots fine.

In /usr/src/ I have a directory simply called linux, and one called linux-4.14.52-gentoo. I compiled in linux/ as I assumed this would be the original source I downloaded at installation, after copying across .config. Is everything I have done so far correct? Do I need to post any config files? How can I get a new kernel booted with the modules I need without running make install?

ThanksLast edited by Dylanus on Thu Aug 02, 2018 7:46 am; edited 1 time in total

----------

## khayyam

Dylanus ...

it's not altogether clear what you're trying to achieve, you want to modularise the wireless driver? If that is the case then you need to run 'make modules_install' subsequent to 'make', and prior to runing 'genkernel' and building the initramfs. 

best ... khay

----------

## Dylanus

I did run that. The compilation was fine. Now I just want the system to boot that kernel without running make install, so that it doesn't replace the working kernel. Why the magic number error?

----------

## toralf

 *Dylanus wrote:*   

> Now I just want the system to boot that kernel without running make install, so that it doesn't replace the working kernel

 

Usually the new kernel is installed beside the others. It is the grub2 default entry, which usually points to the latest kernel. Take a look at the Gentoo wiki, look there for "grub2" "kernel" and "boot".

----------

## khayyam

 *Dylanus wrote:*   

> I did run that. The compilation was fine. Now I just want the system to boot that kernel without running make install, so that it doesn't replace the working kernel. Why the magic number error?

 

Dylanus ... because the kernel, and modules/initramfs built in concert with that kernel, are intertwined. So, if your kernel is build with say DRIVER=y, and you rebuild with DRIVER=m, then you can't continue to use the first kernel, because that kernel is not consistent with those modules under /lib/modules-$(uname -r) ... which are included in the (genkernel generated) initramfs.

So, rename the vmlinuz and initramfs to {name}-{version}-fallback, and re-create the vmlinuz, modules, and initramfs. You'll then need to re-run 'grub-install'.

best ... khay

----------

## Anon-E-moose

A few points, running "make install" will copy the latest built kernel (along with system.map) into boot, BUT it will rename the old kernel (the last one, if same version number) to <whatever>.old.

If you want to keep it around past that point, then rename *.old to whatever name you want.

With grub you can stop the boot process and edit the command line to boot whichever kernel (in boot) that you want.

Hopefully you also do a modules_install after building the modules and kernel or the running kernel will never see them as they wouldn't be installed into /lib/modules/<whatever version>

You should also copy the System.map to /boot to match the name of the "new" kernel image.

----------

## Dylanus

Thank you both, I understand a bit better now. I'll try all that tomorrow afternoon.

----------

## Anon-E-moose

Sorry, I forget about initramfs as I don't use it. IF you do use one then keep khayyam's advice regarding it, in mind.

Edit to add: as a side note, I didn't use make install for years, but instead copied the files by hand (install is easier  :Smile:  )

----------

## Dylanus

It worked! I originally thought the invalid magic number error may have been caused because I copied the wrong files, but in fact I think my compiled kernel was corrupted. I noticed an error about clock skew, so I had to touch every file, a tip I saw in another post on this forum, which is amazing, by the way. I use initramfs because I have full disk encryption, but the steps for this were very similar to the instructions at installation. I understand the process of booting from a new kernel much better now, thank you.

Unfortunately compiling the wireless drivers as modules has not fixed the problem with libvirtd, but I think it would be best for me to ask that question on another thread.

Thanks again to Anon-E-moose and khayyam.

----------

## alessio_demarchi

Hello everyone

I have the same problem ("invalid magic number" on load kernel at boot).

But I have not understand the solution.

Can You explain me that?

Thanks

----------

