0% found this document useful (0 votes)
16 views18 pages

Linux Day5

Uploaded by

mohammedb.kassab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views18 pages

Linux Day5

Uploaded by

mohammedb.kassab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Linux Administration

Azza Khalel
[email protected]
Azza Khalel | LinkedIn
Day5 contents
• Boot process
• Managing system services
• Package management
• rpm
• yum
• dnf
• Scheduling
• cron
• At
• Storage administration
Linux boot sequence
• BIOS (Basic Input/Output System) / UEFI (Unified Extensible Firmware Interface)
• When you first turn on your computer, BIOS or UEFI SW boots up from ROM.
• the BIOS first performs some integrity checks called POST to make sure all HW are working right.
• If POST finds a problem, it will often show an error message on the screen
• Then, the BIOS searches for, loads, and executes the boot loader program (GRUB2, LILO),
• MBR (Master Boot Record) / .efi boot loader
• ON BIOS, the boot loader can be found in the Master Boot Record (MBR) which located in the 1st sector (512 MB) of the
bootable disk
• ON UEFI, there is a separate partition that stores files like .efi boot loader file
• Once the boot loader program is detected, it's then loaded into memory and the BIOS gives control of the system to it.
• The MBR contains information about GRUB, or LILO in very old systems.
• GRUB2 (GNU GRand Unified Bootloader) / LILO
• LILO, the linux loader is pretty outdated and rarely used in modern distributions.
• GRUB2 is the most full-featured and widely used today,
• it can handle booting multiple OS
• Looks nice with graphical or text-based menus and has a bunch of advanced options for users.
• Once GRUB2 loads itself up, it inserts the linux kernel into memory and hands control over to the kernel to finish the start
up process.
• The GRUB splash screen is often the first thing you see when you boot your computer. It has a simple menu where you can
select some options. If you have multiple kernel images installed, you can use your keyboard to select the one you want
your system to boot with. By default, the latest kernel image is selected.
• The splash screen will wait a few seconds for you to select and option. If you don't, it will load the default kernel image.
• In many systems you can find the GRUB configuration file at /boot/grub/grub.conf or /etc/grub.conf.
• Kernel
Linux boot sequence
• The kernel is often referred to as the core of any operating system, Linux included. It has
complete control over everything in your system.
• After the boot loader starts the kernel, the kernel takes over the computer recourses and
start initialization of all the background processes and services.
• First, it decompress itself into RAM, check the HW and loads device drivers and other kernel
modules
• Next, an initial process called systemd kicks off.
• The kernel then establishes a temporary root file system using Initial RAM Disk (initrd) until
the real file system is mounted.

• Services (systemd)
• Systemd has a ton of responsibilities to get the system booted and ready to use
• It is checking for any remaining HW that needs drivers loaded.
• It mounts up your file system and disks so they are accessible
• It starts launching all the background services you need like networking, sound, power mang.
• Systemd starts all services that should be started on the system and on the selected target.
• Reads files from /etc/systemd/system
Linux boot sequence
Controlling services and demons
• Systemd is the first process to start (PID1).
• Systemd demon manages startup for linux including service start up and service management in general.
• Systemd activates system resources, server demons and other processes both at boot time and on a running system.
• Listing service units
• #systemctl list-units –-type=service ➔ to list all active services

• # systemctl list-units --type=service –all ➔ to list all active and inactive

• #systemctl --failed --type=service ➔ to list all failed services

• #systemctl status sshd.service ➔ to check status of specific service

• Verifying status of a service


• # systemctl is-active sshd.service ➔ if its active or not

• # systemctl is-enabled sshd.service ➔ if its enabled or not

• systemctl is-failed sshd.service ➔ if its failed or not

• Controlling system services


• # systemctl start sshd.service

• # systemctl stop sshd.service

• # systemctl restart sshd.service ➔ stop the service then start

• systemctl reload sshd.service ➔ just reload the config files without stopping the service

• Listing unit dependency


• # systemctl list-dependencies sshd ➔ to check dependencies of the service

• Masking and unmasking services


• #systemctl mask httpd ➔ to stop the service and avoid to be started by mistake, no one can start it
Created symlink /etc/systemd/system/httpd.service → /dev/null.

• #systemctl start httpd


Failed to start httpd.service: Unit httpd.service is masked.

• #systemctl unmask httpd


Removed "/etc/systemd/system/httpd.service".
Linux package management
• RPM (RedHat Package Manager)
• RPM package files names consists of 4 elements
• Name-version-release.architecture.rpm
• To get your OS release
• #cat /etc/redhat-release

