Grub Customizer - a graphical grub2 settings manager

How does it work?

Created by Daniel Richter on on 2010-10-24
Keywords:
documentation backgrounds
Last updated by:
Daniel Richter on on 2011-04-26

First you should know, Grub Customizer doesn't create any initial configuration. So if you're starting it, but doing nothing and clicking the save button, Grub Customizer doesn't modify your configuration in any way (except of temporary modifications when loading the configuration which will be reset when its done).

Grub Customizer tries to do as much as possible in the usual way:

* disabling scripts: grub customizer removes the execute flag (same as chmod -x [SCRIPT])
* moving scripts: grub customizer generates new prefixes for the scripts to alternate its execution order

…but all the other things are not so easy to do:

* moving entries
* renaming entries
* disabling entries

To do this, grub customizer comes with an component called grubcfg_proxy. This is a binary[1] file which reads the script (such as os-prober) output from stdin and gets the modification rules by parameter 1. After reading all the script output, grub customizer executes the given rules and prints the customized output to stdin (which will be appended to the grub.cfg by update-grub). This binary file will not be generated for every script: It will be placed in a special directory and will be started by "proxy-scripts" which will be generated by grub customizer and placed at /etc/grub.d. Such a script looks like this:

#!/bin/sh
#THIS IS A GRUB PROXY SCRIPT
'/etc/grub.d/proxifiedScripts/linux' | /etc/grub.d/bin/grubcfg_proxy "+*
+'Ubuntu, mit Linux 2.6.32-25-generic' as 'Ubuntu 10.04'
-'Ubuntu, mit Linux 2.6.32-24-generic'

As you see, it executes the script (which has been moved the new subdirectory proxifiedScripts) and pipes its output to the proxy file followed by every rule. "+*" is the position where unruled (new) entries will be placed. Grub Customizer shows this Marker as "(new entries)" item. If you disbale it in grub customizer, there is "-*" instead which ignored all the newly generated entries. All the other entries have to use this syntax:
 * '+' or '-' (enabled or disabled)
 * The original name to identify the entry
 * optionally an " as " followed by its output name
 * any other letters, before the next "+" or "-" indicates the next rule begin

Grub Customizer only creates proxies, if you do anything of the features named above (and only the modified scripts). You can see this in Grub Customizer: there is a postfix " (custom)" behind the name of every script, which requires a proxy.

The subdirectories "bin" and "proxifiedScripts" will only be created, if them are required and automatically deleted, when you remove all the customizations using the grub customizer.

If you want to restore the scripts, redo every customization for the script in grub customizer. If this is too much work, click the remove button after selecting the script and then click the add button, choose the script and add it to the configuration. If you cannot use Grub Customizer, you can do it by using the command line too. Simply remove script relevant proxy script and move your script from the proxifiedScripts subdir to /etc/grub.d. After you removed every proxy script, you can delete bin/grubcfg_proxy too.

* Some other functionality:

 # Loading the configuration:

To load the configuration correctly, Grub Customizer activates every unproxified script and disables every proxy script. To get the proxyfiedScripts, it will add small forward scripts to execute then (they'll get the prefix "LS_"). Then it runs grub-mkconfig to read the configuration. When this is done, Grub Customizer restores the old configuration. When Grub Customizer dies in this progress (for example, if you kill it), it tries to repair the directory before reading the configuration.

 # Saving the configuration:

Grub Customizer writes all selected changes to proxyscripts and copies the grubcfg_proxy, if it isn't allready done. Then update-grub will be executed.

 # Installing grub to the mbr:

grub customizer runs grub-install.

 # Partition Chooser:

The partiton info will be loaded by executing blkid. When you click mount, the partition will be mounted on a special directory in /media. After applying this dialog, Grub Customizer uses chroot for commands like grub-install, grub-mkconfig or update-grub. So you will ever work on the correct file system.

 # Settings manager

The settings manager simply edits the file /etc/default/grub like a user would do.

----------------

[1] I decided to use a binary (compiled) file as proxy, because it has been much easier to develop for me and I can use the same code in proxy and the configuration interface. I know it's not a good idea to copy binary code to the configuration directory (not as portable)… so feel free to send me a bash script which does the same and I will use it instead of the binary file.