Debian: how to choose default kernel in grub2

root's picture

It is simple and that is why I will be very straight.

The configuration file for grub2 is /boot/grub/grub.cfg, but you do not have to edit that file directly because it is generated by update-grub command and you will loose all your modification on next update.

The best way is to edit the following files:
- the configuration file: /etc/default/grub
- the snippets: /etc/grub.d/

After you alter any of the above configuration files, you need to run the update-grub command.

Now that you are familiar with grub2, if you want to choose a different default kernel, you just edit /etc/default/grub and modify GRUB_DEFAULT.
The list of kernels starts with number 0, so counting from this number down, you choose the one you desire from /boot/grub/grub.cfg.
For instance, if I want to boot by default from kernel 2.6.32-openvz-042stab113.11-amd64 (from below example), I will set GRUB_DEFAULT as 2.

root@vzc:~# grep menuentry /boot/grub/grub.cfg 
menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64' --class debian --class gnu-linux --class gnu --class os {
menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os {
menuentry 'Debian GNU/Linux, with Linux 2.6.32-openvz-042stab113.11-amd64' --class debian --class gnu-linux --class gnu --class os {
menuentry 'Debian GNU/Linux, with Linux 2.6.32-openvz-042stab113.11-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os {

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.