Linux Format - UK (2019-12)

(Antfer) #1
74 LXF257 December 2019 http://www.linuxformat.com

TUTORIALS Customising GRUB


loopback loop /ubuntu.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/
filename=/ubuntu.iso splash --
initrd (loop)/casper/initrd.lz
}
This code first opens the ISO file in a loopback
device and then hand parameters to the Linux kernel
and initrd files. You can use any ISO file with the same
settings; just make sure you have the files inside your
ISO file. Each distribution has its own needs but you can
check the ISO before you start, or even read it using
GRUBs built-in commands. One caveat is that you need
to install grub-imageboot on the system you are booting
from. In the default configuration, there are five
parameters (out of many more):
GRUB_DEFAULT=0 sets which entry in the table is
executed when the user does not intervene.
GRUB_TIMEOUT=10 sets the default time to wait
before booting automatically.
GRUB_DISTRIBUTOR=’lsb_release -i -s 2> /dev/null ||
echo Debian’ shows the distribution you use.
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
sets how Linux boots – in this case, without showing
text and showing a splash screen.
GRUB_CMDLINE_LINUX=”” Here you can set special
commands you want to run to set up your kernel boot.
The other ones are useful for handling odd screens and
preparing the kernel for bad memory.

Kernel parameters
The more common Linux kernel parameters are quiet
splash ro. If you want to know what is going on during
boot, remove quiet so you can see the bootup text.
Other things you may need to change are memory-
related stuff and graphics card info. You can set vga
in case you have a problem seeing the boot. Values are
the resolution for your screen, seldom used in x86_64
scenarios. video sets the frame buffer resolution during
boot. panic sets the delay before the kernel reboots at
a panic. You can set this value to negative so that you
get reboots immediately on a panic. gpt forces the
kernel to uses any valid GPT signature so you don’t
read MBR from any disks.
The Linux command loads the kernel and prepares
all the parameters; next, initrd sets its parameters and
loads itself. Once you have loaded everything, you run
the boot command. First, you pick the kernel from the
disk; usually, this is named vmlinuz-x.y.z-amd64. Next
you pick the root partition to boot from. Finally, you
choose the file system to be read-only. The file system
will be set to read-write as soon as the boot is finished.
Some other values you can choose include rootflags
to set the root filesystem flags, and init to choose
another init system. This is especially useful if you want
to try out sinit, for example, without changing your
existing system.
Here, you can also set the swap device to return
from when you resume from hibernating, with
resume=/<swap-device>. The list is long, so study the
kernel manual for more info.

File structure
When you want to change your configuration, you need
to change some files. GRUB uses a set of files that are
compiled by update_grub, so if you want to stay with

hard disk. However, there are many other ways to fetch
the image and also more places to fetch it from. With
the correct configuration files, you can boot from USB
using GRUB. It also supports iPXE so you can boot from
the network. When you are booting many operating
systems, you may need to chain-load them. This is
usually the case with Windows. Chain loading means
that GRUB sets the root and hands over control to the
next actor – it does not pass any parameters to it. In
the case of a Linux kernel, you pass kernel and initrd
parameters to it to help run the system.
When you are testing out stuff, you may want to use
an ISO file to get started. Most distributions come as an
ISO file intended to be copied to a USB disk and then
used to install it to the system. You can choose to run
the ISO from the disk; all you need to do is open it with
loopback before you set the values to boot. The boot
will then act as if you booted from external media. Since
you can edit an ISO, you can change the ISO file to suit
your needs; this is a useful way to prepare a
deployment ISO with a special configuration.
Place the ISO file in a directory that GRUB can reach


  • anywhere except an encrypted data partition. You
    then rewrite your GRUB configuration to point to the
    ISO file:
    menuentry “Run Ubuntu Live ISO” {


If you want a
really small and
fast boot, cut
out everything,
even GRUB. The
systemd-boot is
text-only, only
offers very few
options but the
boot is very fast.

MAKING GRUB PRETTY


When you start your computer, GRUB flashes by too quickly for most
users, so the look of its boot screen is plain. If you do want to have a
nice screen (see the LXFDVD for an example), you can add a theme.
The structure is simple: all files need to be put in /boot/grub/
themes/<theme-name>.
You need one file in this directory named theme.txt and all
pictures you need for your theme. To use the theme, add GRUB_
THEME=/boot/grub/themes/<theme-name> to your /etc/default/
grub and GRUB will use it. The file itself points to your graphical
resources; images and icons must be in PNG format. Most of the
items are easy to understand, though you will probably need to
experiment to make it look good.
An alternative is the grub-customizer, a small graphical tool to
define how your GRUB appears and what you want to be included.
This tool is delivered in most distributions by default so just install it
with your regular package manager.
If you just want a nicer background, there are splash images under
Ubuntu. The package manager puts the files in /usr/share/images/
grub/. Once you have the files, add the GRUB_BACKGROUND
parameter, pointing to the file with the full path.
Depending on your configuration, you may need to move the file to
the boot directory.

In grub-
customizer,
imported themes
are unpacked so
you can easily
study how they
are structured.

74 LXF257December 2019 7772Decmbr 019t2a 1


TUTORIALS Customising GRUB


loopback loop /ubuntu.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/
filename=/ubuntu.iso splash --
initrd (loop)/casper/initrd.lz
}
This code first opens the ISO file in a loopback
device and then hand parameters to the Linux kernel
and initrd files. You can use any ISO file with the same
settings; just make sure you have the files inside your
ISO file. Each distribution has its own needs but you can
check the ISO before you start, or even read it using
GRUBs built-in commands. One caveat is that you need
to install grub-imageboot on the system you are booting
from. In the default configuration, there are five
parameters (out of many more):
GRUB_DEFAULT=0 sets which entry in the table is
executed when the user does not intervene.
GRUB_TIMEOUT=10 sets the default time to wait
before booting automatically.
GRUB_DISTRIBUTOR=’lsb_release -i -s 2> /dev/null ||
echo Debian’ shows the distribution you use.
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
sets how Linux boots – in this case, without showing
text and showing a splash screen.
GRUB_CMDLINE_LINUX=”” Here you can set special
commands you want to run to set up your kernel boot.
The other ones are useful for handling odd screens and
preparing the kernel for bad memory.

