How can I pick which kernel GRUB 2 should load by default? I recently installed a Linux real-time kernel and now it loads by default. I'd like to load the regular one by default.

So far I only managed to pick the default OS... and for some reason the /boot/grub.cfg already assumes that I want to load the real-time kernel and put it into the generic Linux menu entry (in my case Arch Linux).

  • 2
    grub2-set-default <title or number> ?
    – taliezin
    Commented Apr 22, 2015 at 21:15
  • 3
    But how do I know the number? The numbers in grub.cfg only correspond to the OSs and not the kernels.
    – TomTom
    Commented Apr 22, 2015 at 21:17
  • In some cases this works: askubuntu.com/questions/216398/… You can find the menu names by looking through this file: /boot/grub/grub.cfg
    – TekOps
    Commented Oct 4, 2018 at 5:18
  • An alternative not including position of GRUB menu items could be manipulating what is going on in script /etc/grub.d/10_linux (as it is "which locates kernels in the default partition"). There must be a way to make it pick a particular kernel version (say, an LTS one) instead of the one with the highest version number (not necessarily better)). Commented Mar 9, 2023 at 11:31

10 Answers 10


After struggling for 2 hours, I have found a much easier way to achieve this. I just RTFM. ;)

Add two lines to /etc/default/grub


Do the sudo update-grub, reboot, get into your grub menu and select whichever menu or submenu item you need. The choice will be saved every time and then your computer will boot into it automatically. When you manually choose a different entry, that becomes the new default.

  • 6
    As of 2020, sudo update-grub returns a command not found in Arch. Instead the command sudo grub-mkconfig -o /boot/grub/grub.cfg should be used.
    – bela83
    Commented Jun 9, 2020 at 7:59
  • 1
    I had to comment out GRUB_DEFAULT=0
    – daslicious
    Commented Sep 24, 2020 at 18:23
  • 1
    "The choice will be saved and next time your computer will boot into it automatically". So it only saves the default once in the next reboot? Or will it it automatically change the default every time you choose a specific kernel?
    – geekley
    Commented Dec 26, 2020 at 1:53
  • 1
    @geekley what do you think save default means?
    – RichieHH
    Commented Jan 8, 2021 at 6:53
  • 1
    @RichieHH I made that comment before editing the answer. Before, it wasn't so clear if the default would be saved only on the first reboot or every time I choose an option. That's why I rephrased it to better clarify that the default changes every time you manually choose a different entry. Btw, this saved default is not necessarily the first choice (like "Ubuntu"), it can be a sub-entry (like "Ubuntu with linux X.Y.Z generic"). The first choice won't automatically reflect the default, which might get you a bit confused if you have 2 kernels like linux and linux-libre.
    – geekley
    Commented Jan 8, 2021 at 19:30

I think most distributions have moved additional kernels into the advanced options sub menu at this point, as TomTom found was the case with his Arch.

I didn't want to alter my top level menu structure in order to select a previous kernel as the default. I found the answer here.

