Linux Boot Process
Linux Boot Process
Linux Boot Process
• This is the hardware portion of the boot process and is the same for
any operating system. When power is first applied to the computer it
runs the POST (Power On Self Test) which is part of the BIOS (Basic
I/O System).
• This helps to switchon hardware components
• BIOS POST checks the basic operability of the hardware and then it
issues a BIOS interrupt, INT 13H, which locates the boot sectors on
any attached bootable devices.
• The first boot sector it finds that contains a valid boot record is
loaded into RAM and control is then transferred to the code that was
loaded from the boot sector.
• The boot sector is really the first stage of the boot loader. There are
three boot loaders used by most Linux distributions, GRUB, GRUB2,
and LILO.
• GRUB2 is the newest and is used frequently these days than the other
older options.
MBR
Most Linux servers lack a graphical user interface and therefore start in runlevel 3. Servers with a GUI
and desktop Unix systems start runlevel 5. When a server is issued a reboot command, it enters
runlevel 6.
• To find current default target the command is
#systemctl get-default
• To set default target syntax :
#systemctl set-default <Target.target>
• Example
#systemctl set-default Multiuser.target
• Multiuser.target analogus to runlevel 3
• Graphical.target analogus to runlevel 5
chkconfig
• The chkconfig tool is used in Red Hat based systems (like CentOS)
to control what services are started at which runlevels.
• To display a list of services
#chkconfig –list
• whether they are enabled or disabled for each runlevel
Creating this file will automatically perform a relabel of all files on next boot. Note
that this may take some time depending on the amount of files you have on the file
system. For a plain vanilla CentOS 7 server, it takes me about 2 minutes to
complete.
Step 8:
Enter the ‘exit’ command twice, the first one will exit the chroot jail
environment while the second will exit the initramfs root shell and
reboot the system.
Once the reboot has completed you will be able to use the root
account with your newly set password.
Login sequence
Linux Login sequence
• The login sequence
• It's worth understanding at least those files in the login sequence that will affect
things like
• whether you can login in the first place,
• where your initial environment comes from, and so on.
• Following are the files you need to worry about that are invoked/consulted every time you log in
(indented in an attempt to show who actually consults who):
• /etc/passwd 1
• /etc/shadow 2
• /etc/group 3
• /etc/profile 4
• /etc/profile.d/*.sh 5
• ~/.bash_profile 6
• ~/.bashrc 7
• /etc/bashrc 8
1. /etc/passwd defines, among other things, the username, numeric UID and GID of the user, the
home directory and the login shell. For security reasons, the encrypted password is no longer
stored in this file.
2. /etc/shadow represents a more secure place to store things like the encrypted password,
password aging information and more. (This is the only file in this list of files that requires root
privilege to display.)
3. /etc/group defines the working groups on the host, along with the users who are members of
those groups.
4. /etc/profile represents the top-level startup/customization file that is invoked by each user.
5. In addition, this file may, toward the bottom, invoke all of the customization files in the
directory /etc/profile.d, which typically represent a small amount of customization on a per-
application or per-command basis. If you're confused about where some login environment
setting is coming from that seems to be affecting the behaviour of a particular command, this is
a good place to look.
6. These two startup files in the user's home directory are for configuring the user's personal
environment. In addition, on some Linux systems, the default .bashrc may invoke the global
/etc/bashrc file, for one final dose of environment configuration and customization.
• As a final helpful hint, once you get logged in, there are two handy
commands that can tell you everything there is to know about your
identity and group affiliations:
• $ id
• $ groups
Kernel modules
Add, list, Remove kernel modules
• A kernel module is a program which can be loaded into or unloaded from
the kernel upon demand, without necessarily recompiling (the kernel) or
rebooting the system, and is intended to enhance the functionality of the
kernel.
• If modules are not there , then the kernel would have to be built with all
functionalities integrated directly into the kernel image.
• This would mean having bigger kernels, and system administrators would
need to recompile the kernel every time a new functionality is needed.
• These are like plugins in windows
• Example – device driver
List All Loaded Kernel Modules in Linux
• In Linux, all modules end with the .ko extension, and they are normally
loaded automatically as the hardware is detected at system boot.
• However a system administrator can manage the modules using certain
commands.
• Usually, all Linux kernel modules (drivers) are stored in the module
directory located that /lib/modules/$(uname -r) directory. To see current
modules, type:
$ ls /lib/modules/$(uname -r)
• To list all currently loaded modules in Linux, we can use the lsmod (list
modules) command which reads the contents of /proc/modules like this.
$lsmod
$lsmod | grep e1000 ----- will check for e1000 module is there or not
modinfo command
• modinfo stand for ‘module information‘. This command will show the
information about a kernel module. For instance you want to view the
information regarding network driver module:
#modinfo e100
• uname –r ---- this command shows the current kernel version. Your
system may contains multiple kernel version
• ls /lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/
Load and unload module
• To load a kernel module, we can use the insmod (insert module)
command. Here, we have to specify the full path of the module. The
command below will insert the speedstep-lib.ko module.
• # insmod /lib/modules/4.4.0-21-
generic/kernel/drivers/cpufreq/speedstep-lib.ko
To Unload the module
• To unload a kernel module, we use the rmmod (remove module)
command. The following example will unload or remove the
speedstep-lib.ko module.
# rmmod /lib/modules/4.4.0-21-
generic/kernel/drivers/cpufreq/speedstep-lib.ko
How to Manage Kernel Modules Using modprobe
Command
• modprobe is an intelligent command for listing, inserting as well as
removing modules from the kernel.
• It searches in the module directory /lib/modules/$(uname -r) for all
the modules and related files, but excludes alternative configuration
files in the /etc/modprobe.d directory.
• so you don’t need the absolute path of a module; this is the
advantage of using modprobe over the previous commands.
• To insert a module, simply provide its name as follows. It will search it
# modprobe speedstep-lib
To remove module using modprobe
• To remove a module, use the -r flag like this.
# modprobe -r speedstep-lib
• Note: Under modprobe, automatic underscore conversion is
performed, so there is no difference between _ and – while entering
module names.
• If we still face problems or errors while loading the modules, then this
time we must do debugging.
• By enabling debugging we can find exact error or issue before or after
installing the modules.
• #modprobe -f floppy
Creating Yum repository on centos 7
• There are several overheads involved in installing a program in a
computer Like the following.
• http://linux.duke.edu/projects/yum/
• What are packages in Linux?
• Red hat Linux,Fedora & all other red hat based distributions uses RPM as
their main software installation package tool.
• A Linux software package is nothing but a compressed archive of files,
consisting of following, which enables the functioning of that software
package.
• particular product information
• program files
• Icons
• libraries etc.
• RPM is the default package installation tool used in Red Hat Linux. RPM
stands for Red Hat Package Manager.
• All required files of an application is compiled in a single file format
called with a file extension of .rpm.
• The Red Hat package manager tool, which is installed in all RPM
based system, knows how to open and install these .rpm files in the
system
• .rpm files are compiled and are ready to install, they also perform a
dependency prerequisite check for all required libraries before
installing a particular package.
RPM and YUM
• After a short stint with some long and unintelligible network interface names, we
now have a third set of naming conventions which seem only marginally better.
Names like ethX are still used by CentOS 6.x. The newest naming conventions,
with names like eno1 and enp0s3 are used by RHEL 7, CentOS 7, and more recent
releases of Fedora. The interface naming convention for RHEL 6 and CentOS 6 is
described in Appendix A. Consistent Network Device Naming of the Red Hat
Deployment Guide. RHEL 7, CentOS 7, and current versions of Fedora are
described in Chapter 8. Consistent Network Device Naming of the Red Hat
Networking Guide.
Configuration file examples
• This example network interface configuration file, ifcfg-eth0, defines a static IP
address configuration for a CentOS 6 server installation.
• This file starts the interface on boot, assigns it a static IP address,
defines a domain and network gateway, specifies two DNS servers,
and does not allow non-root users to start and stop the interface.
• # Intel Corporation 82566DC-2 Gigabit Network Connection
• DEVICE=eth0
• HWADDR=00:16:76:02:BA:DB
• ONBOOT=yes
• IPADDR=192.168.0.10
• BROADCAST=192.168.0.255
• NETMASK=255.255.255.0
• NETWORK=192.168.0.0
• SEARCH="example.com"
• BOOTPROTO=static
• GATEWAY=192.168.0.254
• DNS1=192.168.0.254
• DNS2=8.8.8.8
• TYPE=Ethernet
• USERCTL=no
• IPV6INIT=no
• The following interface configuration file, ifcfg-eno1, provides a DHCP configuration for a desktop workstation.
• the DHCP entries, IP address, the search domain, and all other network information are not defined because they are supplied by
the DHCP server. Configuration items like the DNS servers can be overridden in the interface configuration file by adding DNS1 and
DNS2 lines, as in the previous static configuration example.
• TYPE=Ethernet
• BOOTPROTO=dhcp
• DEFROUTE=yes
• IPV4_FAILURE_FATAL=no
• IPV6INIT=no
• IPV6_AUTOCONF=no
• IPV6_DEFROUTE=no
• IPV6_FAILURE_FATAL=no
• NAME=eno1
• UUID=a67804ff-177a-4efb-959d-c3f98ba0947e
• ONBOOT=yes
• HWADDR=E8:40:F2:3D:0E:A8
• IPV6_PEERDNS=no
• IPV6_PEERROUTES=no
• Configuration options
• There are many configuration options for the interface configuration files. These are
some of the more common options: