I am not understanding how it comes to know which kernel image to load? I have so many. Once I had created my own kernel and recompiled. How does it come to know that this is the one to load?
To answer your final question:
You can put the new menuentry anywhere in /etc/grub.d/40_custom.
Then edit /etc/default/grub, and change the DEFAULT to the name of the menuentry that you added to 40_custom. (Using the name rather than a 0-indexed number is best because it allows for the possibility of more kernel images being added or deleted later: see grub2 infopage).
Then make sure to run
Reasoning: 40_custom gets added to grub menu underneath any kernel images that grub-update2 finds, so the order within 40_custom won't overide the kernels found by 10_linux.
It doesn't know. It only looks for certain files (
Then, on the boot stage GRUB looks into the file and uses information it placed there. It's simple.
$ sudo update-grub2 Generating grub.cfg ... Found linux image: /boot/vmlinuz-3.11.0-18-generic Found initrd image: /boot/initrd.img-3.11.0-18-generic Found memtest86+ image: /memtest86+.bin No volume groups found done
To elaborate on Danatela's answer, there exist grub-mkconfig helper scripts in
You could either look at the code in
Short story is that, yes, if you change the /boot/grub/grub.cfg file, the grub2 bootloader will read those changes and act accordingly.
The way around this is, instead of messing with grub.cfg at all, add the custom kernel menu entry to the end of /etc/grub.d/40_custom, and run
(That will ensure that your custom kernel will always be in grub's grub.cfg file even when there are grub or kernel updates pushed by by Ubuntu).
You still need to ensure that your kernel gets booted by default. Do so by editing the file /etc/default/grub
Change the line
where the quoted string is exactly what is in quotes for the corresponding menuentry in grub.cfg
You may need to run update-grub2 again.
That's it, you're done.
I have the following kernel and initrd:
and want to instead boot the following custom kernel by default
1) I look in /boot/grub/grub/cfg for the current entry. (Note, there seems to be a lot of unessential stuff in each menuentry -- see the end of this post for a bare-bones one).
2) I append the menuitem to /etc/grub.d/40_custom, substituting a new menuentry name, kernel image, and initrd:
4) reboot. you should see the new kernel at the bottom of the bootloader list.
5) Make it default by editing the default line in /etc/default/grub. It must exactly match whatever you put in quotes in /etc/grub.d/40_custom right after
6) Not sure if necesary, but won't hurt to re-run `#sudo update-grub2
Terminology: `The bootloader is called grub2, but colloquially ppl still call it 'grub'. So if you google for help on the subject, make sure to search specifically for grub2. Googling just 'grub' will bring up some outdated info on the old grub loader (which is still in use, but renamed 'grub-legacy').
How it knows: Grub2 consists of a tiny piece of software (boot.img) that is installed (usually on the MBR of your disk) and has hardcoded into it the locations on your disk of the grub.cfg file and more software (core.img and various *.mod files) which actually boot the linux kernel. So boot.img knows to find core.img, which in turn will read grub.cfg
grub.cfg is generated by the shell script /usr/sbin/update-grub2. It executes all the executable scripts in /etc/grub.d/ (in alphabetical order, so 10_linux gets executed before 40_custom, etc) and sends their outputs to grub.cfg
Barebones file Unless you are using non-standard filesystems or hardware you should only need a few lines to boot a linux kernel on a standard PC with grub. The other stuff is for graphical splash screens and I don't know what else (the following was tested with an ext4 /boot partition and / in lvm-ext4 ):