TYCS Linux Chapter 1 & 2 Notes
TYCS Linux Chapter 1 & 2 Notes
TYCS Linux Chapter 1 & 2 Notes
Unit 1
Chapter 1
Introduction to Linux
➢ An operating system is software that manages all of the hardware resources associated
with your desktop or laptop. To put it simply, the operating system manages the
communication between your software and your hardware.
➢ Linux is an operating system.
➢ Linus Torvalds designed the free and open-source Linux operating system kernel in
1991.
➢ The Linux Operating System is a type of operating system that is similar to Unix, and it
is built upon the Linux Kernel.
➢ The Linux Kernel is like the brain of the operating system because it manages how the
computer interacts with its hardware and resources.
➢ But the Linux Kernel alone is not enough to make a complete operating system. To
create a full and functional system, the Linux Kernel is combined with a collection of
software packages and utilities, which are together called Linux distributions.
Linux distributions are:
• SUSE
• Open SuSE
• Linux Mint
➢ Linux is a free, open source operating system, released under the GNU General Public
License (GPL). Anyone can run, study, modify, and redistribute the source code, or even
sell copies of their modified code, as long as they do so under the same license.
Managing Software
1)Redhat Package Manager
Example
$rpm -q sshd
This command will display information like the package name, version, architecture, and more.
Example
$rpm -V sshd
This command checks whether the package’s files on disk match the information in the RPM
database.
Example
$rpm -e sshd
This command will uninstall the specified package from your system.
YUM stands for Yellowdog, Updater, Modified. YUM is a powerful package management
tool that simplifies the process of installing, updating, and managing software on Red Hat-
based Linux distributions like CentOS and Fedora.
Before we dive into the most common YUM commands, let’s start with the basic syntax:
yum [options] [command] [package(s)]
Here,
• [options] are optional flags that modify the behaviour of the command.
• [command] is the YUM operation you want to perform (e.g., install, update,
remove).
• [package(s)] specify the package(s) you want to work with.
1. Installing Packages:
This command is used to install packages on your system using YUM. Replace package-name
with the name of the package you want to install. YUM will automatically handle
dependencies and download the necessary files from repositories.
$yum install package-name
Example:
$yum install nginx
2. Updating Packages:
Keeping your system up to date is important for security and performance. Running this
command will check for updates for all installed packages and install any available updates.
$yum update
3. Removing Packages:
Use this command to remove a package from your system. Replace `package-name` with the
name of the package you want to uninstall. YUM will also remove any dependencies that are
no longer needed.
$yum remove package-name
Example:
$yum remove nginx
Example:
$yum search python
5. Listing Installed Packages:
Running this command will provide you with a list of all the packages that are currently
installed on your system. It’s useful for checking what software is already present.
$yum list installed
Example:
$yum info python
To list all software package currently installed in the system following command is used:
$dpkg -l
Install a Debian package with the dpkg command following command is used
3)Update a package
Update a Debian package with the dpkg command following command is used
4)Remove a package
Remove a Debian package with the dpkg command following command is used
2)Usermod
3)Userdel
4)Groupadd
5)Groupmod
6)Groupdel
1)useradd
$useradd username
Example-
$useradd nimish
$passwd Nimish
Options
Example -
2)usermod
It is used to modify the user account.
Syntax-
Options
Example-
3)Userdel
Syntax-
$userdel username
Example-
$userdel Ankita
$userdel -r Ankita
4)groupadd
Syntax-
$groupadd groupname
Example-
$groupadd tycs
Options-
-g Sets group id
Example-
$groupadd -g 5 tycs
5)groupmod
Syntax-
Options
Example
$groupmod -g 10 -n cs tycs
6)Groupdel
Syntax-
$groupdel groupname
Example
$groupdel tycs
Chapter 2
Booting process
The following are the 6 high level stages of a typical Linux boot process.
1. BIOS
BIOS stands for Basic Input/Output System
Performs some system integrity checks
Searches, loads, and executes the boot loader program.
It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12
of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the
control to it.
So, in simple terms BIOS loads and executes the MBR boot loader.
2. MBR
MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in
1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.
3. GRUB
GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which one to be
executed.
GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads
the default kernel image as specified in the grub configuration file.
GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand
filesystem).
Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The
following is sample grub.conf of CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
root (hd0,0)
initrd /boot/initrd-2.6.18-194.el5PAE.img
As you notice from the above info, it contains kernel and initrd image.
So, in simple terms GRUB just loads and executes Kernel and initrd images.
4. Kernel
Mounts the root file system as specified in the “root=” in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of
1. Do a ‘ps -ef | grep init’ and check the pid.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root file system until kernel is booted and the real root
file system is mounted. It also contains necessary drivers compiled inside, which helps it to
access the hard drive partitions, and other hardware.
5. Init
Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate
program.
Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
If you want to get into trouble, you can set the default run level to 0 or 6. Since you know
what 0 and 6 means, probably you might not do that.
Typically you would set the default run level to either 3 or 5.
6. Runlevel programs
When the Linux system is booting up, you might see various services getting started. For
example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed
from the run level directory as defined by your run level.
Depending on your default init level setting, the system will execute the programs from one
of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/
Run Levels
A run level is a state of init and the whole system defines what system services are
operating. Run levels are identified by numbers. Runlevel is a mode or state in
which a Linux system operates. It has a crucial role in the management of the Linux
System.
Whenever a LINUX system boot, firstly the init process is started which is
actually responsible for running other start scripts which mainly involves
initialization of your hardware, bringing up the network, and starting the
graphical interface.
Now, the init first finds the default runlevel of the system so that it can run the
start scripts corresponding to the default run level.
A runlevel can simply be thought of as the state your system enters like if a
system is in a single-user mode it will have a runlevel 1 while if the system is in
a multi-user mode, it will have a runlevel 5.
0 System halt i.e., the system can be safely powered off with no activity.
Multiple user modes under the command line interface and not under the
3 graphical user interface.
4 User-definable.
Multiple user mode under GUI (graphical user interface) and this is the
5 standard runlevel for most of the LINUX-based systems.
1. Service command
2. chkconfig command
1. Service command
The service command starts, stop and restart a daemon or services.
Syntax:
Here, command can be anyone from start, stop, restart and status.
i) start command
To start a service use the following syntax,
Syntax:
Example-
$service sshd start
ii)stop command
To stop a service use the following syntax,
Syntax:
Example-
$service sshd stop
iii)restart command
To restart a service use the following syntax,
ADVERTISEMENT
Syntax:
Example-
$service sshd restart
iv)status command
To get current status of a service use the following syntax,
Syntax:
Example-
$service sshd status
2. chkconfig command
chkconfig command is used to list all available services and view or update their run
level settings. In simple words it is used to list current startup information of
services or any particular service, updating runlevel settings of service and adding or
removing service from management.
Following options are used with chkconfig command
$chkconfig --list
2)To View current status of a particular services.
$chkconfig --list sshd
3)For Disabling a Service: By default 2 3 4 5 run levels are affected by this
command to disable certain run levels only, add –level attribute followed by run
level.
$chkconfig sshd off
4)Enabling a Service: By default 2 3 4 5 run levels are affected by this command to
enable certain run levels only, add –level attribute followed by run level.
$chkconfig ssd on
Cron tab Program
The cron is a software utility, offered by a Linux-like operating system that automates the scheduled task
at a predetermined time. It is a daemon process, which runs as a background process and performs the
specified operations at the predefined time when a certain event or condition is triggered without the
intervention of a user.
Basic Crontab Syntax
The syntax of a cron job line in a crontab file must use the following format:
MIN HOUR DOM MON DOW CMD
The first five fields, each separated by a single space, represent time intervals:
MIN for minutes
HOUR for hours DOM for day of the month
MON for month
DOW for day of the week
They tell Cron when to initiate the cron job.
Example
30 8 10 06 * /home/maverick/full-backup
Where 30 – 30th Minute 08 – 08 AM 10 – 10th Day 06 – 6th Month (June) * – Every day of the week
File system
Volume Management
/etc/inittab File
The /etc/inittab file is the configuration file used by the System V (SysV) initialization system
in Linux. This file defines three items for the init process:
Once all the entries in /etc/inittab for your runlevel are executed, the boot process is completed,
and you can log in.
Each line in the inittab file consists of four colon-delimited fields:
id:runlevels:action:process
Here is a description of these fields:
i) id (identification code) – consists of a sequence of one to four characters that identifies its
function.
ii) runlevels – lists the run levels to which this entry applies.
iii) action – specific codes in this field tell init how to treat the process. Possible values include:
initdefault, sysinit, boot, bootwait, wait, and respawn.
Tells the init command how to treat the process specified in the identifier field. The
following actions are recognized by the init command:
respawn
If the process does not exist, start the process. Do not wait for its termination (continue
scanning the /etc/inittab file). Restart the process when it dies. If the process exists, do
nothing and continue scanning the /etc/inittab file.
wait
When the init command enters the run level that matches the entry's run level, start the
process and wait for its termination. All subsequent reads of the /etc/inittab file while
the init command is in the same run level will cause the init command to ignore this
entry.
once
When the init command enters a run level that matches the entry's run level, start the
process, and do not wait for its termination. When it dies, do not restart the process.
When the system enters a new run level, and the process is still running from a previous
run level change, the program will not be restarted. All subsequent reads of
the /etc/inittab file while the init command is in the same run level will cause
the init command to ignore this entry.
boot
Process the entry only during system boot, which is when the init command reads
the /etc/inittab file during system startup. Start the process, do not wait for its
termination, and when it dies, do not restart the process. In order for the instruction to be
meaningful, the run level should be the default or it must match the init command's run
level at boot time. This action is useful for an initialization function following a
hardware reboot of the system.
bootwait
Process the entry the first time that the init command goes from single-user to multi-user
state after the system is booted. Start the process, wait for its termination, and when it
dies, do not restart the process. If the initdefault is 2, run the process right after boot.
powerfail
Execute the process associated with this entry only when the init command receives a
power fail signal (SIGPWR).
log_type — Configures xinetd to use the authpriv log facility, which writes log
entries to the /var/log/secure file. Adding a directive such as FILE
/var/log/xinetdlog would create a custom log file called xinetdlog in
the /var/log/ directory.
— Configures xinetd to log if the connection is successful. By
log_on_success
default, the remote host's IP address and the process ID of server processing the
request are recorded.
— Configures xinetd to log if there is a connection failure or if the
log_on_failure
connection is not allowed.
cps— Configures xinetd to allow no more than 25 connections per second to any
given service. If this limit is reached, the service is retired for 30 seconds.
Logging
Process of Configuring and compiling Kernel
It contains 5 important steps
1.Preparing to configure the kernel
2.Kernel Configuration
3.Compiling the kernel
4.Installing the kernel
5.Booting the kernel