Linux Booting Procedure1-Final
Linux Booting Procedure1-Final
Linux Booting Procedure1-Final
2
System startup
How computer startup?
Booting is a bootstrapping process that
starts operating systems when the user
turns on a computer system
A boot sequence is the set of
operations the computer performs
when it is switched on that load an
operating system
4
Booting sequence
1. Tern on
2. CPU jump to address of BIOS (0xFFFF0)
3. BIOS runs POST (Power-On Self Test)
4. Find bootale devices
5. Loads and execute boot sector form MBR
6. Load OS
5
BIOS (Basic Input/Output System)
BIOS refers to the software code run by a computer
when first powered on
The primary function of BIOS is code program
embedded on a chip that recognises and controls
various devices that make up the computer.
BIOS on board
BIOS on screen
6
Boot loader
MBR (Master Boot Record)
OS is booted from a hard disk, where the
Master Boot Record (MBR) contains the
primary boot loader
The MBR is a 512-byte sector, located in the
first sector on the disk (sector 1 of cylinder 0,
head 0)
After the MBR is loaded into RAM, the BIOS
yields control to it.
8
MBR (Master Boot Record)
9
MBR (Master Boot Record)
The first 446 bytes are the primary boot loader,
which contains both executable code and error
message text
The next sixty-four bytes are the partition table,
which contains a record for each of four partitions
The MBR ends with two bytes that are defined as
the magic number (0xAA55). The magic number
serves as a validation check of the MBR
10
Extracting the MBR
To see the contents of MBR, use this command:
# dd if=/dev/hda of=mbr.bin bs=512 count=1
# od -xa mbr.bin
11
Boot loader
Boot loader could be more aptly called the
kernel loader. The task at this stage is to
load the Linux kernel
Optional, initial RAM disk
GRUB and LILO are the most popular Linux
boot loader.
12
Other boot loader (Several OS)
bootman
GRUB
LILO
NTLDR
XOSL
BootX
loadlin
Gujin
Boot Camp
Syslinux
GAG
13
GRUB: GRand Unified Bootloader
GRUB is an operating system independant boot loader
A multiboot software packet from GNU
Flexible command line interface
File system access
Support multiple executable format
Support diskless system
Download OS from network
Etc.
14
GRUB boot process
1. The BIOS finds a bootable device (hard disk) and transfers control to
the master boot record
2. The MBR contains GRUB stage 1. Given the small size of the MBR,
Stage 1 just load the next stage of GRUB
3. GRUB Stage 1.5 is located in the first 30 kilobytes of hard disk
immediately following the MBR. Stage 1.5 loads Stage 2.
4. GRUB Stage 2 receives control, and displays to the user the GRUB boot
menu (where the user can manually specify the boot parameters).
5. GRUB loads the user-selected (or default) kernel into memory and
passes control on to the kernel.
15
Example GRUB config file
16
LILO: LInux LOader
Not depend on a specific file system
Can boot from harddisk and floppy
Up to 16 different images
Must change LILO when kernel
image file or config file is changed
17
Kernel
Kernel image
The kernel is the central part in most computer operating
systems because of its task, which is the management of
the system's resources and the communication between
hardware and software components
Kernel is always store on memory until computer is tern off
Kernel image is not an executable kernel, but a compress
kernel image
zImage size less than 512 KB
bzImage size greater than 512 KB
19
Init process
The first thing the kernel does is to execute init
program
Init is the root/parent of all processes
executing on Linux
The first processes that init starts is a script
/etc/rc.d/rc.sysinit
Based on the appropriate run-level, scripts are
executed to start various processes to run the
system and make it functional
20
The Linux Init Processes
The init process is identified by process id "1“
Init is responsible for starting system processes as defined
in the /etc/inittab file
Init typically will start multiple instances of "getty" which w
aits for console logins which spawn one's user shell process
Upon shutdown, init controls the sequence and processes f
or shutdown
21
System processes
Process ID Description
0 The Scheduler
1 The init process
2 kflushd
3 kupdate
4 kpiod
5 kswapd
6 mdrecoveryd
22
Inittab file
The inittab file describes which processes are
started at bootup and during normal operation
/etc/init.d/boot
/etc/init.d/rc
The computer will be booted to the runlevel as
defined by the initdefault directive in the
/etc/inittab file
id:5:initdefault:
23
Runlevels
A runlevel is a software configuration of
the system which allows only a selected
group of processes to exist
The processes spawned by init for each
of these runlevels are defined in the
/etc/inittab file
Init can be in one of eight runlevels: 0-6
24
Runlevels
Runlevel Scripts Directory State
(Red Hat/Fedora Cor
e)
0 /etc/rc.d/rc0.d/ shutdown/halt system
1 /etc/rc.d/rc1.d/ Single user mode
2 /etc/rc.d/rc2.d/ Multiuser with no network services exported
3 /etc/rc.d/rc3.d/ Default text/console only start. Full multiuser
4 /etc/rc.d/rc4.d/ Reserved for local use. Also X-windows (Slackware/BSD)
5 /etc/rc.d/rc5.d/ XDM X-windows GUI mode (Redhat/System V)
6 /etc/rc.d/rc6.d/ Reboot
25
rc#.d files
rc#.d files are the scripts for a
given run level that run during boot
and shutdown
The scripts are found in the
directory /etc/rc.d/rc#.d/ where the
symbol # represents the run level
26
init.d
Deamon is a background process
init.d is a directory that admin can star
t/stop individual demons by changing
on it
/etc/rc.d/init.d/ (Red Hat/Fedora )
/etc/init.d/ (S.u.s.e.)
/etc/init.d/ (Debian)
27
Start/stop deamon
Admin can issuing the command and
either the start, stop, status, restart or
reload option
i.e. to stop the web server:
cd /etc/rc.d/init.d/
(or /etc/init.d/ for S.u.s.e. and Debian)
httpd stop
28
Overview of RHEL 7
Features
Logging
Dependencies
Cgroups
Activating Services
Graphical.target
Multi-user.target
Basic.target
Sysinit.target
Local-fs.target
29
Red Hat Enterprise Linux 7 Booting Process
30
BIOS
31
MBR
32
MBR (Master Boot Record)
33
GRUB2
34
GRUB2
35
GRUB2
36
About Initramfs – /etc/dracut.conf
The job of the initial RAM file system is to preload the block device
modules, such as for IDE, SCSI, or RAID, so that the root file system, on
which those modules normally reside, can then be accessed and
mounted.
The initramfs is bound to the kernel and the kernel mounts this initramfs
as part of a two-stage boot process.
The Dracut utility creates initramfs whenever a new kernel is installed.
Use the lsinitrd command to view the contents of the image created by
dracut:
#lsinitrd | less
So, in simple terms GRUB2 just loads and executes Kernel and
initramfs images.
37
Kernel
38
systemd
39
Troubleshooting of Booting related issues
40
Booting RHEL 7 into Rescue Mode
Rescue mode is equivalent to single user mode and
requires the root password
Rescue mode allows you to repair your system in
situations when it is unable to complete a regular booting
process.
Rescue mode will try to mount all local file systems and
start some important system services, but it does not
activate network interfaces neither allow multiple users to
be logged in.
41
Booting RHEL 7 into Rescue Mode
There are 2 ways to get into rescue mode :
1. Method 1
There is a GRUB2 menu option when you boot up the
system which can be selected to directly boot into rescue
mode.
42
Booting RHEL 7 into Rescue Mode
2. Method 2
1. During bootup, when the GRUB2 menu shows up, press the
e key for edit.
2. Add the following parameter at the end of the linux16 line:
Systemd.unit=rescue.target
Press Ctrl+a (or Home) and Ctrl+e (or End) to jump to the
start and end of the line.
43
Booting RHEL 7 into Rescue Mode
44
Booting RHEL 7 into Emergency Mode
Emergency mode provides the most minimal environment possible
and allows you to repair your system even in situations when the
system is unable to enter rescue mode.
In emergency mode, the system mounts the root file system as read-
only, does not attempt to mount any other local file systems, does not
activate network interfaces. and only starts few essential services.
In Red Hat Enterprise Linux 7, emergency mode requires
the root password.
45
Booting RHEL 7 into Emergency Mode
Bootup into Emergency mode(target)
1. During bootup, when the GRUB2 menu shows up, press the e key for edit.
systemd.unit=emergency.target
46
Booting RHEL 7 into Emergency Mode
Press Ctrl+a (or Home) and Ctrl+e (or End) to jump to the start and end of
the line.
47
Switch to Emergency mode(target)
#systemctl emergency
To prevent systemd from sending informative messages
#systemctl rescue
To prevent systemd from sending informative messages
48
Changing and Resetting the Root
Password
Resetting the Root Password Using an Installation Disk takes you to a shell prompt, without
having to edit the GRUB menu. It is the shorter of the two procedures and it is also the
recommended method. You can use a boot disk or a normal Red Hat Enterprise Linux 7
installation disk.
49
Changing and Resetting the Root
Password
Start the system and when BIOS information is displayed, select the option for a
boot menu and select to boot from the installation disk.
Choose Troubleshooting.
#chroot /mnt/sysimage
50
Changing and Resetting the Root
Password
# rm –f /.autorelabel
51
Changing and Resetting the Root
Password
IMPORTANT
The rhgb and quiet parameters must be removed in order to enable system messages.
Add the following parameters at the end of the linux line on 64-Bit IBM Power Series,
the linux16 line on x86-64 BIOS-based systems, or the linuxefi line on UEFI systems:
rd.break enforcing=0
52
Changing and Resetting the Root
Password
The file system is mounted read-only on /sysroot/. You will not be allowed to change the
password if the file system is not writable.
53
Changing and Resetting the Root
Password
#chroot /mnt/sysimage
54
Changing and Resetting the Root
Password
Updating the password file results in a file with the incorrect SELinux security
context. To relabel all files on next system boot, enter the following command:
# touch /.autorelabel
Alternatively, to save the time it takes to relabel a large disk, you can omit this
step provided you included the enforcing=0 option in step 3.
Remount the file system as read only:
# mount –o remount,ro /
55
Changing and Resetting the Root
Password
Enter the exit command again to resume the initialization and finish the system boot.
With an encrypted file system, a pass word or phrase is required at this point. However the password
prompt might not appear as it is obscured by logging messages. You can press and hold the Backspace key
to see the prompt. Release the key and enter the password for the encrypted file system, while ignoring the
logging messages.
NOTE
Note that the SELinux relabeling process can take a long time. A system reboot will occur automatically
when the process is complete.
Ifyou added the enforcing=0 option in step 3 and omitted the touch /.autorelabelcommand in step 8, enter
the following command to restore the /etc/shadow file's SELinux security context:~]# restorecon
# restorecon /etc/shadow
Enter the following commands to turn SELinux policy enforcement back on and verify that it is on:
Setenforce 1
getenforce
56
Overview of RHEL 7
Features
Logging
Dependencies
Cgroups
Activating Services
Graphical.target
Multi-user.target
Basic.target
Sysinit.target
Local-fs.target
57
INTRODUCTION TO GRUB 2
Red Hat Enterprise Linux 7 is distributed with version 2 of the GNU GRand
Unified Bootloader (GRUB 2), which allows the user to select an operating
system or kernel to be loaded at system boot time. GRUB 2 also allows the
user to pass arguments to the kernel.
58
MENU ENTRIES IN GRUB.CFG
59
MENU ENTRIES IN GRUB.CFG
60
MAKING TEMPORARY CHANGES TO A GRUB 2 MENU
Startthe system and, on the GRUB 2 boot screen, move the cursor to
the menu entry you want to edit, and press the e key for edit.
Move the cursor down to find the kernel command line. The kernel
command line starts with linux on 64-Bit IBM Power Series, linux16 on
x86-64 BIOS-based systems, or linuxefi on UEFI systems.
61
MAKING TEMPORARY CHANGES TO A GRUB 2 MENU
Edit the kernel parameters as required. For example, to run the system in
emergency mode, add the emergency parameter at the end of the linux16
line:
The rhgb and quiet parameters can be removed in order to enable system
messages.
These settings are not persistent and apply only for a single boot. To make
persistent changes to a menu entry on a system, use the grubby tool.
62
MAKING PERSISTENT CHANGES TO A GRUB 2 MENU USING
THE GRUBBY TOOL
The grubby tool can be used to read information from, and make
persistent changes to, the grub.cfg file.
# ls -ltr /etc/grub2.cfg
lrwxrwxrwx. 1 root root 22 Apr 4 2016 /etc/grub2.cfg ->
../boot/grub2/grub.cfg
63
MAKING PERSISTENT CHANGES TO A GRUB 2 MENU USING
THE GRUBBY TOOL
# grubby --default-kernel
/boot/vmlinuz-3.10.0-229.4.2.el7.x86_64
#
To make a persistent change in the kernel designated as the default kernel, use the
grubby command as follows:
64
MAKING PERSISTENT CHANGES TO A GRUB 2 MENU USING
THE GRUBBY TOOL
VIEWING THE GRUB MENU ENTRY FOR A KERNEL
L
#grubby –info=ALL
To view the GRUB menu entry for a specific kernel, enter a commands as follows:
65
MAKING PERSISTENT CHANGES TO A GRUB 2 MENU USING
THE GRUBBY TOOL
ADDING AND REMOVING ARGUMENTS FROM A GRUB MENU ENTRY
#grubby --remove-args="rhgb quiet" --args=console=ttyS0,115200 --update-kernel
/boot/vmlinuz-3.10.0-229.4.2.el7.x86_64
This command removes the Red Hat graphical boot argument, enables boot message to
be seen, and adds a serial console. As the console arguments will be added at the end of
the line, the new console will take precedence over any other consoles configured.
66
MAKING PERSISTENT CHANGES TO A GRUB 2 MENU USING
THE GRUBBY TOOL
CHANGING A KERNEL ARGUMENT
To change a value in an existing kernel argument, specify the argument again,
changing the value as required. For example, to change the virtual console font size,
use a command as follows:
67
LAB ON RHEL 7
68