What does Grub do?
GRUB is the first thing that runs at boot. It has the responsibility to set from where your system boots, enabling mutli-boot systems. It will also pass a number of parameters to your kernel which depend on the kernel you boot into. Except for making your chosen distribution boot correctly, you can also use a theme for GRUB. That is, if you want to keep even early boot look good.
Where do you store it?
In most cases, your distribution installer will place GRUB “where appropriate”, this is not always ideal. For UEFI systems, which is almost all modern ones, you have many more options to store GRUB. Since this is the boot loader, you first choose a device, most commonly /dev/sda1, then you can choose where modules can be stored. Ordinarily, you would leave all other boot files in the /boot directory but you may need more space so there is an option to move it elsewhere. The safest way to do this is to create a partition that you mount on /boot. Because of the many features of UEFI, you will also store a lot of information in the /boot/efi directory. This will most commonly be a partition that GRUB mounts during boot. In most cases, you will simply run the grub-install script without parameters.
The grub-install command is a script that looks through your disks and creates menu entries for every OS you have on your disc. This means it will create a chain-loading entry for Windows, if you have it on your disk. The ‘update-grub’ command does similar updates to your existing system. You can also create an ISO file where GRUB resides. You can use this to boot your machine in case you have problems with the current GRUB install.
Some basic settings
To adapt the behaviour of GRUB, you have a few standard settings. Let’s go through them. The GRUBDEFAULT value, usually zero, sets which is your most common entry to boot from. To use it, you set another numerical value or you can name your entry with the ‘id’ tag.
You have the option to set the latest chosen entry as the default. You do this by setting the parameter
You can also set the time it takes before GRUB boots into your default entry. Distributions put ten second for this value, you may want to set it lower when you feel that you will not tweak GRUB anymore.
This entry will set the timeout to 5 seconds.
The really interesting values are for how you boot your Linux system. You will not find the values in GRUB, instead you will need to look for them in the Linux kernel documentation. Some common values are:
|quiet||Disable all log messages|
|splash||Shows the splash images|
|rfkill.defaultstate=0||Make the default rfkill state open|
The list is long, you need to look for all of them in the kernel documentation.
Some interesting features
It may seem that all the boot-loader should do is boot the system, but you can have a few special things happen to GRUB.
There are several themes available for GRUB, so you can make the menu look nice. The package is grub2-splashimages in your favourite repository (Ubuntu, at least!). You can find many more themes at Gnome Look, oddly enough!
You may want to protect your machine from intruders by protecting the GRUB install it self. NOTE: If you do not, then someone can reboot your machine and use GRUBs command line to run your OS without password. Achieving root is very easy from GRUB. Having said that, if they have their machine then they can boot from a memory stick and gain access to your files any ways.
To protect GRUB from being changed by anyone who boots your computer, you can set a password. The procedure is simple, just add the password in the GRUB config.file
In the example you need a hashed password, to create it, use the below command
The command asks you for a password twice and returns the HASH that corresponds to your password.
Where do you find error logs?
Now that you have started changing in GRUB, you will need to check what happened with your changes. So where does GRUB leave its logs? You have two files to examine, as shown below. They contain different details,
/var/boot/log/boot.log This file contains many other data but you can see that the boot succeeded from GRUB.
/var/log/dmesg The ‘dmesg’ file is renewed each day and contains all the kernel parameters that you set during last boot. Very useful to see which values are set by the system.
How do you run it manually?
If you want to try out some settings and commands while it is booting, you can do so. From the GRUB menu, you can go into command line mode and set everything up for the current boot. Nothing will be saved so you will want to take notes while trying this out. The big advantage is that you will not change what GRUB will do on the next boot, so most commands can be cleared with a new reboot.
You can also consider the ‘grub-customizer’. This is a software package that writes to your GRUB files (/etc/grub.d/40custom). The Grub Customizer With this tool, you can change all values that you wish so be careful. Note that it does not have full documentation for GRUB so must figure out what you want to change from documentation.
When you dig into the documentation of GRUB, you will quickly see that choosing the correct file and partition to boot from is far from the only thing that GRUB does. If you dig deeper, you can make huge changes to your system. You can also render your system un-bootable. So always have backups and an alternative media to boot from.