To summarize:

  1. Find the $menuentry_id_option for the submenu:

    $ grep submenu /boot/grub/grub.cfg
    submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
  2. Find the $menuentry_id_option for the menu entry for the kernel you want to use:

    $ grep gnulinux /boot/grub/grub.cfg
    menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
    submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-rt-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-rt-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-rt-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-rt-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.18.0-0.bpo.1-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-0.bpo.1-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.17.0-0.bpo.1-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.17.0-0.bpo.1-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.17.0-0.bpo.1-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.17.0-0.bpo.1-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.9.0-8-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.0-8-amd64-advanced-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
        menuentry 'Debian GNU/Linux, with Linux 4.9.0-8-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.0-8-amd64-recovery-38ea4a12-6cfe-4ed9-a8b5-036295e62ffc' {
  3. Comment out your current default grub in /etc/default/grub and replace it with the sub-menu's $menuentry_id_option from step one, and the selected kernel's $menuentry_id_option from step two separated by >.

    In my case the modified GRUB_DEFAULT is:

  4. Update grub to make the changes. For Debian this is done like so:

    $ sudo update-grub


Now when you boot, the advanced menu should have an asterisk and you should boot into the selected kernel. You can confirm this with uname.

$ uname -a
Linux NAME 4.18.0-0.bpo.1-amd64 #1 SMP Debian 4.18.0-0 (2018-09-13) x86_64 GNU/Linux

Changing this back to the most recent kernel is as simple as commenting out the new line and uncommenting #GRUB_DEFAULT=0:



then rerunning update-grub.

Specifying IDs for all the entries from the top level menu is mandatory. The format for setting the default boot entry can be found in the documentation.

  • 3
    This method is quite adventurous with out having the GUI console or Serial console.... Trying to change the aws kernel to generic kernel and after rebooting the AWS EC2 instance (which has been deployed in the the region doesn't support serial console feature), its not accessible.. It seems, that was stuck at the grub menu itself, but the aws dashboard system checks are in green. Commented Aug 6, 2021 at 18:15
  • 2
    The problem is that the default kernel does not update when a new kernel of the desired series gets installed.
    – jarno
    Commented Sep 4, 2021 at 14:10
  • I'd expect to find a utility to report the latest kernel matching a certain keyword, and another to automatically make it the default. But these aren't hard to write. Commented Aug 4, 2023 at 9:02
  • This should work I think, but somehow didn't for me. The machine still booted into the default (HWE) kernel, which caused problems in this case. Worth pointing out is that I was rebooting uninteractively, via SSH. I ended up uninstalling the "bad" kernel using an approach like this instead: askubuntu.com/a/1335455/305208 Commented Jan 25 at 13:55

As mentioned in the comments, you can set the default kernel to boot into using the grub-set-default X command, where X is the number of the kernel you want to boot into. In some distributions you can also set this number by editing the /etc/default/grub file and setting GRUB_DEFAULT=X, and then running update-grub.

The number is the index to an array of kernels/kernel settings shown in the GRUB menu during boot, with 0 being the first (top-most) entry. You can usually find the right number by looking for menuentry lines in /boot/grub/grub.cfg, like so:

grep menuentry /boot/grub/grub.cfg

You'll see each kernel listed with the name that is shown in the GRUB boot menu. The first one is 0, the second is 1, and so on.

  • 2
    In Fedora 21 it's /boot/grub2/grub.cfg. Commented Apr 23, 2015 at 0:01
  • 3
    This is not working for me. The latest kernel in my installation is 4.4.0-64-generic (menuentry 0) but I want 4.4.0-59-generic (menuentry 9) to be the default boot kernel. I ran grub-set-default 9 and then grub-update and rebooted. I let grub boot with the default kernel and it still boots with 4.4.0-64-generic. I also tried editing /etc/default/grub and set GRUB_DEFAULT=9 and ran grub-update. On rebooting nothing changes, system still boots with 4.4.0-64-generic. Maybe I missed something, can anyone help me? Commented Feb 27, 2017 at 14:40
  • This did not work for me either. I deleted the unwanted kernel like explained here: askubuntu.com/a/764242/456247
    – Luis
    Commented Jan 11, 2018 at 10:52
  • 4
    @Dronacharya After 5 years I can tell you that you probably needed to write both the submenu number (0 for the top one, 1 for "Advanced options") and then the menuentry number (9), all in between quotes, like GRUB_DEFAULT="1>9".
    – Andyc
    Commented Feb 2, 2022 at 17:30

Simply doing grep 'menuentry' /boot/grub/grub.cfg lists additional entries that are not related to the actual kernel or OS versions. For instance, it lists

if [ x"${feature_menuentry_id}" = xy ]; then
export menuentry_id_option

I would like to propose a small improvement to the method of searching that file:

$ awk '/menuentry/ && /class/ {count++; print count-1"****"$0 }' /boot/grub/grub.cfg
0****menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-86df21bf-d95f-435c-9292-273bdbcba056' {
1****   menuentry 'Ubuntu, with Linux 3.19.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-26-generic-advanced-86df21bf-d95f-435c-9292-273bdbcba056' {
2****   menuentry 'Ubuntu, with Linux 3.19.0-26-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-26-generic-recovery-86df21bf-d95f-435c-9292-273bdbcba056' {
3****   menuentry 'Ubuntu, with Linux 3.13.0-62-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-62-generic-advanced-86df21bf-d95f-435c-9292-273bdbcba056' {
4****   menuentry 'Ubuntu, with Linux 3.13.0-62-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-62-generic-recovery-86df21bf-d95f-435c-9292-273bdbcba056' {

With the command above and its output, you can see the code corresponding to each OS version, which gives you the number to use in the /etc/default/grub file.

Instead of editing the /etc/default/grub file by hand, I suggest using sed. In the following command, replace X with the appropriate number as determined above:

sudo sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT=X/g' /etc/default/grub; sudo update-grub

  • 2
    This isn't an answer. It reads like a comment. An answer should say, "This is how to set the default entry in GRUB", not "let me make an addendum to another answer". You can easily edit this into a proper answer, but it might be smarter to just leave a comment on jkt123's answer about using awk instead of grep. Commented Sep 28, 2016 at 8:50
  • 3
    I think this answer does improve signifcantly on the answer proposing grep, if you compare the output of the two, the awk output is much easier to use (includes number, easier to read). But, the introduction should probably be re-written so this answer stands alone, and doesn't read like a comment to the grep answer.
    – Cameron
    Commented Jan 30, 2020 at 1:47
  • I would love to see a real helper to do this thing and not just scripts. I tried this solution and I broke my boot and, since I don't have physical access to the machine, I couldn't boot it anymore. On Ubuntu 20 the default option is GRUB_DEFAULT="1>0", and not just a number. I wanted to boot option 5 (from this awk cmd), but 1>5 broke it since apparently the second menu is a 0-indexed menu. Still looking for a reliable remote solution to set default kernel...
    – hfingler
    Commented Apr 11, 2022 at 16:50

In order to do it with a GUI, I use Grub Customizer (I'm in Mint and have installed it like this.).

The idea is to keep the Advanced options in the grub list in case the default list is changed within Grub Customizer.

enter image description here

Then, under General settings select the default entry: previous booted entry.

enter image description here

Then, reboot, and during boot select the "Advanced options" entry in the grub list:

enter image description here

and select the desired kernel

enter image description here

On the next reboot, the "Advanced options" item will be the one selected by default in the grub list and the last selected kernel from under there will be booted (without opening the full list of kernels).

In case Windows is used, or other option in the grub list, remember to re-do the previous procedure.


jkt123's answer will work for most distributions, I guess. However, for Arch Linux it didn't work, at least not with the packages I have available.

The indices you can set with grub-set-default only correspond to the main menu entries. The kernel options are however in a submenu. So either you move the kernel entry out of the submenu into the main menu or you put the entry on top of the submenu list and select the submenu.

My GRUB Menu

  • Arch Linux
  • Advanced options for Arch Linux
    • Kernel 1
    • Kernel 2
  • Windows

To be able to boot Kernel 2, you have to either swap it with Kernel 1 or you put it outside the submenu on the same level as Arch Linux or Windows. And then set the default number to one of the main menu indices. For example, in the menu above "0" boots "Arch Linux" and "1" boots Kernel 1.

To change the hierarchy and swap, open /boot/grub/grub.cfg and move the entry you wish to move. An entry could look like this

menuentry 'ENTRY NAME'
   ... some code ...

Then you need to apply your changes. In my case with grub-mkconfig. But this might vary from system to system.


Solution without worrying about index number or identifiers

This is what worked for me on an archlinux VPS:

In addition to setting the following in /etc/default/grub:


I used the following option to set the mainline Linux kernel as the default:

sudo grub-set-default 'Advanced options for Arch Linux>Arch Linux, with Linux linux'
sudo grub-mkconfig -o /boot/grub/grub.cfg

The above works because the man 8 grub-set-default page says this about MENU_ENTRY option:

MENU_ENTRY is a number, a menu item title or a menu item identifier.

If you make the mistake of just using Arch Linux, with Linux linux for example, it will still work but you will get a warning when you run the grub-mkconfig command.


As recently as CentOS-6.6 grub.conf looked like this can could be manually edited to change the default selection:

  • But it will often be overwritten (by updates, etc.)? Commented Mar 9, 2023 at 10:42

In short, steps that work for me:

  • Edit /etc/default/grub

The indexing of all installed kernel/OSes starts with '0'. Pick yours, if not '0'.

  • Regenerate the grub configuration

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

    In some cases, it might be grub2. Choose accordingly.

  • Reboot (reboot)


  • But zero is already the default. Commented Mar 9, 2023 at 10:47
  • What might be 'grub2'? grub2-mkconfig, grub2 (folder), or grub2.cfg? What combinations? Commented Mar 9, 2023 at 10:48
  • A common one is /boot/grub2/grub.cfg Commented Mar 9, 2023 at 11:17

Debian Stretch:

Rather than messing around with config files, create a folder in /noot (call it what you want), leave the kernel you want, along with the matching config and system files, in /boot and move the rest to this new folder.

Run update-grub.

Double check the /boot folder that your kernel version and matching config and system files are are still there (in case you copied something you shouldn't have) and reboot.

  • 1
    I suspect this would not survive a kernel update (and neither would the method with the numbers).
    – Andyc
    Commented Feb 2, 2022 at 17:35
  • Although it's a simple quick-an-dirty solution, this is a very bad advice to do this way.
    – trolzen
    Commented Nov 23, 2022 at 10:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .