http://www.techradar.com/pro/linux December 2019 LXF257 75
Customising GRUB TUTORIALS
your distribution, you need to change only specific files.
The most common file to change is /etc/default/
grub, in which you can set the delays and other defaults
mentioned earlier.
The other directory you need to know about is /etc/
grub.d/, which contains files that update-grub uses to
compile the final settings. For interest, the final file is
/boot/grub/grub.cfg. This file is created by your
scripts and you should not edit it. When you have
special requirements, such as starting from an ISO
file, you can use a file in /etc/grub.d/.
Using /etc/grub.d/
Filenames in this directory start their names with
numbers, a system inherited from Sysv init. The files
are handled in numerical order and some are reserved,
while others you can use.
The files starting with 00, 10 and 20 are reserved. If
you want to add another OS, you can use 01, 11 and so
on to define the order in which they are placed in the
boot menu. The best place to place your changes is to
leave them in 40_custom, since this is the convention.
If you want to change the look of GRUB, you can use
/etc/default/grub to add a background image. You
need to point to the image file and run the update-grub
command. The code is simple since there is already a
keyword for it.
GRUB_BACKGROUND=”/usr/share/images/grub/
Windbuchencom.png”
This will only change your background to a nice
winter background. You need to be careful though –
you may not be able to read the menu entries if you
have the wrong colour of background. To make sure
you can read what GRUB tells you, try a theme
instead. To install a theme, you need the files of all the
fonts available to GRUB. The safest place is under /
boot/grub/themes/. This directory is not there by
default, so may need to add it. You can find a theme on
http://www.gnome-look.org. Once the files are there, you
need to add the theme to your configuration. Add the
below code to your /etc/default/grub.
GRUB_GFXMODE=1280x760
GRUB_BACKGROUND=/boot/grub/themes/
AgeOfSystems/background.png
GRUB_THEME=/boot/grub/themes/<folder>/theme.txt
The first value sets the resolution of the GRUB
screen, and the next sets the background. The last one
is a link to the theme.txt file. This contains code similar
to CSS but with the elements of a GRUB screen.
During boot, you can stop GRUB and try out the
commands that you will later set in your grub.cfg. A
good tip is to try this out in a virtual machine to get the
hang of it. Any script GRUB needs to have support for
filesystems and procedures to load the specific system.
The script first loads the modules GRUB requires.
This usually means loading filesystem modules. To get
access to the command line, you stop GRUB from
continuing and then press C. You can print all
commands with the help command and you have
command completion using the Tab key. If you have an
odd filesystem, you will need to load a module for that.
To load the ext2 filesystem, use:
$ insmod ext2
The system can now use ext2 to find your files. Note
that the module is called with the name, not including
the ‘mod’ extension.
List what partitions you have with ls. You can also
find devices that have the boot value set using the
search command. There are many parameters
available so you can choose the one whose system you
are trying to start. The most robust way is to use this to
pick a UUID to boot from. With the set parameter in
the search command, you can then set root to that
value, like so:
$ search --fs-uuid <device id> --set root
You can then use the root variable in your linux
command:
$ linux /boot/vmlinuz-5.0.0-32-generic root=root
After that, you load your initial ramdisk with the
initrd image of your choosing, if necessary.
$ initrd /boot/initrd.img-5.0.0-32-generic
This provides an initial filesystem to boot from,
useful in most cases as it loads in a fast, compact initial
root filesystem. rEFInd is the most similar alternative to
GRUB, but it’s made especially for UEFI so does not
support BIOS.
You can also make your system boot directly into the
Linux kernel. To achieve this, you need to have a kernel
with the efi-stubloader compiled into it. This is usually
the case in regular distributions.
Most of us won’t change the boot very often. In fact,
who needs to boot at all, with sleep and hibernate
features? However, when we want a special setup, it is
wise to investigate what options there are. If you are
dead-set on using only one kernel and distribution, you
should set your machine to boot straight into the kernel
as it will reduce boot times.
BOOT US INTO YOUR LIFE Subscribe now at http://bit.ly/LinuxFormat
While booting,
GRUB has test
commands built-in.
One of these is a
graphics test
that shows you
the capabilities
of text and colour
for your setup.
When you
install grub2-
splashimages,
they end up in
‘/usr/share/
images/grub’. One
of them has a nice
frozen tree.
7772Decmbr rb2c019tb09aksyo December 2019 LXF257 75
Customising GRUB TUTORIALS
your distribution, you need to change only specific files.
The most common file to change is /etc/default/
grub, in which you can set the delays and other defaults
mentioned earlier.
The other directory you need to know about is /etc/
grub.d/, which contains files that update-grub uses to
compile the final settings. For interest, the final file is
/boot/grub/grub.cfg. This file is created by your
scripts and you should not edit it. When you have
special requirements, such as starting from an ISO
file, you can use a file in /etc/grub.d/.
Using /etc/grub.d/
Filenames in this directory start their names with
numbers, a system inherited from Sysv init. The files
are handled in numerical order and some are reserved,
while others you can use.
The files starting with 00, 10 and 20 are reserved. If
you want to add another OS, you can use 01, 11 and so
on to define the order in which they are placed in the
boot menu. The best place to place your changes is to
leave them in 40_custom, since this is the convention.
If you want to change the look of GRUB, you can use
/etc/default/grub to add a background image. You
need to point to the image file and run the update-grub
command. The code is simple since there is already a
keyword for it.
GRUB_BACKGROUND=”/usr/share/images/grub/
Windbuchencom.png”
This will only change your background to a nice
winter background. You need to be careful though –
you may not be able to read the menu entries if you
have the wrong colour of background. To make sure
you can read what GRUB tells you, try a theme
instead. To install a theme, you need the files of all the
fonts available to GRUB. The safest place is under /
boot/grub/themes/. This directory is not there by
default, so may need to add it. You can find a theme on
http://www.gnome-look.org. Once the files are there, you
need to add the theme to your configuration. Add the
below code to your /etc/default/grub.
GRUB_GFXMODE=1280x760
GRUB_BACKGROUND=/boot/grub/themes/
AgeOfSystems/background.png
GRUB_THEME=/boot/grub/themes/
The first value sets the resolution of the GRUB
screen, and the next sets the background. The last one
is a link to the theme.txt file. This contains code similar
to CSS but with the elements of a GRUB screen.
During boot, you can stop GRUB and try out the
commands that you will later set in your grub.cfg. A
good tip is to try this out in a virtual machine to get the
hang of it. Any script GRUB needs to have support for
filesystems and procedures to load the specific system.
The script first loads the modules GRUB requires.
This usually means loading filesystem modules. To get
access to the command line, you stop GRUB from
continuing and then press C. You can print all
commands with the help command and you have
command completion using the Tab key. If you have an
odd filesystem, you will need to load a module for that.
To load the ext2 filesystem, use:
$ insmod ext2
The system can now use ext2 to find your files. Note
that the module is called with the name, not including
the ‘mod’ extension.
List what partitions you have with ls. You can also
find devices that have the boot value set using the
search command. There are many parameters
available so you can choose the one whose system you
are trying to start. The most robust way is to use this to
pick a UUID to boot from. With the set parameter in
the search command, you can then set root to that
value, like so:
$ search --fs-uuid <device id> --set root
You can then use the root variable in your linux
command:
$ linux /boot/vmlinuz-5.0.0-32-generic root=root
After that, you load your initial ramdisk with the
initrd image of your choosing, if necessary.
$ initrd /boot/initrd.img-5.0.0-32-generic
This provides an initial filesystem to boot from,
useful in most cases as it loads in a fast, compact initial
root filesystem. rEFInd is the most similar alternative to
GRUB, but it’s made especially for UEFI so does not
support BIOS.
You can also make your system boot directly into the
Linux kernel. To achieve this, you need to have a kernel
with the efi-stubloader compiled into it. This is usually
the case in regular distributions.
Most of us won’t change the boot very often. In fact,
who needs to boot at all, with sleep and hibernate
features? However, when we want a special setup, it is
wise to investigate what options there are. If you are
dead-set on using only onekerneland distribution, you
should set your machine tobootstraight into the kernel
as it will reduce boot times.
BOOT US INTO YOUR LIFE Subscribe now at http://bit.ly/LinuxFormat
While booting,
GRUB has test
commands built-in.
One of these is a
graphics test
that shows you
the capabilities
of text and colour
for your setup.
When you
install grub2-
splashimages,
they end up in
‘/usr/share/
images/grub’. One
of them has a nice
frozen tree.