TYCS Linux Chapter 1 & 2 Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Subject: Linux Server Administration

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:

• Red Hat Enterprise Linux


• Fedora
• Ubuntu
• Debian
• Centos

• 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

2)Yum Package Manager

3)Debian Package Manager

1) Redhat Package Manager


he RPM (Red Hat Package Manager) command is a fundamental tool in the world of Linux
package management. It is widely used in Red Hat-based distributions like Fedora and
CentOS, as well as other RPM-based distributions. The RPM command allows users to install,
query, verify, and manage software packages, making it an essential tool for system
administrators and Linux enthusiasts.

Basic Syntax of RPM in Linux

The basic syntax of the rpm command is as follows:


rpm [options] [package_name]
Here,
[options] represent various command-line options that control the behavior of the rpm
command.
[package_name] refers to the name of the RPM package you want to work with.

Options Available in the `rpm` command in Linux


These options provide a wide range of functionalities and control when working with RPM
packages on Linux systems. You can use them to install, upgrade, query, and manage packages
effectively.
Options Description

-i, –install Install an RPM package.

-U, –upgrade Upgrade an RPM package.

Query RPM package(s) or display


-q, –query information about installed packages.

-a, –all Used with -q, lists all installed packages.

-V, –verify Verify the integrity of installed packages.


Options Description

-e, –erase Uninstall or erase an RPM package

Common RPM Commands and Options


1. Installing RPM Packages
To install an RPM package, you can use the `rpm` a command followed by the `-i` (or `--
install`) option and the name of the RPM package file. For example:
$rpm -i sshd
This command installs the specified package on your system.

2. Upgrading RPM Packages


To upgrade an installed package with a newer version, use the `-U` (or `--upgrade`) option:
$rpm -U sshd
This command will replace the older version of the package with the new one if it’s already
installed

3. To list all installed packages in RPM


To list all installed packages on your system, use the -q (or –query) option with the -a (or –all)
flag:
$rpm -qa
This will display a list of installed packages along with their names and versions.

4. Querying RPM Package


To retrieve detailed information about a specific package, use the `-q` (or `–query`) option
followed by the package name:
$rpm -q package_name

Example
$rpm -q sshd
This command will display information like the package name, version, architecture, and more.

5. Verifying RPM Package


You can verify the integrity and authenticity of an RPM package without installing it using the
`-V` (or `--verify`) option. This checks if the package’s files have been modified or deleted:
$rpm -V package_name

Example
$rpm -V sshd
This command checks whether the package’s files on disk match the information in the RPM
database.

6. Uninstalling RPM Packages


To remove an installed package, use the `-e` (or `–erase`) option followed by the package
name:
rpm -e package_name

Example
$rpm -e sshd

This command will uninstall the specified package from your system.

2) Yum package Manager

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.

Basic Syntax of `yum` command in Linux

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.

Commonly used YUM Options in Linux


These options cover a wide range of package management tasks, from installation and updates
to package removal and repository management. You can combine them with other YUM
commands to perform specific operations efficiently on your Linux system.
Options Description

install package Install a package

update Update all packages


Options Description

remove package Remove a package

update package Update a specific package

Common YUM Commands:

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

4. Searching for Packages:


This command allows you to search for packages by providing a keyword. YUM will display a
list of packages that match the keyword, making it easier to find the package you need.
$yum search keyword

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

6. Display Package Information:


Use this command to get detailed information about a specific package, including its
description, version, dependencies, and more.
$yum info package-name

Example:
$yum info python

3)Debian Package Manager


dpkg in Linux is the primary package manager for Debian and Debian-based systems, such as
Ubuntu. The tool installs, builds, removes, configures, and retrieves information for Debian
packages.

Common dpkg commands

1) List all package

To list all software package currently installed in the system following command is used:

$dpkg -l

2) List all package

Install a Debian package with the dpkg command following command is used

$sudo apt-get install python

3)Update a package

Update a Debian package with the dpkg command following command is used

$sudo apt-get update python

4)Remove a package

Remove a Debian package with the dpkg command following command is used

$sudo apt-get remove python


User Management Commands
1)Useradd

