Description: Candidates should be able to properly manipulate a Linux system during both the boot process and during recovery mode. This objective includes using both the init utility and init-related kernel options. Candidates should be able to determine the cause of errors in loading and usage of bootloaders. GRUB version 2 and GRUB Legacy are the bootloaders of interest. Both BIOS and UEFI systems are covered.
Key Knowledge Areas:
BIOS and UEFI
NVMe booting
GRUB version 2 and Legacy
grub shell
boot loader start and hand off to kernel
kernel loading
hardware initialisation and setup
daemon/service initialisation and setup
Know the different boot loader install locations on a hard disk or removable device.
Overwrite standard boot loader options and using boot loader shells.
Use systemd rescue and emergency modes.
Terms and Utilities:
mount
fsck
inittab, telinit and init with SysV init
The contents of /boot/, /boot/grub/ and /boot/efi/
EFI System Partition (ESP)
GRUB
grub-install
efibootmgr
UEFI shell
initrd, initramfs
Master boot record
systemctl
Boot process overview
lets take a look at boot process and stick what ever we have learned till now:
BIOS / UEFI
|
Bootable Disk
|
Boot Loader(LILO,Grub,Grub2)
|
Kernel (initramfs/initd)
|
init --->systemd / upstart / SysV
|
everything---shell & other services and programs
if any problems occur on any of these steps, boot process fails. It might be motherboard problems, Disk problems or boot loader problem.lets start from very beginig.
BIOS basic Input Output System vs UEFI(EFI) Unified Extensible Firmware Interface
When we start computer there should be away to wake up the kernel from sleep. But even our pour bootloader sleeps on the hard disk and has to access disk when no kernel driver is available. So there should be a hardware solution to access hard disk and starts boot loader and then bootloader wake up the kernel.
BIOS and UEFI are both interfaces for accessing disk.They sit between hardware/firmware and operating system and help computers to start. BIOS has become pretty old and UEFI has developed to retire it. UEFI has many advantages and has become default interface in modern PCs. UEFI is able to boot from large disks when we use GPT.
MBR(Master Boot Record)
on BIOS system Master boot record is read from disk. MBR is not part of any file system and considered as metadata of your hard disk.How is it working ?Master boot record holds two things, some of or all of boot loader program and the partition table. At first stage just 446 kb of disk is read, (primary boot loader/IPL) and its job is to load second stage .as 512 bytes is so small to keep whole needed files to load the kernel, In second stage a MB of disk is read, which is meta data area of disk and every thing which is needed to load kernel should be exsited here. Boot loader(grub2) located in first 30 KB of hard disk immediately after MBR. grub load kernel and inintrd from /etc/boot/grub/grub.conf and loads other modules as needed. Grub loads GUI from /grub/splash.xpm.gz and starts the system.
in UEFI system, GPT partition table is used. GPT partition table contains an EFI System Partition (ESP).Inside that there is always /efi directory. /efi directory might contains one or many boot loaders. Each boot loader has its own identifier and corresponding directory. So if you are using boot linux and microsoft windows, its usual to have both /efi/grub and /efi/microsoft directories.Boot loaders in this partition has .efi extension. So as you can see UEFI/EFIgive more flexibility and you can support more than one operating system by just having an ESP partition on a hard disk. no more pain :).
root@server3:~# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/sda: 62914560 sectors, 30.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3F67AA1F-8E90-4EA6-AB2E-2B8287545A35
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 62914526
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 1050623 512.0 MiB EF00 EFI System Partition
2 1050624 58722303 27.5 GiB 8300
3 58722304 62912511 2.0 GiB 8200
Command (? for help): q
root@server3:~# mount | grep efi
efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime)
/dev/sda1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
Recovering boot loader needs to specify three major required elements. We have already got familiar with all 3:
root partion
kernel and boot partition as its argument (usually same as root)
initrd/initramfs
how ever some commands are different in grub version 1 and version 2.
Recovering Grub Legacy
grub version1 dosn't have "ls" command.Do not forget it starts counting hard disk partitions from "Zero".
grub>help ###to see grub v1 commands
###1.root,What the root is ?
grub>root ### if nothing showed up, we have to boot system by using another media
###2.Kernel, which kernel we want to boot from? nad where is the boot partition? consider lvm :(
grub> kernel /vmlinuz.x.y.z root=/dev/sdaX
###3.initramfs/initrd , Which initramdisk is going to be loaded? It should be the same as kernel version
grub>initrd /initrd-x.y.z
### and finally boot the system
grub>boot
after rebooting system install grub again:
[root@localhost ~]# grub-install /dev/sda
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
# this device map was generated by anaconda
(hd0) /dev/sda
Recovering Grub2
Grub2 is more enhanced than legacy grab and if boot problems occur, grub might left system in different states.
grub command prompt
Description
grub>
prompt
GRUB 2 loaded modules but was unable to find the grub.cfg file. = has already found root partition
grub rescue>
prompt
GRUB 2 failed to find its grub folder, or failed to load the normal module. = has not found root partition
grub>:
The grub prompt on a blank screen
GRUB 2 has found the boot information but has been either unable to locate or unable to use an existing GRUB 2 configuration file (usually grub.cfg)
grub rescue>:
the rescue mode
GRUB 2 is unable to find the grub folder or its contents are missing/corrupted. The grub folder contains the GRUB 2 menu, modules and stored environmental data.
GRUB-
a single word, with no prompt and no curser
GRUB has failed to find even the most basic information, usually contained in the MBR or boot sector.
Busybox or Initramfs
GRUB 2 began the boot process but there was a problem passing control to the operating system. Possible causes include an incorrect UUID or root= designation in the 'linux' line or a corrupted kernel.
Frozen splash screen
blinking cursor with no grub> or grub rescue prompt. Possible video issues with the kernel. While these failures are not of GRUB 2's making, it may still be able to help. GRUB 2 allows pre-boot editing of its menu and the user may restore functionality by adding and/or removing kernel options in a menuentry before booting.
each failer might need different remedies here lets take a look at the first one. Grub2 supports "ls" , "cat" command and support tab tab completion. it starts counting partitions from "One" . Strange world huuh ?
###1.root, Finding root partition --- no "root command" in grub2
grub>ls ### to see partitions, (hdX,A) (hdX,B) (hdX,C) , ...
grub>ls (hdX,A) ###try to guess based on content, setting root partition in grub 2 is different from grub 1
grub>set ###it show all current grub2 variables, we should check/create/fix two of them:
###prefix=(hdX,A)/boot/grub
###root=hdX,A
grub>set root=(hdA,Y) ###set/modify required variables base on information that we have got from ls
grub>set ###check results
###2.kernel, introducing kernel --- no "kernel command" in grub 2
grub>linux /boot/vmlinux.x.y.z root=/dev/sdY
###3.initramfs/initrd, give appropriate initramdisk for kernel , consider versions
grub>initrd /boot/init.img.x.y.z
###and finally
grub>boot
and finally do some post configuration :
root@server1:~# update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.10.0-42-generic
Found initrd image: /boot/initrd.img-4.10.0-42-generic
Found linux image: /boot/vmlinuz-4.10.0-40-generic
Found initrd image: /boot/initrd.img-4.10.0-40-generic
Found linux image: /boot/vmlinuz-4.10.0-28-generic
Found initrd image: /boot/initrd.img-4.10.0-28-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
and install grub:
root@server1:~# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.