M01: Introduction to Operating Systems
TU1: Installing, configuring and exploiting a computer system
ASIX1
Pract. Exerc. 12 - GRUB: The Linux Boot Loader  24-3-14

Practical Exercise 12 - GRUB: The Linux Boot Loader

GENERAL CONDITIONS
1- Deadline: 28-04-2014.
2- Show me your new GRUB menu

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) 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) When the  POST process  finishes, instructions contained in  the BIOS make the  CPU load and start a very small program (less than or equal to 446 bytes) 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 (or zero sector) of a hard disk drive. Another important component of the  Master Boot Record is the Partition Table info (64 bytes).
3rd)  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) GRUB 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 even among differents 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 starting it running.  

2- Configuring the GRUB menu.

You can change  any aspect of the GRUB menu by editing the /etc/default/grub file, renaming and changing permissions of files in /etc/grub.d, and 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 and any change in this file should be made by update-grub, which for his part, read information about the menu list from /etc/default/grub and files in /etc/grub.d.

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_LINUX_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_GFXMODE: It sets the resolution displays for the boot menu. Format: GRUB_GFXMODE=WxH, geing W = Width and H = Height. Example: 
GRUB_GFXMODE=600x480.
e) GRUB_TERMINAL: Enables or Disables  the graphical menu

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 specfied 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 virtualised 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:
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/howto/17787/clean-up-the-new-ubuntu-grub2-boot-menu/
(2) http://ubuntuforums.org/showthread.php?t=1195275

PRACTICAL EXERCISE

FIRST PART
1.-
  Create a new virtual machine using the DebUb.vdi virtual disk and 1GB of RAM memory.
2.- Make  Ubuntu, with Linux 3.2.0-29-generic-pae your first menu entry.
3
.- Make 
Debian GNU/Linux, with 3.2.0-4-686-pae your last menu entry.
4.- Remove the Debian GNU/Linux, with 3.2.0-4-686-pae (recovery mode) boot menu entry.
5.- Make Debian GNU/Linux, with 3.2.0-4-686-pae  your boot operating system by default.
6.-
Configure GRUB for waiting 15 seconds before booting the operating system by default if no key is pressed.
7.- Disable the graphical menu for 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 us to correct your exercise.

SECOND PART
1.-
  Hide the menu and select Debian as the operating system which starts automatically when you turn on your  machine. HELP https://jamielinux.com/articles/2013/01/hide-grub-menu-fedora/
2.- If your new configuration works then call us to correct your exercise.

THIRD PART
1.-
  Hide the Ubuntu entries. HELP: Read Note a) in section 2.2.
2.- 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.

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