2)Usermod

3)Userdel

4)Groupadd

5)Groupmod

6)Groupdel

1)useradd

Useradd command is used to add user account.


Syntax-

$useradd username

$useradd options username

Example-

$useradd nimish

$passwd Nimish

Options

-d dir Mention user's home directory

-e date Mention the account expiration date

-g group Sets the users primary group

-s shell Sets the users shell

-u uid Sets the userid


-f time Disable the account time days after password expires

Example -

$useradd -d /home/Ankita -e 10-10-2024 -u 101 Ankita

2)usermod
It is used to modify the user account.

Syntax-

$usermod options username

Options

-d dir Mention user's home directory

-e date Mention the account expiration date

-g group Sets the users primary group

-s shell Sets the users shell

-u uid Sets the userid

-f time Disable the account time days after p

Example-

$usermod -e 20-10-2025 Ankita

3)Userdel

It is used to delete user account.

Syntax-

$userdel username
Example-

$userdel Ankita

To delete all files created by user following command is used.

$userdel -r Ankita

4)groupadd

It is used to create a group.

Syntax-

$groupadd groupname

$groupadd options groupname

Example-

$groupadd tycs

Options-

-h Display help message

-g Sets group id

-o Adds a group with non-unique GID

-r create a system group

Example-

$groupadd -g 5 tycs
5)groupmod

It is used to modify group account.

Syntax-

$groupmod options groupname

Options

-g Changes the GID

-n Change the groupname

Example

$groupmod -g 10 -n cs tycs

6)Groupdel

It is used to delete a group account.

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

title CentOS (2.6.18-194.el5PAE)

root (hd0,0)

kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/

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.

The standard LINUX kernel supports these seven different runlevels :


Runlevel Description

0 System halt i.e., the system can be safely powered off with no activity.

1 Single user mode.

2 Multiple user mode with no NFS (network file system).

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.

6 Reboot which is used to restart the system.


Enabling and disabling services
In linux services are managed by using two types fo commands such as

1. Service command
2. chkconfig command

1. Service command
The service command starts, stop and restart a daemon or services.

Syntax:

$service servicename start/stop/status/restart

Here, command can be anyone from start, stop, restart and status.

i) start command
To start a service use the following syntax,

Syntax:

$service servicename start

Example-
$service sshd start

ii)stop command
To stop a service use the following syntax,

Syntax:

$service servicename stop

Example-
$service sshd stop
iii)restart command
To restart a service use the following syntax,

ADVERTISEMENT

Syntax:

$service servicename restart

Example-
$service sshd restart

iv)status command
To get current status of a service use the following syntax,

Syntax:

$service servicename status

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

1)To List current status of all system services.

$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:

 the default runlevel


 what processes to start, monitor, and restart if they terminate
 what actions to take when the system enters a new runlevel

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.

Some of the actions are

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).

iv) process – defines the command or script to execute.


/etc/xinetd.conf File
The /etc/xinetd.conf file contains general configuration settings which effect every service
under xinetd's control. It is read once when the xinetd service is started, so for
configuration changes to take effect, the administrator must restart the xinetd service.
Below is a sample /etc/xinetd.conf file:
defaults
{
instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
cps = 25 30
}
includedir /etc/xinetd.d
These lines control the following aspects of xinetd:
 instances — Sets the maximum number of requests xinetd can handle at once.

 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

1.Preparing to configure the kernel


Linux kernel source file make file which help to add together the
thousands of other files that make up the kernel source.
Following commands are used to prepare the system for configure
kernel
i) makemrproper: All previous kernel
configurations will be deleted from the build
environment
ii) make clean: It deletes most generated files not
the configuration files.
iii) Make help: It acts as an online help.
2.Kernel configuration
i) Start graphical kernel configuration type\
$make config
ii)Select necessary options to configure kernel.
iii)Close kernel configuration window e=when finish.
3.Compiling kernel
To compile the kernel use following command
$make
4.Installing the kernel
To install the kernel use following command
$new-kernel-pkg -v --mkinitrd --depmod --install

5.Booting the kernel


To apply kernel configuration reboot the system using following
command
$reboot

You might also like