# Grub2 not detecting newly compiled kernel

## Buuntu

I just recently installed gentoo and compiled the kernel with the genkernel script (I was lazy at the time).  In order to get my wireless driver to be loaded however, I had to re-compile the kernel to allow support for it.  The problem now is that grub2 is not recognizing the new kernel after updating grub.  After choosing the right modules with 'make menuconfig', I compiled with:

```
make && make modules_install

cp arch/x86/boot/bzImage /boot

```

Grub2 is installed on a separate partition running Ubuntu 11.10, so I had to boot into it each time and run: 

```
sudo update-grub
```

but after restarting the only entries that showed up were the Gentoo versions (normal and recovery mode) with the kernel compiled from the genkernel script.

After that didn't show up in the grub menu, I changed the kernel name to begin with 'kernel' (also tried 'vmlinuz'), since I read that is what grub2 looks for. It looked something like:

```
kernel-3.12.13-gentoo
```

The last thing I attempted was manually adding an entry into the 40_custom grub file, which I basically copied from the genkernel entries in grub.cfg, only changing the linux kernel line to the newly compiled kernel.  That showed the entry in the grub menu and appeared to begin booting when I selected it but after a while I got an error about my root partition not being set to a proper device.  That didn't make sense to me since it was set to the same root partition as the genkernel entries (which boot up properly).  All of the gentoo installation is on one partition; no separate /home or /boot partitions.

Am I missing something or going about switching kernels incorrectly?

----------

## Logicien

Your Ubuntu version is quite old now, since the latest stable is 14.04.

If I understand well, you let Ubuntu Grub detect your Gentoo with the os_prober script in the /etc/grub.d directory. I do not use that script. It is possible that os_prober can only add one entry for a Linux operating system.

Anyway, you can use the 40_custom script to add an entry to Grub. First, do you see the kernel-3.12.13-gentoo image in the Gentoo boot directory? If you show us the entry you create in the 40_custom file, we could help you more. Did you set Grub to the good Gentoo partition

```
set root=(hdx,y)
```

Did you set the Gentoo kernel to boot on the good root partition

```
linux /boot/kernel-3.12.13-gentoo root=/dev/sdxy
```

If you use an initrd, you must write a line for it in the entry. 

Note that all the scripts you want ot use in /etc/grub.d must be executables. The grub-mkconfig (update-grub) command will not execute a script who is not executable in that directory. Dont forget to execute

```
update-grub
```

from Ubuntu after any Grub configuration modification.

----------

## Buuntu

My /boot/grub/grub.cfg look like this:

```
menuentry "Gentoo 3.12.13" --class gnu-linux --class-gnu --class os {

insmod part_msdos

   insmod ext2

   set root='(hd0,msdos7)'

   search --no-floppy --fs-uuid --set=root cef6e7f4-c4ef-42dd-91aa-1a2ff96553d6

   linux /boot/kernel-3.12.13-gentoo root=UUID=cef6e7f4-c4ef-42dd-91aa-1a2ff96553d6 ro

   initrd /boot/initramfs-genkernel-x86-3.12.13-gentoo

}

```

I copied the UUID from the working gentoo kernel entries but have also tried just entering /dev/sda7, where the root partition is located.  So at this point I guess the problem isn't that the kernel isn't detected since it does appear in the grub menu after manual entry (although it would be nice for grub to automatically identify it) and seems to begin to load before the error message.  The error message is about /dev/sda7 not being a working device for the root partition.  Interesting because the genkernel entries are set identically and don't give me the error message.

----------

## pa1983

I just started using grub2 a few months ago, use grub on all other systems and used lilo back in the day.

I compiled my kernel manually as always, I just changed how I set up the bootloader on the latest system. I have also upgraded the kernel on that system a few times now since its pretty new hardware so out of the box I did not have full support on all the stuff I needed.

Any way this is what I do.

First find out how many threads your CPU supports. First processor starts at 0 so if the last is 1 you have 2 cores or threads.

cat /proc/cpuinfo | grep processor

before you compile the kernel clean up any old files

cd /usr/src/linux

make clean

Then compile the kernel and use the -j flag to save time. Now add + 1 to the number of processors "cat /proc/cpuinfo | grep processor" gave you for example a duel core CPU with out SMT would be 2+1 so that makes 3. This will make sure both cores runs jobs for the compiler

make -j3 bzImage

if you want to know how long it took to compile the kernel you can use the time command like so to see what -j option works best for you in the future

time make -j3 bzImage

before copying the kernel make sure /boot is mounted. If not mount it like so

df -Th

mount /boot

copy the kernel and rename it to kernel-version where version is replaced with the actual version for example kernel-3.12.6. If you run many kernels you can add -gentoo or -vanilla after the kernel number. This is just  a recommendation not a must do

cp arch/x86_64/boot/bzImage /boot/kernel-3.12.6

emerge genkernel if you dont have it installed (in your case I assume you have since you mentioned it so you can skip this)

emerge genkernel

for grub2 to write a proper config file for you new kernel or kernel images you need an initrd image for it. To create one for you kernel or kernel images you need to run the fallowing command. This should generate initramfs images and you should find them in /boot starting with initramfs-genkernel-* fallowed by the name you gave your kernel image

genkernel --install initramfs

Finally we need to create a new grub.conf so we can boot our new kernel images. Grub2 should tell you that it found the initramfs-genkernel-* and kernel images in /boot that you compiled and generated in the previous steps. If so you should have them in grub2 when booting as boot options

grub2-mkconfig -o /boot/grub/grub.cfg

If you want to remove an old kernel just delete the initramfs-genkernel-* and the kernel image associated with it and re run "grub2-mkconfig -o /boot/grub/grub.cfg" to generate a new grub.conf with out them.

I hop this helps.

----------

