DEV Community

Cover image for Maintenance free system multi booting
suntong
suntong

Posted on • Updated on

Maintenance free system multi booting

The journey continues

First, recap from the previous article, a single grub boot menu entry can be as simple as:

With it, we don't need to hunt for the UUIDs, and we don't need to remember to mount boot partition and update the boot entries any more. It can boot to whatever latest kernel it is, and it will still work even we reformat the partition and install a new Linux, and it will still work even we change the distro from Debian, to Mint, Arch, Fedora, or openSUSE etc.

In this article, we'll first look at those few more boilerplates that enable you to only write the above few lines and everything will work out magically. Then we'll move on to how to make things even simpler, with the help of easygen.

The supporting files

To break free from the rigid format requirement of 40_custom and allow people only write the above few lines, or to order boot entries in the order we want, instead of being determined by their partition orders, we need to build our grub.cfg file from ground up ourselves. And, it is not that scary either and could be really straightforward. Here are all the code it needs:

The grub.cfg file that replace grubs default .cfg file. Deliberately made so simple so that it can be easily restored if it was accidentally overwritten.

The grub-main.cfg that the grub.cfg file actually calls. The idea comes from grml. We can see that it is sourcing a header, a footer, and the main/real .cfg files, like the entry shown above.

Arrange those .cfg files so that their order show up in the order you want in the grub menu. For example, this is how I arrange my grub menu:

image

I.e., in my preference, I want my grub menu to be in the order of:

  • My current Linux
  • Live Linux from ISO, in case I need to check/repair anything
  • My Windows
  • My old Linux versions

They are ordered from most probably used to the least probably used. Changing the order is simple, just shift them around in the .cfg text file.

The grub menu's look-and-feel is defined in the header, and the "Shutdown / Reboot" is defined in footer, showing below respectively.

ISO Booting

The bonus and prestige of the whole article, here is how ISO files are automatically discovered and listed:

It can automatically discover and list whatever ISO available on disk:

image

and boot from them:

image

The red background color is chosen for the grub menu, to symbolize the live system, and also as the notification sign that this will be the last grub menu level, after which the system will be in booting mode.

Can it be even simpler

So far, we can see that using some simple scripts/configs, we can let the grub to show whatever we want it to show, in whatever order we want as well. Now,

Can it be even simpler?

As pointed out in the "Conclusion" section in the last article, the only things that matter in a grub menu entry are the 'Debian GNU/Linux' and the 'hd0,gpt2', the rest are just the boilerplate that don't normally need to be changed.

What if I only want to specify the 'Debian GNU/Linux' and the 'hd0,gpt2' part, and let the machine to generate the grub menu entry/entries for me? -- Not a problem, if with the help of easygen.

This is all what you need to specify:

Feed that to easygen as:

easygen os2grub-1

then you'll get:

The secret is the easygen's template:

Customize it to whatever you like.

But, most people not just has a single boot menu. How do you deal with that? Simple -- with another small tool of grub2yaml.sh:

Just run it with

grub2yaml.sh /boot/grub/grub.cfg | tee /tmp/myOSs.cfg

Slightly edit it, and you'll get more entries like this:

With multiple entries like that, easygen really starts to shine. You can get the following without a drop of sweat:

Enjoy

IMHO, the way grub2 generates boot entries automatically, at least as of this article is written, is still a big mess. You may not agree with that, but I do enjoy my grub menu system to be plain and simple, straightforward and out of my way. And, I enjoy my freedom to hand-craft my own boot menus again, just like the good old days, but without an extra spare letter to waste.

Hope you enjoy that as well.

Cheers

Top comments (0)