Boot Process and Systemd
Boot Process and Systemd
Boot sequence:
1. When the machine start power it did what is known as Power on self-test
(POST) checking on all Critical H/W components (RAM, VGA,
Keyboard) and if there is any problem the machine start raising loud voice
based on the mother board codes or everything is going well so we can
boot the machine.
2. All of this tasks is done using Either (Old Version BIOS) or (UEFI
system).
3. Then the machine start checking the boot settings (boot sequence) from
the bios or UEFI ( Boot from Network (Kick Start), CD/DVD, USB and
Hard disk) based on the priority of the bios. This is done boot section of
bios or the UEFI.
4. To Load the OS from the Hard disk there is must be pointer to each OS to
load this pointer must be on the first section of the Hard disk.
5. We used either Two systems (MBR system) and (GPT system), they are
called partitioning styles. Now we are going to Talk about the MBR
System:
6. It is the special type of the boot sector that was used in the early days of
using computers it is divided to 3 parts (Initial Boot loader (IBL) 446
bytes, 64 byte partition table, 2 bytes magic number check for bad sector)
= first part of disk and it size 512 byte.
7. It will display disk operating system (DOS) that means we use MBR
system.
Note: we only change in /etc/default/grub and save our change via grub2-
mkconf.
11.The grub takes the control of the system and moves to the next step.
12.The boot loader display a menu to the used which is used to select which
operating system is going to be installed.
13.Behind this menu the grub configuration to the OS.
14.After the timeout the grub will load two things the kernel (vmlinuz) and
the initramfs.
Check this location:
[root@server ~]# ls -l /boot/
15.The initramfs is loaded from the disk to the ram based on the
configuration file that is called /etc/dracut.conf
16.The initramfs have all the kernel modules that is needed to load the
system drivers and initialization scripts
17.The kernel loads the root file system /sbin/init ==>
/lib/systemd/system/initrd-root-fs.target (read-only) emergency.
In RHEL 6:
Initramfs ==> initrd
Systemd ==> init
Services and chkconfig:
It is used to start the services and enable it.
The run levels K and S with its priorities
To switch from runlevel to another we use init command and runlevel number
/etc/inittab
/etc/rc.d and run levels
NOTE: I can change some grub parameters while booting then make this
command to fix that you need while booting and once you have booted
successfully, you write them to grub config file.
If your server doesn’t boot well, it make sense to enter one of the
troubleshooting modes, it can be the systemd rescue.target or emergency.target
or from the CD/DVD.
1. we press e to see grub boot options, first part is not very important
2. it is mainly the linux16 line it counts, in the linux line, the kernel is started
with all the arguments that I needed to start the kernel.
Note: To start with, you probably don’t like the rhgb quiet, by removing
them, you can see what is happening while you are booting your system.
3. At the end of the line we have systemd.unit=rescue.target to start at rescue
mode.
4. Then press cntr+x to continue, here we have to enter root password to
enter, in previous versions, it is easy to get in the system without knowing
the root password, in RHEL 7 that become real hard.
5. Once we finished what we want to do:
6. [root@server ~]# systemctl reboot
7. If you want to make permanent modification, permanent modification
should be written in /etc/default/grub and /etc/grub.d and once you have
applied modification, you need to run
grub2-mkconfig and that make it written in MBR.
Understanding systemd:
init process has run levels and there is /etc/inittab which is its config file and it
is no longer used when using systemd.
It starts things, basically in the boot procedure after loading the kernel,
systemd is started.
Systemd is taking care of staring everything, not like the old run level system
where just services started, but systemd takes care of starting services, doing
mount, automount, etc.
In RHEL 7, PID 1 is systemd, the new init system, a few of the new features
provided by systemd include:
-parallelization capabilities, which increase the boot speed of a system
-on demand, starting of daemon without requiring a separate service
-automatic service dependency management network if it is not needed turn it
off
-a method of tracking related processes together by using Linux control groups
(cgroups)
The systemd depends mainly on units, the unit is different types of systemd
objects
To see the units:
Unit can be service to start like httpd, socket used with super services like
telnet, or path used to delay the service like spool.
The system creates softlink from the service configuration to the global service
config to add the service or start it
basic unit in systemd is the service:
Note: it is possible that one target is a part of another target or depend on it,
example graphical.target depend on multi-user.target which depends on
basic.targe.
Service Masking:
a system may have conflicting services installed, for example, there are
multiple methods to manage networks (network and NetworkManager) and
firewalls (iptables and firewalld). To prevent an admin from accidently starting
a service, that service may be masked. Masking will create a link in the config
directory /etc/systemd/system to /dev/null so that if the service is started,
nothing will happen.
To mask or unmask a service:
[root@server ~]#systemctl mask iptables
[root@server ~]#systemctl unmask iptables
One task that every system admin should be able to accomplish is recovering a
lost root password. If the admin is still logged in, either as an unprivileged user
but with full sudo access or as root, this task is trivial, when the admin is not
logged in , this task become slightly invalid.
On RHEL7, because of the change of systemd, it has become much harder, just
starting the emergency or rescue target isn’t enough, you need to break into the
system, it is possible to have the scripts that run from the initramfs pause at
certain moment, provide a root shell, and then continue when that shell exit.
4. so it allows you to get in even before the point where you get in, if you
entering an emergency.target level.
Then press cntr+x à it breaks you to the root shell without asking for any
password with the root fs from the actual system mounted read-only on
/sysroot
NOTE: selinux not yet enabled at this point, so any new files being created
will not have an selinux context assign to them, keep in mind that some
tools(such as passwd) first create a new file, then move it in place of the file
they are intended to edit, effectively creating a new file without an selinux
context.
5. Switch:/#mount -o remount,rw /sysroot à because we are so early in the boot
procedure, the root file system is mounted on a mount point with the name
/sysroot and it is read only mount, in this command is making rw.
next we need to make the content of sysroot, the current root dir
6. chroot /sysroot
In this point, you can set the new password, not just by doing anything else,
but use passwd cmd
now we also need to tell selinux that it needs to do automatic relabeling
because we are so early in boot procedure. Selinux isn’t completely functional
and if you don’t do the touch cmd (touch /.autorelabel) this file you change get
lost.
7. selinux has policy and it sets the right context to the files in your system
8. cntr+d to exit the chroot shell
9. cntr+d to restart your system à to exit from initramfs debug shell, it will take a
while