M01: Introduction to Operating Systems
TU1: Installing, configuring and exploiting a computer system
Pract. Exerc. 13 - GRUB: The Linux Boot Loader  18-04-17

Practical Exercise 13 - GRUB: The Linux Boot Loader

1- Deadline
ASIX1 (Catalan) --> 18-4-17

DAW1 (English) --> 20-4-17

2-Teachers will check that
your new GRUBS menus are working properly


1- Bootstrat or boot  process. MBR. Boot Loader. GRUB.
It is the process of loading an operating system into memory and starting it running without any outside help or assistance. If you are ruunig Linux, the following steps are taken in order to start the operating system:

st step) When  you turn on the computer, the CPU begins to carry out a set of instructions contained in the the BIOS. The first set of instructions is the POST (Power On Self  Test). The POST performs initial hardware checks such as determining if RAM memory,  mass storages devices or video card  are present in the system, the amount of RAM memory and so on. If an error is found, the  BIOS will warn us displaying a message on the screen or emitting a sequence of beeps, and the start up process will be stopped..

2nd step)
When the  POST process  finishes, instructions contained in  the BIOS make the  CPU load and start a very small program  called  Boot Loader, which is responsible for starting the process of loading and running the operating system.  The Boot Loader is part of the  Master Boot Record (MBR), which usually resides on the boot sector (also called zero sector) of a hard disk drive. Nowadays, the typical Linux Boot Loader is GRUB.

3rd step)
  The Boot Loader in MBR contains a small  part (called phase 1) of GRUB (Grand Unified Boot Loader).  Phase 1 loads  phase 2, which is the bulk of the Boot Loader and it is stored in the Linux partition  where resides  the /boot/grub directory.

4th step)
GRUB is a boot manager as well and therefore it will present a menu of posible boot options, which allows us to load differents kinds of operating system kernels (Windows, Linux, minix, BSD and so on) or different versions of  Linux kernels stored in the /boot directory of a disk partition. One you have selected an operating system from the menu, GRUB will be responsible for  locating the operating system kernel, loading it into memory and transferring control to the selected operating system kernel. The kernel, in turn, initializes the rest of the operating system (services, some drivers, etc...).  

2- Configuring the GRUB menu.

You can change  any aspect of the GRUB menu by:
    1st step) Editing the /etc/default/grub configurations file.
    2nd step) Renaming and changing permissions of special scripts located in
3rd step) Running update-grub. When update-grub is executed, the results are saved in  a file called /boot/grub/grub.cfg, which is the is the main GRUB file and  contains the menu information.. The  /boot/grub/grub.cfg should not be     edited manually and any change in this file should be made by update-grub, which for his part, combines the settings from the /etc/default/grub file and the scripts from /etc/grub.d, creating a /boot/grub/grub.cfg file that is read at boot.

2.1- /etc/default/grub
Changing the values of variables in the /etc/default/grub file allows you to modify many aspects of how the system boots and how GRUB displays its menu. Some of the most important variables are the following:
a) GRUB_DEFAULT: It specifies the ordinal  number of the default menu entry. Menu entries are numbered starting with 0 (0 specifies the first menu entry).
b) GRUB_TIMEOUT: It specifies the number of seconds GRUB waits before booting the operating system by default.
c) GRUB_DISABLE_RECOVERY: It specifies whether or not update-grub   generates recovery-mode menu entries. Commented out  by default. Default value is false, which means that entries are generated.
d) GRUB_TERMINAL: Enables (#GRUB_TERMINAL=console) or disables (
GRUB_TERMINAL=console)  the graphical menu.