• To get your CPU arch


• #uname –a

• RPM used to install a package which already downloaded without any dependencies
• To download a package
• #wget <package_URL>
• YUM (Yellowdog Updater, Modified)
• Its designed to be a better system for managing rpm-based packages
• Its used to download and install any package with all its dependencies
• It uses repository concept.
• Starting from RHEL8, ther are 2 main repos
• BaseOS (all OS related packages)
• AppStream (any other packages)

• Dnf (Dandified YUM)


• is the next-generation version of the yum
RPM
• rpm -i <pck_name> OR rpm --install <pck_name>
• rpm -ivh <pck_name> (install verbose installation progress hash ###)
• rpm --install --nodeps <pck_name>
• rpm --install --force <pck_name>
• rpm -q <pck_name> ➔ print some info for installed package
• rpm -qi <pck_name> ➔ more info
• rpm -qp <pck_name> ➔ print some info for downloaded not installed package
• rpm -qpi <pck_name> ➔ more info
• rpm -qa ➔ list all installed packages
• rpm -ql <pck_name> ➔ print all files for this installed package
• rpm -qc <pck_name> ➔ print only config files of this package
• rpm -qd <pck_name> ➔ print only documentation files of this package
• rpm -qpl <pck_name> ➔ print all files for this downloaded package
• rpm -qf <file_name> ➔ print the pck of this file)
• rpm -q --changelog <pck_name> ➔ to know all changes happened for this package
• rpm -qR <pck_name> ➔ print all dependencies for this pck
• rpm -U <pck_name> ➔ upgrade the pck (if it’s installed,update it and if not installed,install it then
update)
• rpm -F <pck_name>➔ fresh the pck (if it’s installed, update it and if not installed, no actions)
• rpm -e <pck_name> OR rpm --erase <pck_name> ➔ uninstall pck
YUM
• Yum list ➔ print all installed packages
• Yum search <keyword> ➔ list all package which contain this keyword in the
name or summary fields only
• Yum info <pck_name> ➔ print information about pck
• Yum install <pck_name> ➔ to install package and its dependencies
• Yum provide <dir_path> ➔ to know this dir is related to which package
• yum update <pck_name>
• yum upgrade <pck_name>
• Yum remove <pck_name>
• Yum history ➔ to get the history of installing and removing packages
• yum localinstall <pck_name>➔ install a downloaded pck with it’s dependencies
Repositories
• Yum repolist ➔ to list all enabled repos
• Yum repolist all ➔ to list all enabled and disabled packages
• /etc/yum.repo.d ➔
• the dir which contain all .repo files which contain all repos
• Each file contain one or more repos
• Each section in this file represent a repo
• yum --enablerepo=<repo_name> ➔ to enable a specific repo
• yum-config-manager --enable repository <repository name>
• yum-config-manager --disable repository <repository name>
Own repo
• #mkdir /myrepo
• #cp /media/DVD_name/Packages /myrepo
• #chmod -R 755 /myrepo
• #createrepo /myrepo
• vi /etc/yum.repos.d/ownrepos.repo
[ownrepos]
name=that's my own repos
baseurl=file:///myrepo
gpgcheck=0 (not check from redhat or from any)
enabled=1

• #yum clean all