Kernel parameters
The more common Linux kernel parameters are quiet
splash ro. If you want to know what is going on during
boot, remove quiet so you can see the bootup text.
Other things you may need to change are memory-
related stuff and graphics card info. You can set vga
in case you have a problem seeing the boot. Values are
the resolution for your screen, seldom used in x86_64
scenarios. video sets the frame buffer resolution during
boot. panic sets the delay before the kernel reboots at
a panic. You can set this value to negative so that you
get reboots immediately on a panic. gpt forces the
kernel to uses any valid GPT signature so you don’t
read MBR from any disks.
The Linux command loads the kernel and prepares
all the parameters; next, initrd sets its parameters and
loads itself. Once you have loaded everything, you run
the boot command. First, you pick the kernel from the
disk; usually, this is named vmlinuz-x.y.z-amd64. Next
you pick the root partition to boot from. Finally, you
choose the file system to be read-only. The file system
will be set to read-write as soon as the boot is finished.
Some other values you can choose include rootflags
to set the root filesystem flags, and init to choose
another init system. This is especially useful if you want
to try out sinit, for example, without changing your
existing system.
Here, you can also set the swap device to return
from when you resume from hibernating, with
resume=/<swap-device>. The list is long, so study the
kernel manual for more info.

File structure
When you want to change your configuration, you need
to change some files. GRUB uses a set of files that are
compiled by update_grub, so if you want to stay with

hard disk. However, there are many other ways to fetch
the image and also more places to fetch it from. With
the correct configuration files, you can boot from USB
using GRUB. It also supports iPXE so you can boot from
the network. When you are booting many operating
systems, you may need to chain-load them. This is
usually the case with Windows. Chain loading means
that GRUB sets the root and hands over control to the
next actor – it does not pass any parameters to it. In
the case of a Linux kernel, you pass kernel and initrd
parameters to it to help run the system.
When you are testing out stuff, you may want to use
an ISO file to get started. Most distributions come as an
ISO file intended to be copied to a USB disk and then
used to install it to the system. You can choose to run
the ISO from the disk; all you need to do is open it with
loopback before you set the values to boot. The boot
will then act as if you booted from external media. Since
you can edit an ISO, you can change the ISO file to suit
your needs; this is a useful way to prepare a
deployment ISO with a special configuration.
Place the ISO file in a directory that GRUB can reach


  • anywhere except an encrypted data partition. You
    then rewrite your GRUB configuration to point to the
    ISO file:
    menuentry “Run Ubuntu Live ISO” {


If youwanta
reallysmalland
fastboot,cut
outeverything,
evenGRUB.The
systemd-bootis
text-only,only
offersveryfew
optionsbutthe
bootisveryfast.

MAKINGGRUBPRETTY


When you start your computer, GRUB flashes by too quickly for most
users, so the look of its boot screen is plain. If you do want to have a
nice screen (see the LXFDVD for an example), you can add a theme.
The structure is simple: all files need to be put in /boot/grub/
themes/<theme-name>.
You need one file in this directory named theme.txt and all
pictures you need for your theme. To use the theme, add GRUB_
THEME=/boot/grub/themes/<theme-name> to your /etc/default/
grub and GRUB will use it. The file itself points to your graphical
resources; images and icons must be in PNG format. Most of the
items are easy to understand, though you will probably need to
experiment to make it look good.
An alternative is the grub-customizer, a small graphical tool to
define how your GRUB appears and what you want to be included.
This tool is delivered in most distributions by default so just install it
with your regular package manager.
If you just want a nicer background, there are splash images under
Ubuntu. The package manager puts the files in /usr/share/images/
grub/. Once you have the files, add the GRUB_BACKGROUND
parameter, pointing to the file with the full path.
Depending on your configuration, you may need to move the file to
the boot directory.

In grub-
customizer,
imported themes
are unpacked so
you can easily
study how they
are structured.
Free download pdf