does not evaluate a line that begin with a hasmark (#). These lines are comments.

2.2- /etc/grub.d
The files in this folder are read during execution of  the update-grub utility. The contents are imported into /boot/grub/grub.cfg. The order of the entries in the GRUB menu is based on the order of the file names. The order the files are run determines the menu order in grub.cfg. Some of the most important files are the following:
a) 00_header: It is the script that loads GRUB settings from /etc/default/grub, including timeout, default boot entry, and others.
b) 05_debian_theme: Sets the background and text colors themes.
c) 10_linux: It  loads the menu entries for the installed distribution. Creates a menu entry for each kernel in /boot. A kernel is specified by a file named vmlinuz-*.
d) 20_memtest86+: If the file /boot/memtest86+.bin (memory test utility) exists, it is included as a menu item.
e) 20_linux_xen: It loads xen linux kernels which are a special kind of virtual kernels.
f) 30_os-prober: It  is the script that will scan the hard disks for other operating systems (Windows, Linux on other partitions,....) and add them to the boot menu.
g) 40_custom: A template for adding custom menu entries.

a) Each of these files must be executable if you want update-grub to process it. If you do not want update-grub to process one of the files, remove the execute bits from the file.
b) All executable files are processed in order according to their number namespace

2.3- update-grub

A utility for updating /boot/grub/grub.cfg according to the contents of the /etc/default/grub file and files in the /etc/grub.d directory.

2.4.- /boot/grub/grub.cfg
The main GRUB file, which contains the GRUB menu information. This file is automatically changed or generated when update-grub is run.You should not edit this file.

3- External Links

(1) http://www.howtogeek.com/196655/how-to-configure-the-grub2-boot-loaders-settings/

(2) http://www.howtogeek.com/howto/17787/clean-up-the-new-ubuntu-grub2-boot-menu/
(3) http://ubuntuforums.org/showthread.php?t=1195275

  Create a new virtual machine using the DebUb.
2.- Make  Ubuntu, with Linux 3.2.0-29-generic-pae your first menu entry.
Read IMPORTANT NOTE b) in section 2.2.
.- Remove the Debian GNU/Linux, with 3.2.0-4-686-pae (recovery mode) boot menu entry.
4.- Make Debian GNU/Linux, with 3.2.0-4-686-pae  your boot operating system by default.
Configure GRUB for waiting 15 seconds before booting the operating system by default if no key is pressed.
6.- Disable the graphical menu for GRUB.
7.- Update GRUB.
8.- Check your new menu.  Boot your virtual machine with Ubuntu 12.04. Restart the system and boot your virtual machine with Debian 7.4.0.
9.- If your new configuration works then call me to correct your exercise.

Boot your virtual machine with Ubuntu. Remove  the Ubuntu, with Linux 3.2.0-29-generic-pae (recovery mode) boot menu entry:
    a) Change
GRUB_DISABLE_RECOVERY of /etc/default/grub on Ubuntu to modify the GRUB configuration file on Ubuntu.
    b) Run update-grub on Ubuntu in order to update the GRUB boot-loader on Ubuntu.

2.- Boot your
virtual machine with Debian machine. Change again GRUB_DEFAULT in or to make again Debian your operating system by default
3.- Update the GRUB boot-loader on Debian. Reboot your system.
Check your new menu. If your new configuration works then call us to correct your exercise. 

Make  Debian GNU/Linux, with 3.2.0-4-686-pae your first menu entry again and your boot operating system by default.
2.- Enable the graphical menu for GRUB.
.- If your new configuration works then call us to correct your exercise.

.- Hide the GRUB menu. HELP: Read (4) of External Links.
2.- If your new configuration works then call us to correct your exercise.

  Unhide the GRUB menu.
Configure GRUB for waiting 30 seconds before booting the operating system by default if no key is pressed.
Hide the Ubuntu entry. HELP: Read IMPORTANT NOTE a) in section 2.2.
2.- If your new configuration works then call us to correct your exercise.

1.- Return your bootloader (GRUB) to its initial conditions (that are conditions previous the start of this exercise).
2.- If your new configuration works then call us to correct your exercise.

1- The password for inf1 and root  on Debian is fjeclot.
The password for inf1 on Ubuntu is fjeclot.