• #yum repolist ===> to list all system repos
Scheduling(periodic)
• cron
• /var/spool/cron/user_name
• crontab -e
• crontab -u <user_name> -e
• Syntax ⇒ min hour day month no.of.day cmd
• 0-59 0-23 1-31 1-12 0-7(sunday)
• Output is sent to mail until you redirect it.
• crontab -l
• crontab -u <user_name> -l
• crontab -r
• /etc/cron.allow ⇒ isn’t exist by default
• /etc/cron.deny ⇒ it’s exist by default
• Crontab mechanism ⇒ see the cron.allow then decide.
Scheduling(one time)
• at
• /var/spool/at/user_name
• at 17:30 [at 17:30, at now+2 min,at 17:30+4 days, at noon, at midnight, at
teatime ] teatime⇒ 5PM
• at> then writ wanted command and Enter then the second command
• Ctrl +d (at the end)
• Output is sent to mail until you redirect it.
• atq (list all at jobs)
• at -d <at_job-name> OR atrm <at_job_name>
• /etc/at.allow
• /etc/at.deny
String processing
• Use the wc and the diff commands to gather word file statistics and compare two
files.
• #wc <filename> ➔ to get number of lines, words and characters.
• #diff <file1> <file2> ➔ to get the difference between 2 files
• Search strings for patterns using the grep command.
• #grep [options] regular-expression filename(s)
• -i → ignore letter case
• -v → only shows lines that do not contain the regular expression.
• -r → searches files in the current directory and all subdirectories.
• The tr command can be used to translate characters from standard input and write
to standard output.
• #tr [option] string1 string2
#echo "Hello, world." | tr 'a-z' 'A-Z'
HELLO, WORLD
• cut command cuts fields or columns of text from standard input or the named file
and displays the result to standard output
• cut option[s] [filename]
• Options
• -f specifies field or column.
• -d specifies field delimiter (default is TAB).
• -c specifies characters and cuts by characters.
cut -f3 -d: /etc/passwd
• Organize data using the sort command.
• sort option[s] [filename]
• sort /etc/passwd ➔ rearrange by first field ASC
• sort –k4 –t: /etc/passwd ➔ rearrange by 4th field ASC and terminator is :
• sort –k4 –t: -n ➔ rearrange by 4th field numeric ASC
• sort –r ➔ rearrange Descending
Storage management
• 3 steps should be done to use a disk partition and access it’s data
• Create the partition
• #fdisk –l ➔ print full info about disks and their partitions
• #df –h ➔ print all mounted partitions which ready for use
• #fdisk /dev/sda [to create a new partition or delete a partition]
• #cat /proc/partitions
• #partporbe
• #reboot
• #lsblk ➔ to check block devices we have attached to our system

• Format this partition with a certain file system


• #mkfs -t ext3 /dev/sda1 OR mkfs.ext3 /dev/sda5
• #fsck ➔ to check the file system issues and try to repair it
• Lable the partition if needed (optional)
• #e2label /dev/sda1 mypart1
• Mount this partition to a free dir on our system
• Temporary mount
• #mount /dev/sda5 /dir1 OR #mount LABEL=mypart1 <mount_point>
• #df -h
• Permeant mount
• #vi /etc/fstab
HD_partition mount_point fs_type options dump pass
LABEL=mypart1 <mount_point> fs_type options dump pass
• After writing in fstab, you should reboot system or run mount command
SWAP
• #swapon -s ➔ print info about swap partitions
• Create a SWAP
• From disk partition
• #fdisk /dev/sdb ➔ create /dev/sdb1 partition
• #mkswap /dev/sdb1 ➔ make it a swap partition
• swapon /dev/sdb1 ➔ add it to swap area
• vi /etc/fstab ➔ add this partition on fstab file to be permanently on the system]
/dev/sdb1 swap swap defaults 0 0

• From file
• #dd if=/dev/zero of=/myswap bs=1024byte count=512000 ➔ to create a new file with
size 1024*512000=512MB, named /myswap
• mkswap /myswap
• swapon /myswap
LVM (Logical Volume Manager)
• If the HD was partitioned and then want to extend its size, These partitions
should be LVM to apply that.
• Partitions’ type should be LVM
• Then convert them to physical volumes.
• Put all physical volumes in a volume group.
• Then we can partition this volume group to logical volumes.
• Mount these logical volumes on your system; it will be your system partitions.

• Here, Data is stored in an extent, before that in the normal partition data is
stored in blocks.
LVM
• Create a partition
• #fdisk /dev/sda n p t 8e :wq
• Make physical volume
• #pvcreate /dev/sda1 #pvs #pvdisplay #pvdisplay /dev/sda1 #pvremove /dev/sda1
• Create volume group
• #vgcreate vg0 /dev/sda1 /dev/sda2 #vgs vgdisplay #vgremove vg0
• Create logical volume
• #lvcreate -L +50G -n lv0 vg0 #lvs #lvdisplay #lvremove lv0
• Make file system
• #mkfs.ext3 /dev/vg0/lv0
• mount and fstab
• #mount /dev/vg0/lv0 /part1
• #vi /etc/fstab
/dev/vg0/lv0 /part1 ext3 defaults 0 0
• #vgextend vg0 /dev/sdb ➔ will create a PV from this disk and expand the VG
• #vgreduce vg0 /dev/sda3
• #lvextend -r -L +10G lv0 ➔ will add 10G to this lvm and –r to extend the XFS File
system
• #lvextend –r –L 10G lv0 ➔ this will set this lvm to be 10G
• #resize2fs /dev/vg1/lv0
• #lvreduce -L -10G lv0

You might also like