You are not logged in.

#1 2017-11-09 06:08:15

donutmtoazt
Member
Registered: 2017-11-09
Posts: 3

Proper way to modify the grub config?

So I'm looking for advice on the best way to modify the grub config generated by grub-mkconfig. I recently tried installing linux-hardened as a second kernel, but when I run the mkconfig command, it ends up outputting the hardened version as the default (first) choice, making me go down into a sub menu to find my normal kernel.

So I looked into /etc/grub.d/ and noticed that I have a file that generates the linux kernel portion of my grub.cfg, simply iterating through all the kernels in my boot folder that are named vmlinuz-*, and somehow the hardened version is being chosen first over the normal version.

So to the final question, whats the best practice for fixing this order issue? Should I modify the outputted grub.cfg file and rearrange the entries to match what I want? Or would it be better to modify/replace the handy file I have that collects the kernels for me?

Thanks for any help!

Offline

#2 2017-11-09 06:19:16

adesh
Member
Registered: 2016-10-05
Posts: 167

Re: Proper way to modify the grub config?

That's has something to do with how GRUB orders entries. As a workaround, you can tell GRUB to always save the last booted entry. This way the last entry will be automatically highlighted and booted into on the next reboot.

Offline

#3 2017-11-09 08:35:39

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,427

Re: Proper way to modify the grub config?

You can define a default entry, no need for workarounds https://wiki.archlinux.org/index.php/GR … menu_entry

Last edited by V1del (2017-11-09 08:36:06)

Offline

#4 2017-11-12 00:13:17

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Proper way to modify the grub config?

Or you could always write your grub.cfg by hand rather than relying on the obtuse autogenerated one. smile

It really is a lot easier than people think, which I mostly blame on grub-mkconfig. See for example: https://ptpb.pw/bAEg

Using a handwritten config means it is far, far easier to trivially modify it to look the way you want it to look, because (in the true Arch spirit) you actually understand what it is doing...


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2017-11-12 02:56:57

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,130

Re: Proper way to modify the grub config?

Eschwartz wrote:

Or you could always write your grub.cfg by hand rather than relying on the obtuse autogenerated one. smile

It really is a lot easier than people think, which I mostly blame on grub-mkconfig. See for example: https://ptpb.pw/bAEg

I also found it broke much less than the auto-configured one. (More-or-less never broke, except when I switched to LVM-on-LUKS because the wiki really is most unclear about what is needed on the kernel command line. Just needed to copy the stuff from a Fedora install, which is a bit backwards, but worked.)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#6 2017-11-12 06:04:31

verndog
Member
Registered: 2007-09-21
Posts: 55

Re: Proper way to modify the grub config?

I've been using my own 'grub.cfg' for years. Trying to read through the default generated 'grub.cfg' is tiring. Mine is about 1/4 the size.

Offline

#7 2017-11-23 18:04:38

donutmtoazt
Member
Registered: 2017-11-09
Posts: 3

Re: Proper way to modify the grub config?

Since the kernel name never changes when upgrading the kernel, I'm assuming it's safe to overwrite the grub.cfg unlike with ubuntu where the kernel name is versioned, ya?

My grub.cfg says DO NOT EDIT THIS FILE at the top, but I guess that's for systems that have mkconfig automatically run?

Offline

#8 2017-11-24 02:52:36

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,130

Re: Proper way to modify the grub config?

donutmtoazt wrote:

Since the kernel name never changes when upgrading the kernel, I'm assuming it's safe to overwrite the grub.cfg unlike with ubuntu where the kernel name is versioned, ya?

My grub.cfg says DO NOT EDIT THIS FILE at the top, but I guess that's for systems that have mkconfig automatically run?

If you write your own from scratch, you can make sure it doesn't tell you this.

Last edited by cfr (2017-11-24 02:52:47)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#9 2017-11-25 06:51:54

donutmtoazt
Member
Registered: 2017-11-09
Posts: 3

Re: Proper way to modify the grub config?

All right, thank you all for the help and the new direction. I'll start working on making my own grub config!

Offline

#10 2017-11-25 19:08:28

GrimBandito
Member
Registered: 2016-12-04
Posts: 41

Re: Proper way to modify the grub config?

donutmtoazt wrote:

So I'm looking for advice on the best way to modify the grub config generated by grub-mkconfig. I recently tried installing linux-hardened as a second kernel, but when I run the mkconfig command, it ends up outputting the hardened version as the default (first) choice, making me go down into a sub menu to find my normal kernel.

The standard procedure for me is to ONLY edit '/etc/default/grub' and save to apply any configuration changes for grub. Then like you do a 'grub-mkconfig -o /boot/grub/grub.cfg' which goes away and builds the new grub menu.

One of the problems with default setups for grub is the use of a submenu which, on adding multiple kernels does indeed mess with the default choice. Setting the default menu choice doesn't seem to work and is instead ignored.

One way to fix this behaviour is to edit '/etc/default/grub/' and disable the submenu by adding the following line:-

GRUB_DISABLE_SUBMENU=y

And now the default option works as intended again. Follow this with 'grub-mkconfig -o /boot/grub/grub.cfg' and your grub menu is rebuilt with no submenu and defaults to the kernel of your choice.

I currently use both the linux and linux-lts kernel packages installed which results in four grub menu entries (2x linux kernels + 2x fallbacks). You can also configure grub to remember your last choice (assuming you are not running root on BTRFS) which is a more flexible option.

Last edited by GrimBandito (2017-11-25 19:33:40)

Offline

#11 2017-11-25 19:35:47

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,680
Website

Re: Proper way to modify the grub config?

donutmtoazt wrote:

I'll start working on making my own grub config!

For your Ubuntu menu entries you can point to /vmlinuz (for the "linux" line) and /initrd.img  because Debian-based distributions maintain symlinks to those locations from the current running kernel — if this is done then you won't have to change the menu entry every time Ubunutu's kernel gets upgraded.

See the 'testbed' entry in my grub.cfg for an example:

https://raw.githubusercontent.com/Head- … r/grub.cfg

Offline

Board footer

Powered by FluxBB