How can we add a kernel to grub2? i knew the stuff we could do with the former versions, but it seems to have changed. What files should we edit?
8 Answers
To add a new kernel to grub2:
- Move your kernel to /boot/
- Run sudo update-grub
update-grub will scan your computer for kernels, and create a listing of available kernels at boot.
In order for you to select which kernel to boot at boot time, you may have to hold the SHIFT button down right after your BIOS does its posting.
You can edit /etc/default/grub to change default boot options and parameters that you may need.
Non-Debian Linux
See the grub notes for your distribution, such as these Fedora GRUB 2 docs.
grub2-mkconfig -o /boot/grub2/grub.cfg
- 331
I'm running Fedora 20, and the command to update grub2 is grub2-mkconfig. Also, the entire process can be accomplished with the kernel build make:
make xconfig (make config, etc)
make bzImage
make modules
sudo make modules_install
sudu make install
This (last step) will copy the kernel into /boot, and update the grub2 boot loader. Very easy, and it worked correctly in my case. My only issue is that you don't really learn any important details of the process, everything is automated. If you have problems and have to figure out what's wrong, you could get stuck.
- 31,511
Try update-grub or update-grub2 depending on you grub version. You will have to run these as root, sudo. This worked for me when I installed a second Linux distro without reinstalling grub.
- 1,465
For Grub2, the file you should edit is called 40_custom and it's located at /etc/grub.d/. As this file states:
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment.
Here is an example of what a menu entry looks like:
menuentry 'Debian with Linux 5.10.0-21-amd64 (in /dev/sda8)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-simple-97a0ac1a-9298-4dfc-baf5-ae8cfb37e3f0' {
insmod part_gpt
insmod ext2
set root='hd0,gpt8'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt8 --hint-efi=hd0,gpt8 --hint-baremetal=ahci0,gpt8 97a0ac1a-9298-4dfc-baf5-ae8cfb37e3f0
else
search --no-floppy --fs-uuid --set=root 97a0ac1a-9298-4dfc-baf5-ae8cfb37e3f0
fi
linux /boot/vmlinuz-5.10.0-21-amd64 root=UUID=97a0ac1a-9298-4dfc-baf5-ae8cfb37e3f0 ro quiet
initrd /boot/initrd.img-5.10.0-21-amd64
}
You add your own modified menu entry (without deleting 40_custom's initial content) and then you run sudo update-grub2 or grub2-mkconfig -o /boot/grub2/grub.cfg (they do the same thing). To confirm that your entry was added, you can check the /boot/grub/grub.cfg file:
...
### BEGIN /etc/grub.d/40_custom ###
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
>>Your entry should appear here<<
END /etc/grub.d/40_custom
...
I had a similar issue and this post helped. First let me describe my issue, Installed Ubuntu first, then Fedora. Grub on Fedora is used at boot. Ubuntu kernal updates were not reflected in the grub boot menu. For Ubuntu the linux kernal can be found in /boot. There you will find entries named vmlinuz-n.n.n-generic where n.n.n is the version. I tried changing 40-custom as described by gene,bustam and ran grub2-mkconfig in the Fedora system but no joy - the new menu entry did not appear. What worked is editing /boot/grub2/grub.cfg directly. There was a menu entry for an old no longer existing kernal. I changed it to the new kernal version, rebooted and I was able to boot the latest Ubuntu kernal. Hope this helps.
/boot/grub/grub.cfg is the file that replaced menu.lst from grub1
In Debian/Ubuntu systems this is generated by update-grub, which runs the scripts in /etc/grub.d using something similar to run-parts.
If the new kernel is installed with dpkg (as if it's compiled with make-kpkg), update-grub2 is enough (it removes no more existent kernels, too)
- 2,394
You don't "edit" to add kernels anymore. It scans and adds them dynamically. If you MUST add one a scan doesn't find you should look in /etc/grub.d and modify or copy and custom40(it is added last so it's a great place to test your config before you put it at the top of your list).
- 5,934