# New Grub option GRUB\_TOP\_LEVEL

**URL:** <https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007>\
**Category:** Applications\
**Created:** [November 17, 2022, 7:03pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007 "2022-11-17T19:03:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![petsam](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/petsam/32/41308_2.png) [@petsam](https://forum.endeavouros.com/u/petsam)\
**Post date:** [November 17, 2022, 7:03pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/1 "2022-11-17T19:03:42Z")

</div>

The [latest grub update introduces new options](https://git.savannah.gnu.org/cgit/grub.git/commit/?id=62037e01b296fe772c1724343cf75b75ea52e220), to explicitly select an entry of the installation (among linux, linux-lts, linux-zen etc) being at the top level of the menu. In case you use submenus, the selected entry is the one in the front/main page, while it is also at the top in the Advanced menu entries page.

> A user may wish to use an image that is not sorted as the “latest”  
> version as the top-level entry. For example, in Arch Linux, if a user  
> has the LTS and regular kernels installed, “/boot/vmlinuz-linux-lts”  
> gets sorted as the “latest” compared to “/boot/vmlinuz-linux”, meaning  
> the LTS kernel becomes the top-level entry. However, a user may wish to  
> use the regular kernel as the top-level default with the LTS only  
> existing as a backup.
> 
> This need can be seen in Arch Linux’s AUR with two user-submitted packages ([grub-linux-default-hook](https://aur.archlinux.org/packages/grub-linux-default-hook), [grub-linux-rt-default-hook](https://aur.archlinux.org/packages/grub-linux-rt-default-hook)) providing an update hook which patches /etc/grub.d/10\_linux to move the desired kernel to the top-level. This patch serves to solve this in a more generic way.
> 
> Introduce the GRUB\_TOP\_LEVEL, GRUB\_TOP\_LEVEL\_XEN and GRUB\_TOP\_LEVEL\_OS\_PROBER variables to allow users to specify the top-level entry.
> 
> Create grub\_move\_to\_front() as a helper function which moves entries to the front of a list. This function does the heavy lifting of moving the menu entry to the front in each script.
> 
> In 10\_netbsd, since there isn’t an explicit list variable, extract the items that are being iterated through into a list so that we can optionally apply grub\_move\_to\_front() to the list before the loop.

* * *

The online grub manual is not updated with these options (as we are following grub git master branch 😉 )  
The relevant change in the manual is this:

> GRUB\_TOP\_LEVEL  
> GRUB\_TOP\_LEVEL\_XEN
> 
> This option should be an absolute path to a kernel image. If provided, the image specified will be made the top-level entry if it is found in the scan.

> GRUB\_TOP\_LEVEL\_OS\_PROBER
> 
> This option should be a line of output from `os-prober`. As GRUB\_TOP\_LEVEL, if provided, the image specified will be made the top-level entry if it is found in the scan.

* * *

For example (as tested), you can add this line in `/etc/default/grub`, to set Linux main kernel at the top of the menu list:

```auto
GRUB_TOP_LEVEL="/boot/vmlinuz-linux"

```

Re-create grub configuration to apply the changes:

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

```

I haven’t tested the os-prober option, but I assume it would be something like this (it’s copied from `sudo os-prober` output):

```auto
GRUB_TOP_LEVEL_OS_PROBER="/dev/sda8:Archcraft (rolling):archcraft:linux"

```

---

<div class="post-metadata">

**Author:** ![manuel](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/manuel/32/396_2.png) [@manuel](https://forum.endeavouros.com/u/manuel)\
**Post date:** [November 17, 2022, 8:38pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/2 "2022-11-17T20:38:33Z")

</div>

> [@petsam](#):
>
> `GRUB_TOP_LEVEL="/boot/vmlinuz-linux"`

This seems to be working with btrfs as well. 😄

---

<div class="post-metadata">

**Author:** ![arcDaniel](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/arcdaniel/32/67569_2.png) [@arcDaniel](https://forum.endeavouros.com/u/arcDaniel)\
**Post date:** [November 18, 2022, 5:34am UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/3 "2022-11-18T05:34:33Z")

</div>

Why shouldn’t it? There is no writing from grub itself.

---

<div class="post-metadata">

**Author:** ![manuel](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/manuel/32/396_2.png) [@manuel](https://forum.endeavouros.com/u/manuel)\
**Post date:** [November 18, 2022, 11:38am UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/4 "2022-11-18T11:38:05Z")

</div>

Yeah, and it works around the problem of not being able to use GRUB\_SAVEDEFAULT with btrfs.

---

<div class="post-metadata">

**Author:** ![anon50380917](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/b9bd4f/32.png) [@anon50380917](https://forum.endeavouros.com/u/anon50380917)\
**Post date:** [November 18, 2022, 12:04pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/5 "2022-11-18T12:04:24Z")

</div>

Should I put the line first, or does it matter:

```auto
# GRUB boot loader configuration

GRUB_TOP_LEVEL="/boot/vmlinuz-linux"
GRUB_DEFAULT=0
GRUB_TIMEOUT=3
GRUB_DISTRIBUTOR="EndeavourOS"
GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=48bae162-f72c-460e-b78e-dc2999154904 loglevel=3 nowatchdog nvme_load=YES"
GRUB_CMDLINE_LINUX=""

```

And what would be the entry for the latest LTS kernel then?

```auto
GRUB_TOP_LEVEL="/boot/vmlinuz-linux-lts"

```

?

---

<div class="post-metadata">

**Author:** ![manuel](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/manuel/32/396_2.png) [@manuel](https://forum.endeavouros.com/u/manuel)\
**Post date:** [November 18, 2022, 2:33pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/6 "2022-11-18T14:33:41Z")

</div>

I tested very shortly, added GRUB\_TOP\_LEVEL as you wrote. That worked.  
Then I also commented out GRUB\_DEFAULT. It worked too.

So simply testing will tell what works and what not.  
Tip: better do this testing in a virtual machine first. 😉

---

<div class="post-metadata">

**Author:** ![petsam](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/petsam/32/41308_2.png) [@petsam](https://forum.endeavouros.com/u/petsam)\
**Post date:** [November 18, 2022, 3:07pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/7 "2022-11-18T15:07:47Z")

</div>

> [@anon50380917](#):
>
> Should I put the line first, or does it matter:

It doesn’t matter. `/etc/default/grub` is just a list of environment variables. The order is irrelevant. If the same variable is entered more than once, the last one is in effect.

> [@anon50380917](#):
>
> `GRUB_TOP_LEVEL="/boot/vmlinuz-linux-lts"`

Looks OK.

> [@manuel](#):
>
> I also commented out GRUB\_DEFAULT. It worked too.

In case of a misunderstanding, the new setting is not replacing or affecting the behavior of GRUB\_DEFAULT, AFAIK and IIUC.

GRUB\_DEFAULT selects/sets the default boot entry (highlighted).  
GRUB\_TOP\_LEVEL re-orders the list of entries in the menu.

> [@petsam](#):
>
> For example, in Arch Linux, if a user  
> has the LTS and regular kernels installed, “/boot/vmlinuz-linux-lts”  
> gets sorted as the “latest” compared to “/boot/vmlinuz-linux”, meaning  
> the LTS kernel becomes the top-level entry. However, a user may wish to  
> use the regular kernel as the top-level default with the LTS only  
> existing as a backup.

On a non-BTRFS system, if `GRUB_DEFAULT=saved`, the default (highlighted) boot entry would be the previously booted one.

On BTRFS, the grub environment file is not writable on boot, so the last booted entry cannot be saved. That’s why GRUB\_DEFAULT is always used, no matter which entry was previously booted in.

---

<div class="post-metadata">

**Author:** ![manuel](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/manuel/32/396_2.png) [@manuel](https://forum.endeavouros.com/u/manuel)\
**Post date:** [November 18, 2022, 4:39pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/8 "2022-11-18T16:39:19Z")

</div>

Thanks for the detailed explanation.

What I meant with GRUB\_DEFAULT is that obviously its default value is 0 if not set in /etc/default/grub.

And the new GRUB\_TOP\_LEVEL is a great feature. Helps making easy to set the default entry also on btrfs.

---

<div class="post-metadata">

**Author:** ![anon11595408](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@anon11595408](https://forum.endeavouros.com/u/anon11595408)\
**Post date:** [November 19, 2022, 3:41pm UTC](https://forum.endeavouros.com/t/new-grub-option-grub-top-level/34007/9 "2022-11-19T15:41:16Z")

</div>

Had to bookmark this post for my Fedora Rawhide installation (daily new kernels).

Thanks a bunch, petros\_mou! 👍
