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

Practical Exercise 13 - GRUB: The Linux Boot Loader

GENERAL CONDITIONS
1- Deadline Practical Exercise-I (Working with debian9v1)
ASIX1 (Catalan) -->  6-4-16.

DAW1 (English) --> 9-4-18 .

2- Deadline Practical Exercise-II (Working with debian9v1)
ASIX1 (Catalan) -->  13-4-16.

DAW1 (English) --> 16-4-18 .

2-Teachers will check that
your new GRUB menu is working properly


DOCUMENTATION

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:

1
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
/etc/grub.d.
   
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: It enables (#GRUB_TERMINAL=console) or disables (
GRUB_TERMINAL=console)  the graphical menu.
e) GRUB_DISABLE_SUBMENU: It disables ("y") or enables (with #) submenus.

IMPORTANT ---> GRUB
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.

IMPORTANT NOTES:
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.phpF?t=1195275
(4)
https://jamielinux.com/articles/2013/01/hide-grub-menu-fedora/

PRACTICAL EXERCISE - I (WORKING WITH THE debian9v1 VIRTUAL MACHINE)

FIRST PART
1.- Take note of the boot menu initial conditions.
2.-
Disable submenus
3
.- Configure GRUB for waiting 15 seconds before booting the operating system by default if no key is pressed.
4.- Disable the graphical menu for GRUB.
5.- Update GRUB.
6.- If your new configuration works then call us to correct your exercise.

SECOND PART
1.- 
Make the  Debian GNU/Linux, with 4.9.0-3-amd64 (recovery mode) your default menu entry.
2.- Update GRUB.
3.- If your new configuration works then call us to correct your exercise.

THIRD PART
1.- 
Make the  Debian GNU/Linux, with 4.9.0-3-amd64 your default menu entry.
2.-infin Remove the Debian GNU/Linux, with 4.9.0-3-amd64 (recovery mode) entry.
3.- Update GRUB.
4.- If your new configuration works then call us to correct your exercise.

FOURTH PART
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.

FIFTH PART
1.- Disable the GRUB background theme
2.- If your new configuration works then call us to correct your exercise.


PRACTICAL EXERCISE - II (WORKING WITH THE grub VIRTUAL MACHINE)

NOTES:
1- The password for inf1 and root  on Debian is fjeclot.
2-
The password for inf1 on Ubuntu is fjeclot.
3-
The password for Administrador on Windows 2012 Server is Fjeclot2018.

FIRST PART
1.- Take note of the boot menu initial conditions.
2.-
Disable submenus
3
.- Configure GRUB for waiting 20 seconds before booting the operating system by default if no key is pressed.
4.- Disable the graphical menu for GRUB.
5.- Remove Debian recovery mode entry.
6.- Update GRUB.
7.- If your new configuration works then call us to correct your exercise.

SECOND PART
1.- 
Make  Windows your first menu entry, Ubuntu your 2nd to 5th menu entries and Debian your last menu entry.
2.- Make Ubuntu (on /dev/sda5) your default menu entry.
3.- If your new configuration works then call us to correct your exercise.

THIRD PART
1.-
 
Boot your virtual machine with Ubuntu. Remove  the Ubuntu 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. Update the GRUB boot-loader on Debian. Reboot your system.
3.-
Check your new menu. If your new configuration works then call us to correct your exercise.

FOURTH PART
1.-
 
Boot your virtual machine with Ubuntu.
2.- Install the Ubuntu GRUB as the main boot loader and manager on your hard disk. Run grub-install /dev/sda and reboot your computer.
3.- Check if the Ubuntu GRUB boot loader and manager is now in charge of your boot menu . If your new configuration works then call us to correct your exercise.

FIFTH PART
1.- Disable submenus for the Ubuntu menu.
2
.- Disable the Memory test entries for the Ubuntu menu.
3.- Disable the Windows and Debian entries for the Ubuntu menu.
4.- If your new configuration works then call us to correct your exercise.

SIXTH PART
1.- Hide the Ubuntu menu. HELP: Read (4) of External Links.
2.- At system boot, the menu can not be accessed by pressing <Esc>. HELP: Read (4) of External Links.
3.- If your new configuration works then call us to correct your exercise.

SEVENTH PART
1.- Return your Ubuntu menu to its initial conditions.
2.- If your new configuration works then call us to correct your exercise.

EIGHTH PART
1.-  Boot your virtual machine with Debian.
2.- Return your Debian menu to its initial conditions.
3.- Install the Debian GRUB as the main boot loader and manager on your hard disk.
4.- If your new configuration works then call us to correct your exercise.

NINTH PART
1.- Modify the Windows menu entry. Change "Windows Recovery Environment   (a /dev/sda1)"  to "Window 2012 Server".
2.-
If your new configuration works then call us to correct your exercise.

TENTH
1.-
  Boot your virtual machine with Debian.
2
.- Run update-grub and return your Debian menu to its initial conditions again.
3.-
If your new configuration works then call us to correct your exercise.