You are on page 1of 251

/


.
:

.
:

Linuxcbt
red hat administrator 1
red hat administrator 2
/
John_Wiley_Redhat_Linux_Networking_and_System_Administration
RHCSA_Hands-on.Guide.to.the.Red.Hat.Exams
.


janateba@hotmail.com
https://www.facebook.com/?q=#/tibea2004

RHCSA/RHCE Egypt

---------------------------------------------------------------------------------------------------------------(History)
(4-----6)

(6-----7)
/
(8-----9)
/
-------------------------------------------------------------------------------------------------- (starting with login)
(10---13)

(13---16)
(help)
---------------------------------------------------------------------------------------------------- (File System)
(17---24)
FHS
(25---29)
(examine the file)
------------------------------------------------------------------------------- (user & permission)
(---30---)

(31---34)
/etc/passwd
(35---38)
(group)
(38---40)
(permission)
(---41---)
Umask
(42---43)
Special permission
(43---47)
Network user modules (Ldap Nis)
------------------------------------------------------------------------------------------- (linux management)
(48---49)
Inode
(50---51)
Links
(51---53)
Search
(53---55)
Archiving and compression
(56---66)
(string process manage)
(66---74)
(process management)
(74---77)
Job schedule (crond atd)
(---78---)
DF DU
------------------------------------------------------------------------------------------- (working with shell script)
(79---82)
Shell
(82---83)
Shell script
(83---84)
Return value
(84---96)
Shell variable
(96--100)
Standard I/O
(100-103)
(scripting)
--------------------------------------------------------------------------------------------- (storage drive)
(104-106)

(106-112)
Partitioning
(112-114)
File system
(114-116)
Mount
(116-118)
Secure erase
(118-120)
Swap
(120-126)
Logical volume management
(126-130)
RAID
(130-132)
QUOTA
(132-134)
ACL
(134-135)
F.S management
(135-137)
Autofs

RHCSA/RHCE Egypt

------------------------------------------------------------------------------------ (red hat installation)


(138-141)

(141-146)
Basic install
(146-152)
Network install (kickstart)
(152-164)
Hardware device and (proc sys)
-------------------------------------------------------------------------------------- (package installation)
(165-166)

(166-174)
RPM
(174-179)
YUM + REPO
------------------------------------------------------------------------------ (BOOT SEQUANCE)
(--180---)

(181-186)
Grub
(187-191)
Init
(192-198)
Service
(198-204)
Kernel (update install)
-------------------------------------------------------------------------------------- ( ) System admin tool
(205-213)
(cups)
(213-218)
Rsyslog
(218-226)
(Luks attr)
--------------------------------------------------------------------------------------------------------------networks
(227-238)
network management
(239-242)
network utilities
(243-245)
NFS
(--246---)
SSH-NTP
(--247---)
Selinux
------------------------------------------------------------Exams sample----------------------------------------------------

RHCSA/RHCE Egypt

Linux
History

1969
MULTICS
) (Bell telephone labs AT&T .
BLT
General Electrics .MIT .
BTL MULTICS
) (compiler )(loading program
DEC PDP7
) ( .
) (



. .
)

( . ) (
( PDP11.
)
.
RAM .
) ( .
.(man-page BTL
) Troff

BTL .
:
.
.
.

1971
. ) (1972 ) V2
( V5
.
1973

. AT&T
. .

.
USENIX 1974
.
.
1975

) (sun Microsystem .
Ex Vi
.
.
.

RHCSA/RHCE Egypt

.BSD
: .
BSD

BSD.
. 1977 PDP
IBM Interdata V7 1979

. awk, lint, make, uucp 400


c BTL
400 .

. C
) (BOURNE SHELL . expr findcpio

.
: Xenix
SCO Intel 8086 BSD
AT&T V7
.
.


.
AT&T
Minix 1991 .
BSD ) - ( 4.1

SUN Microsystems ,BSD 4.2
SunOS . 1983 :
SUN

IBM AIX DEC Ultrix HP HPUX SECO Xenix .
1980 AT&T " " " UNIX System V
SV3 BSD 4.x
.
IEEE POSIX UNIX97 FHS.

System V AT&T BSD .
.
AT&T )
(
: 1990 OSF UI USL
BSD . .
SCO OSF SCO
.

RHCSA/RHCE Egypt

1991 ) 1995 (1999


.

.
/

. Microsoft DOS
. .
.

Minix - 1984
.
Minix Intel 8086
. IBM )
(C ,
.
FSF GNU
. HURD
.
1991 0.0.1
. Intel 386 GPL
.
.
.

RHCSA/RHCE Egypt


:

-1 :
.
GPL


-2 ) ( : ) (
C GCC GNU .

.
/ x86 : IA86 x86 - x86-64
AMD MIPS sun PowerPC - Silicon - IBM S390 - - m68k -
.........

:
Monolithic

-3

. Microkernel .

)( .

) ( .
modules .

-4 ) :(modules : )(FS
) (udev ) ( .
.
)( :
-5

) (

. .
.
.
GCC
FSF

GNOME
) Xfree (X Window KDE

MYSQL POSTGREE SQL


/
/ . /
.
/ ) (

.
/

/ .
.
FSF .
.
/
.
.
1991 .
HURD /.
/ BSD .
MacOS X
.

RHCSA/RHCE Egypt

/:

/:

/ .
/ :
-1 : .
-2 : FSF .
-3 : .


. /
.
/
. )( )(
/ .
/ .
.
.
)
( : (gtk) + ) (QT
. XFCE, :
FVWM,Motif, Enlightenment, BlackIce.
www.distrowatch.com
. iso
.


.
.
1993 / .
.
" "
.
APT DEB APT
. APT
)(ftp web CD

linex
.

RHCSA/RHCE Egypt

/:


/ .
.1994
. ) :(
) (
) (.

.
) (

.
) (2003 ) (9x
/
.
) ( .
.

.
) Open SUSE SUSE(


) (
RPM .SUSE

RHCSA/RHCE Egypt

10

Beginning
The Linux


) (username ) (password /
)CUI (tty GUI .
) (GUI xdm X WINDOWS gdm) (gnome kdm )(KDE
/ 6 ) (virtual console ) (virtual console 1
.Figure 1-1 tty
Ctrl + alt + Fn n 1-6 #chvt n
Ctrl+alt+F1 ) x server
( .
)(CLI
Figure 1-1

)(GUI
Figure 1-1

)(terminal

(Real Console)-1 )(tty) (CUI
.
(Fake(Pseudo)-2 )(gnome KDE other
real console ).(ssh GUI terminal
terminal tty
(Pseudo) terminal GUI
open terminal Figure 1-2

RHCSA/RHCE Egypt

11

Applications System Tools Terminal :

Terminal

- :who Figure 1-4

Figure 1-4

ssh
)- : (How write command in Terminal
/
) (Figure 1-5

Figure 1-5

RHCSA/RHCE Egypt

12

) (command )(-
) .(-- ) (command ) (--help
) (-- ) (-
ls Figure 1-6
ls Figure 1-6

) (Figure 1-7

Figure 1-7

) (-- Figure 1-8


Figure 1-8

) (--help )(Figure 1-9


Figure 1-9

RHCSA/RHCE Egypt

13

HELPS

)) terminal )(Figure 1-10


Figure 1-10


)(terminal


)(

HELPS

.
/:
(manual page) man . /
. :
#man n command #man command
n . man less
man Figure 1-11
Figure 1-11



man
man


/
.

RHCSA/RHCE Egypt

14

HELPS

- :man

man /usr/share/man/ gzip


man .manpath
apropos man
man .man-k
]#apropos [keyword] = #man -k [keyword
man -k : whatis .apropos
:man
man 9 man
11.
NAME-1 :
SYNOPSIS-2 .
option .
.
.
][
> < .
} { .
.
DESCRIPTION-3 .
.
OPTIONS-4
.
EXAMPLES-5
.manual
AUTHORS-6
.
BUGS-7
.
COPYRIGHT-8
.
SEE ALSO-9
.mount
FILES-10
UNIX.BSD
HISTORY-11
-

info

. .
man .
info #info command pinfo
pinfo info

RHCSA/RHCE Egypt

15

HELPS

/usr/doc/ - /usr/share/doc/ . .

)(red hat documentation guide


.
)(yelp) (Genome help browser F1 Figure 6.1 & 6.2

RHCSA/RHCE Egypt

16

HELPS

)(--help
man

whatis man .
whatis - :
)#mandb ------- (Ubuntu, SUSE
)#makewhatis------- (Red Hat

-1 )(define problem
-2 )(search docs and kbase
-3 )(gather background information
-4 (gather relevant diagnostic info (sos report)) log file
-5 )(determine severity level
-6 )(contact redhat by web
tab
m m tab m
y n m tab
. Figure 6.4
Figure 6.4



.en_US.UTF-8 ) (Figure 6.5& 6.6
System-config-language system administration language

/etc/sysconfig/il8n
LANG

=#LANG

RHCSA/RHCE Egypt

17

)FHS (Filesystem Hierarchy standard

File system
Basic

.
.
/
/ . .

Linux Standard Base] LSB [
Filesystem Hierarchy Standard] FHS [

/ .
/ hardware .software
)FHS (FILESYSTEM HIERARCHY STANDARD

) (File system )(root directory) (/
).(/

) (fully qualified name /home/alice/website /home/alice/website/songs/song1.midi
Standard Linux Directory Scheme

RHCSA/RHCE Egypt

18

)FHS (Filesystem Hierarchy standard

Path
name

Contents
) (files ) (directory )(root
) (binary code
/bin/ls /bin/bash
) . (User Excitable /bin
/usr /usr/bin
.(kernel and boot loader) /boot/vmlinuz
)(devices devices
. /dev/console /dev/mouse /dev/cdrom
: -
/dev/mouse /dev/psaux PS2 /dev/cdrom /dev/hdc
. IDE
IDE /dev/hdx SCSI /dev/sdx x .
/
) (hotplug , udev /dev/
.
configuration file ./etc/passwd


/home
.a .so
libc. /lib/modules
mount mnt/cdrom/ .
.
./ usr/local/
. root /bin/fsck/
. /usr/sbin

. )
(/usr/share/ ) .(/usr/share/doc/
/usr/local/

/
/bin
/boot

/dev

/etc
/home
/lib
/mnt
/media
/opt
/sbin
/tmp
/usr

/usr/bin , /usr/include (compiling c) , /usr/lib , /usr/local , /usr/sbin , /usr/share , /usr/src , /usr/tmp

/
/var/log/ /var/spool/mail/
./var/spool/lpd
services
root
/proc /selinux

/var
/srv
/root


/ ) (X graphical environment
) (Nautilus ) (explorer .
-1 computer
application system tools File Browser-2
Figure 1-2 &1-3&1-4

RHCSA/RHCE Egypt

19

)FHS (Filesystem Hierarchy standard


Figure 1-2

Figure 1-3

Nautilus


- :
-1 spatial mode

-2 browser mode


File management
Figure 1-5

Figure 1-5 File Management

behavior

RHCSA/RHCE Egypt

20

)FHS (Filesystem Hierarchy standard

file management view


List .
Compact
Arrange items ) (
/
/ ) (FQN
)} (current working directory {cwd FQN .
pwd cwd:

)(TRANSPORT BETWEEN DIRECTORY

(change directory command) cd cd

cd : )(Table 1-1

- : ---
---

absolute pathname
relative pathname

absolute pathname )( / root )) (FQN


(/
rich@testbox[]$cd /etc
rich@testbox[]$ cd /usr/lib/NetworkManager
rich@testbox[etc]$
rich@testbox[NetworkManager]$

RHCSA/RHCE Egypt

21

)FHS (Filesystem Hierarchy standard

relative pathname (root directory) /


)(notFQN
) (Table 1-2 sample.txt .alice

FILE AND DIRECTORY LISTING



ls . shell
.ls
]ls [option] [file or directory

.(option) ls
-F

) (/ )*(
exec )@( symbolic link )=(
socket )|( FIFO (named pipe) First in First out %
-a
...
-R directory + sub directory
-l

-i
Inode number

- : ls -l ll

RHCSA/RHCE Egypt

22

)FHS (Filesystem Hierarchy standard

ls l :
-1 ) ( ) (d ) (c (b) character device .block device
-3 soft link .hard link
-2 .permissions
-5 .
-4 .
-8
-7 .
-6 .

FILE HANDLING
-

creating file

touch

copying file .
cp [OPTION] SOURCE DIRECTORY

myprog1 myprog2
mohammed cp

p cp



-f

r R
cp
cp r

a p + r
i

RHCSA/RHCE Egypt

23

)FHS (Filesystem Hierarchy standard

moving / renaming file ) ( mv


mv [OPTION]... SOURCE... DIRECTORY

test2 test1

mv
Jana ls
test 2
mv test1

jana
mohammed
mv

deleting file
:
}rm [OPTIONS] {FILE...

r rm

jana
rm
r

-f

create directory
mkdir :
}mkdir [OPTIONS] {DIRECTORY...

RHCSA/RHCE Egypt

24

)FHS (Filesystem Hierarchy standard


teba jana1 teba jana1
teba jana1 p

delete empty directory rmdir .rm r


}rmdir [OPTIONS] {DIRECTORY...

tree examine directory with tree

ls R
- : ) (. ls a
wild cards

RHCSA/RHCE Egypt

25

examing the file

EXAMING THE FILE


text file-1 .
executable file-2 .
data file -3
.binary code
-

file

stat
ls l

cat

]file [OPTIONS] [FILE...

]cat [OPTIONS] [FILE...


----
.
.
cat

-n
-b
-s
-A

tac cat cat


lessmore more less
cat more less
. :

RHCSA/RHCE Egypt

26

examing the file

) (Table 6-1

headtail a tail
10 n )($tail -n 3 text1
-f log file
b head
10

RHCSA/RHCE Egypt

27

Text editor

TEXT EDITOR

.

html
/ :
nano-1gedit
vi-2 vim) emacs (
nano
Pico :
]nano [OPTIONS] [FILE
nano
Ctrl + k =^k

-m
-v

gedit nano nano ) (shell


accessories gedit text editor
) (X window environment
gedit
vim
/ vi .
vi improved vim vim vi
vim
) ( $ vim myprog.c
vim mode - :
1- Command mode
2- Insert mode
.

RHCSA/RHCE Egypt

28

Text editor

insert mode i command mode Esc


EX mode )(:
:q

!:q

:w

:wq
or zz

][Count] command [where
command mode
count 23x 23 where .

-1
-2 )h(left) , k (up) , l (right) , j (down
-3
PageDown (or Ctrl+F)-4
PageUp (or Ctrl+B)-5
G-6 L H M
num G-7
gg-8
command mode
)Yank (copy

)Delete (cut

)Change (replace

yy or Y

dd

cc

Line

yl

dl

cl

Letter

yw

dw

cw

Word

)y

)d

)c

Sentence ahead

(y

(d

(c

Sentence behind

{y

{d

{c

Paragraph above

}y

}d

}c

Paragraph below

:set all

vim editor command mode


vi editor
:set
on
:set no
off
x
u U
P p
? / or
vim A x
emacs )
lisp use net
diary calendar (
- :
-2 -3
-1 auto save
#emacs myprog.c

RHCSA/RHCE Egypt

29

Text editor

emacs
Ctrl+h t (emacs tutorials).

i Ctrl+h . manual

f Ctrl+h
p Ctrl+h
alt+x c++-mode java-mode calendar

RHCSA/RHCE Egypt

30

Users
&Permission

/ ) (
. )
( .
- : user name UID .
- : group name .GID
:

root
-1 ) (root or super user

.

.
UID 0

-2 ):(human user

) (/temp/

UID 500
) : (system users) ( lp, news ,wheel ,www-data
-3
.
.
( )( UID 1 499

)
/etc/passwd : /etc/shadow /etc/group /etc/gshadow

/ .task
UID
) (user UID ) (user identification number
32 0 .4,294,967,295
login
. UID
user /etc/passwd
etc/shadow/ UID GID id .groups
id UID n ls ls ln

RHCSA/RHCE Egypt

31

The /etc/passwd file

THE /ETC/PASSWD FILE

UID
/ UID Directory services

UID
- :

1- Login name

2- Encrypted password placeholder



3- UID (user ID) number

4- Default GID (group ID) number

5-GECOS information: full name, office, extension, home phone

6- Home directory

7- Login shell

: x

root user security service
. system account
chfn GECOS service user /sbin/nologin
The /etc/shadow file
password root
user - :

The login name



The encrypted password

The date of last password change

The minimum number of days between password changed
The maximum number of days between password changed
The number of days before password expiration

The number of days after a password expires before the account will be disabled
account expiration date

A field reserved for future use

123456789-

RHCSA/RHCE Egypt

32

The /etc/passwd file

passwd -e

/etc/skel/ .

. ) (skeleton skel
.

user manger )(x window environment
system-config-users ) (terminal system admin user&group

useradd userdelusermod
useradd HOME
useradd -D
- :/etc/default/useradd




useradd -D



.


]useradd -D [option
-e expire date
-g
-s shell

RHCSA/RHCE Egypt

33

The /etc/passwd file

: root user
sudo useradd . root
/etc/login.defs. /etc/default/useradd
)useradd [options] LOGIN_NAME (username
:



)(primary group
)(secondary group
home
home


UID 500 999
)system user (service user

option
-c comment
-e expire_date
-g group_name_or_NO.
-G group_name_or_NO.
-m
-M
-p password
-s shell_name
-u uid
-r

jana13 primary_group jana secondary_group


teba jana1321983 uid 600
) (-d home_dir home directory .
userdel /etc/passwd HOME dir.
r .Home directory
)userdel [options] LOGIN_NAME (username
- :
usermod /etc/passwd :
)usermod [options] LOGIN_NAME (username




)(primary group
)(secondary group
home -d



L
uid

option
-l new_username
-c comment
-e expire_date
-g group_name_or_NO.
-G group_name_or_NO.
-m
-p password
-s shell_name
-L
-U
-u new userid

usermod jana3 teba:

RHCSA/RHCE Egypt

34

The /etc/passwd file

chpasswd chpasswd
user_name: password
. c ) (-c MD5 , -c NONE e


passwd --stdin
)(#echo 1321983 | passwd --stdin

chage l
]chage [options] [LOGIN
/etc/shadow

chage )(password aging

chage d 0 jana
-l )(chage -l user01
chshch chsh
chfn finger /etc/passwd
finger .
.

RHCSA/RHCE Egypt

35

Using Linux Groups

# finger rich
Login: rich
Name: Rich Blum
Directory: /home/rich Shell: /bin/bash
On since Thu Sep 20 18:03 (EDT) on pts/0 from 192.168.1.2
No mail.
No Plan.
#
USING LINUX GROUPS

- : ID
(group identifier number) GID .
primary group
) (secondary group
. 31 ).(secondary group
/etc/group /etc/gshadow
The /etc/group file
/etc/shadow GID
/ GID
Directory services UID

- :
1- The group name

2- The group password

3- GID (group ID) number

4- The list of user account


user manger )(x window environment
system-config-users ) (terminal system admin user&group
.
groupadd groupdelgroupmod
groupadd :
groupadd [options] group_name
r system group g group id
groupmod :
groupmod [options] group_name



gid

G :
groupdel
gpasswd
.

option
-n new_groupname
-p password
-g GID_NO.

#groupmod -G group_name user_name

RHCSA/RHCE Egypt

36

Using Linux Groups

.

.
Information Systems NetworkLDAP NIS+ NIS
.
/ /
.
- : shadow passwd pwunconv
shadow passwd shadow passwd
pwconv
pwconv shadow passwd
pwunconv passwd passwd+shadow
grpconv gshadow group
grpunconv group group+gshadow
: )(process userid groupid primary .groupid secondary
) (owner userid owner groupid .12 mode bits
.
12 mode bit
:user bit-1 3 ) ( userid
:group bit-2 3 ) ( primary groupid
secondary groupid groupid
:other bit-3 3 ) ( userid groupid
:special bit-4 3 ) suid sgid(sticky bit
/
id ) uid gid ( :
]id [OPTION] [USERNAME


gid primary group
gid
uid
uidgid

whoami
users )(who logon now

elvis 5 ) (terminal
) (terminal )(session
.

RHCSA/RHCE Egypt

37

Using Linux Groups

w users
]#w [-h | -s | -f] [USERNAME
:


from


tty





who w
/

su sudo

]su [OPTION] [-] [USER [ARG]...

Non-login shell

login shell

RHCSA/RHCE Egypt

38

Decoding file permissions

env

) (root user $ #

) (primary group
secondary group primary group
]newgrp [GROUP
newgrp=sg

Decoding file permissions


ls l
.
/ ) (
-1 )-2 (user owner )-3 (group owner )(permission


) (-rwxrwxrwx ) (- )(file
- :
- for files

d for directories

l for links

c for character devices

b for block devices

n for network devices

] [rwx
read r write w execute x x
cd

RHCSA/RHCE Egypt

39

Changing Permissions

:
:chown-1
:chgrp-2
:chmod-3 ) (rwx
R
)(recursive
Changing Permissions
chown [user] [:group] file...
chgrp GROUP FILE...

chmod - :
#chmod options mode file name
chmod chown chgrp

) symbolic method-1 (mode


numeric method-2
symbolic method
- :
a , o , g , u , , , ) + +(
= , - , + , ,
x , w , r , ,
.

RHCSA/RHCE Egypt

40

Changing Permissions

t , s

][ugoa][[+-=] [rwxXstugo

og-r
))(who(u+g+o+a) operator(+ - =) permission (r+w+x+S+t
o g - r .
:
o chmod ugo+r file:

o chmod o-wx dir:

o chmod --reference file1 file2
--reference option
numeric method
user group
.other
4 r 2 w 1 .e

6 user 2+4 , w , ruser


0 group group
0 other other

properties
.

RHCSA/RHCE Egypt

41

)Default File PERMISSIONS (umask

) DEFAULT FILE PERMISSIONS (UMASK

umask :
) (user) (group) (other umask ) (octal digit chmod

.umask
umask .
(-rw-rw-r--) 664 .umask
umask .
) ( - :
) 666-umask (files
666

) 777-umask (directory
777

777 binary

default permission umask- :


umask

#umask 022

RHCSA/RHCE Egypt

42

special permission


umask 002 022 root
- : 664 775
) :(root user 644 755

SPECIAL PERMISSION
SUID, SGID, Sticky bit

Special permission

SUID Set user ID


SGID Set group ID
Sticky bit

(multi-user access) SUID-1


client user
passwd /etc/shadow root
special
permission SUID passwd root
.
SGID-2
-a execute group x SUID
)(x
-b directory SGID
owner owner .
sticky bit-3
-a
-b
.
)(process uid uid
groupid groupid .

set-groupid bit
groupid set-groupid
.

RHCSA/RHCE Egypt

Network Based User Models

43


Permission

U
rwx
s

s = SUID + X

G
rwx

S=SUID

#chmod u+s filename


#chmod g+s filename/dir
#chmod +t dir
SUID

s
s = SGID + X

O
rwx

S=SGID

t = sticky bit + X

T
T= sticky bit

SUID
symbolic
SGID

Sticky bit

numeric

#chmod 4777
special permission 7
[root@localhost ~]# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 27012 Aug 22 2010 /usr/bin/passwd
permission
$ mkdir testdir
$ ls -l
drwxrwxr-x 2 rich rich 4096 Sep 20 23:12 testdir/
$ chgrp shared testdir
$ chmod g+s testdir
$ ls -l
drwxrwsr-x 2 rich shared 4096 Sep 20 23:12 testdir/
$ umask 002
$ cd testdir
$ touch testfile
$ ls -l
total 0
-rw-rw-r-- 1 rich shared 0 Sep 20 23:13 testfile
$
NETWORK BASED USER MODELS
:
authconfig-tui
A menu-based configuration utility for network authentication clients
authconfig
A command-line based version of authconfig-tui
NSS(Name Service Switch) NSS ( Naming Service)
.( ) name resolution /etc/nsswitch.conf

RHCSA/RHCE Egypt

44

LDAP

-2 ) (source
-1 )(date base
-1 ) (database ) (: passwd shadow group hosts
.
-2 ) (source .

.
Database
Passwd shadow group hosts automount
passwd ) (file
/etc/passwd .ldap
Source
file-1 /etc/passwd
(network information system) nis-2 1980 UNIX.
.
nisplus-3 nis public key mechanism
(Lightweight Directory Access Protocol) ldap-4 standard network-based naming protocol
.
) (directory service . (Distinguished Name) DN
.
NIS LDAP
(system security service) sss-5 )(authentication provide
) (authentication configuration tool SSSD
LDAP .
hesiod-6 ) (MIT )(DNS
.
/etc/nsswitch.conf
nsswitch.conf source
.
/etc/nsswitch.conf :

passwd Jana )(files


/etc/passwd LDAP .nis
/etc/hosts .nis
.DNS
)(Lightweight Directory Access Protocol) (LDAP
Directory .
Directories ) (write-once/read-many systems
) (relational databases .
Directories . .directory
.
LDAP

1980 . (DAP) Directory access protocol X.500 .


LDAP DAP TCP / IP
ldapd DAP X.500.
) (ldap gate .DAP LDAP )) (slapd (standalone LDAP Server TCP / IP
X.500.
LDAP ) (Standalone ldap server OpenLDAP
Netware Directory Services Red Hat Directory Server Active Directory
.

RHCSA/RHCE Egypt

45

)The Network Information Service (NIS

slapd ) (schema attribute .


) (schema )(.attribute
UID ) (attribute .
uidnumber uid . Mapping
LDAP ) (admin :
Base DN -1
) (directory server distinguished name
.
) Base distinguished name (Base DN .
Base DN " "dc=example,dc=com ""ou=People,dc=mycompany,dc=com
.
Server FQDN -2
) (remote network . NIS IP
. LDAP ) .Fully Qualified Domain Name (FQDN
TLS .
CA Certificate -3
TCP/IP plain text LDAP .TCP/IP
.
TLS .
) (CA Certificate FQDN ) (public key
.
NIS ) (client daemon LDAD .authentication
OpenLDAP library calls . Base DN server
URL /etc/openldap/ldap.conf CA Certificate /etc/openldap/cacerts
SSSD /etc/sssd/sssd.conf
LDAP LDAP-PACKAGE ldapadd ldapmodify .ldapsearch
)THE NETWORK INFORMATION SERVICE (NIS

ypserv .host record groups passwd


/etc/hosts /etc/group/etc/passwd .NIS NIS
.NIS map
NIC client ypbind /etc/nsswitch.conf NIS
NIS Client
NIS Server .
ypbind service .
chkconfig.
NIC client NIC server NIC
NIC clients engineering NIC server engineering
marketing
.

RHCSA/RHCE Egypt

46

)The Network Information Service (NIS

NIC domain /etc/sysconfig/network domain_name


NIC client NIC server .
NIC server ) (client address .
/etc/ypserv.conf yp ypservypbind
Domain server /etc/yp.conf:
domain example.com server 172.168.1.1
))LDAP
system-config-authentication nsswitch.conf

ypbind.
system-config-authentication system admin authentication :

local accounts only LDAP

ldap Base DN server TLS


LDAP PLAIN TEXT kerberos password
LDAP password

RHCSA/RHCE Egypt

47

getent

System-config-authentication ).System Security Services Daemon (SSSD


SSSD LDAP .
. SSSD .
SSSD . nsswitch.conf
) NIS LDAP(.
SSSD .
SSSD system-config-authentication
/etc/sssd/sssd.conf

. /var/log/sssd
GETENT

getent passwd getent .


/etc/passwd LDAP.

. ) (override .
LDAP 4200 userid
workstation client 500

System-config-authentication authconfig-tui :

LDAP

authconfig-gtk

RHCSA/RHCE Egypt

48

Inodes

Linux
Management
INODES

- :
-1 )(data
-2 )(Inode) (meta data
-3 )(dentry

Inode
/
Inode X
56689 Inode
Inode
Inode table 1M
.
Inode number ) (metadata :
file type, permissions, UID, GID
UID, GID
)the link count (count of path names pointing to this file

)the file's size and various time stamps(time access

)pointers to the file's data blocks on disk (location of data in hard disk

other data about the file

)(file type

o
o
o
o
o

Timing information
atime ctime mtime


Inode number .Inode number
.

RHCSA/RHCE Egypt

49

Inodes

blocks block 1k 8 Inode Inode


128 byte . block Inode mke2fs -j -b 2048 -i 2048

Inode and Directory

) (cp , mv , rm Inode number


.
)(Inode

-1 stat

-2 ls i

RHCSA/RHCE Egypt

50

Hard link &soft link

HARD LINK &SOFT LINK


) (link hard soft links
.
hard link-1- :
(symbolic)soft link -2
Hard link


Inode
media
partition
.
ls l
2 hard
link 3 hard
link . hard link

ln- :
]ln [OPTION...] TARGET [LINK
or
]cp [-l] TARGET [LINK
Soft link
hard link Inode
l . media

ln s- :
]cp [-s] TARGET [LINK

or

]ln [-s] TARGET [LINK

soft link

hard link

RHCSA/RHCE Egypt

51

/locating the file

/ LOCATING THE FILE

/ :
-

)(X server
search for files search for files

places

locate
updatedb
locate [OPTION]... PATTERN...
]>[-i <remove case sensitive

find find
criteria-2 root directory (directory)-1 action-3
)find (root directory) (criteria) (action
find
Directory-1 )(.
criteria-2
action-3 print

RHCSA/RHCE Egypt

52

/locating the file

criteria name .
criteria find

action find print

action find exec


}{ );( \ );\(

RHCSA/RHCE Egypt

53

Archive and Compressing

which

whereis
which

which command

ARCHIVE AND COMPRESSING

Archive

Compressing

Compressing- :Uncompressing
) (x server archive mangerapplication accessories archive manger

gzipgunzip
1) #gzip file1

2) #gunzip file1.gz

.gz
#gzip -c file1 > file1.gz

zcat .gz zcat 1million.txt.gz

RHCSA/RHCE Egypt

54

Archive and Compressing

bzip2 bunzip2

.bz2
#bunzip2 jana.bz2

#bzcat filename

) (Compression Ratio Compression Ratio bzip2 gzip
Compression Ratio
.
zip zip PKZIP MS-DOS /
. zip
#zip


#zipcloak
#zipnote

#zipsplit

#unzip

#zcat

tar . :
[OPTION...] [FILE]...Function

archive

RHCSA/RHCE Egypt

tar

55

Archive and Compressing

tar f

) (- tarct = tar-c-t
tar



gzip
bzip2
tar.xz
)(verbose

-A
-r
-z
-j
-J
-v
-c new_dir

RHCSA/RHCE Egypt

56

STRING process mangment

STRING PROCESS MANGMENT


/ text encoding
encoding .
encoding )ASCII (American Standard Code for Information Interchange
cat cat tab .

$
tab ^I

Ctrl ^n

cat -A

TAB CTRL

wc

)(word
/ tab
.

RHCSA/RHCE Egypt

57

finding text

FINDING TEXT

grep
. - :

] ) [file ( ] pattern #grep [options


fgrep
grep basic regex
egrep grep extended regex
grep

$ grep -e t -e f file1 :
capitalsmall

FOR Perl-regex
FOR

-P
-f

FOR basic-regex
FOR match whole line

-G
-x

FOR extend-regex
FOR invert match

-E
-v

)REGULAR EXPRESSION(regex

:
@ . com
,
a h
. regex
regular expression
) (patternregex

^ cart ) (line that begin with

RHCSA/RHCE Egypt

58

finding text

$ dollar sign )(the line end with .


Regular expression :
) literal character-1 (
wildcards-2 regex ) (. ....
modifiers-3 *
anchors-4 ) (pattern ^ $
(dot) .

] [ bracket expression
] [abc a b c
] [a-f a f small
] [A-F A F capital
] [^a-f a f
] [a-fA-F A (capital &small) F
] [1-9 1 9
] [!

) ( modifiers
Modifiers




= n
1 7 n=minimum m=maximum
m
n

*
+
?
}{n
}{n,m
}{,m
}{n,

RHCSA/RHCE Egypt

59

finding text

\ )(escape . \. .

grouping
) (
| )(or

)REGULAR EXPRESSION (REGEX

RHCSA/RHCE Egypt

60

finding text

sort
sorting


.
) sort ( .
) ( ) (sorting )
( .

sort

RHCSA/RHCE Egypt

61

finding text

sort n

o u
sort
) sort key (.

ls k
n

sort key k5 k7
t : )(-t :
uniq ) ( . .sort
cut sort ) (

-d tab

RHCSA/RHCE Egypt

62

finding text

Paste
tab
diff

RHCSA/RHCE Egypt

63

finding text

tr
#tr a-z A-Z < lowercase.txt

tr :

aspell ) (aspell check , aspell list :


-c file||check file

-l || list

fmt
split
] ]split [SWITCHES] [FILENAME [PREFIX

split --lines=190 - < oldfile.txt


split -190 oldfile.txt
.

split --lines=190 - newfiles < oldfile.txt


split -190 < oldfile.txt

RHCSA/RHCE Egypt

64

awk

(stream Editor) sed


basic_regex_expression r extend_regex_expression
-1- : -2 . script
]#sed OPTIONS [SCRIPT] [INPUTFILE
#sed -e 's/dog/cat/' -e 's/hi/lo/' pets

f -e script ) (sed e script_file ) (-i file_name
:sed )' ('/regex/ )' ('\%regex% ''regex
) d ( ) p (n ) }{ command
( ) s ( sed
s search sed
's/regexp/replacement/flags':
) (regex )(replacement
flags s g : globally replacement
number g
p
w )(w file_name
$sed 's/mr./mrs./g' <gamal> lila
mr. mr. mrs. gamal
lila
#sed 's/dog/cat/g' pets
dog cat pets
#sed -n '1p' grep.test.txt -
#sed -n '2p' grep.test.txt -
#sed -n '$p' grep.test.txt - regex
d 'sed '/^$/d' grep.test.txt: n
.p
AWK

.
)-: regex grep
) (redirection pipes
&& || - (
awk #awk 'BEGIN {print "Test Program"}' :
" "Test program awk
awk pattern {action} : " "pattern " "action
" "BEGIN
" "print "."Test program
) $0 $1 - $2 - (
)( -F fs v
< ): < = , == , =! , > = , > ,
~ , ) ( !~ , ) ( ( regex /../
awk '{print $0}' grep.test.txt
awk '{print $1}' grep.test.txt
awk '{print $2}' grep.test.txt 2
2 awk '{print $2,$1}' grep.test.txt
awk '/Red/ { print $0}' grep.test.txt
2012 awk ' {if ($2 ~ /2011/) {print $0 }' grep.test.txt
awk '/2011$/ { print $0 }' grep.test.txt 2011
awk:
`1- name=`whoami
'}#awk v name=$name 'BEGIN{print "Welcome",name
'}2- awk 'BEGIN{name="Khalid"}{print "Welcome",name
.

RHCSA/RHCE Egypt

65

awk

+) : - , * , / , % , ) 0 1 ,
( () , += , -= , *= , /= ,
%= , ++ , -- , 1 (
""AWK
:NF
:NR
: FS
:FILENAME
:RS ,
:ORS
:OFS

}) {do this action ( ) {do this action} else ( 1) if
}) { the action ( 2) while
}) ( 3) do {the action} while
;continue or ;break }) { the action ( 4) for
#!/usr/bin/awk -f #awk -f program_name

AWK
awk :


" "
)atan2(y,x

)cos(x

)exp(x

)int(x

)log(x
1 0
)(rand

)sin(x

)sqrt(x
)(rand
)srand(x
:


) gsub(r,s,t) -gsub(r,s " "r " "s " "t
$0
" "t " "s " "t
)index(s,t

""x
)length(x
" "r ""s
)match(s,r
" "s " "r ""r
)split(s,a,r

)tolower(s

)toupper(s
}) {Action( function test1
awk
: awk
:
arrayname[string]=value
:value
:string )(index
:arrayname
for.in for (var in arrayname) {action } :
:arrayname :action
:in
:var
)(index
]delete arrayname[index
delete :
awk :
]for(var in arrayname){delete array[var
.

RHCSA/RHCE Egypt

66

Process Management

PROCESS MANAGEMENT
) (application ).(process
) .(application RAM ).(process
) (execute exe msi .binary
) (process ps tty
pts PID
:
: ) " (" daemons
). (Services
) ( ) .(client
) (root user
lp, bin, www, mail).( .
: .
: .
PID
process process PID PPI
Parent Process ID Process .
write on fault
nano bash bash parent nano bash
10 MB RAM nano Size on RAM , Instruction
set ) ( Customize .

(1 load
(2
(3 tty 3 tty 3
child.

1) Foreground Apps:
web server ) (2) Background Apps :
ps .

man ))(Unix option (-) BSD option GNU option (--
parameter ps





pid

terminal
.

a x terminal

RHCSA/RHCE Egypt

67

Process Management

ps -ef ps aux
Z

register format

PID text
editor nano
stat stat
process SN
(1
)1. Runnable (R
)2. Voluntary (Interruptible) Sleep (S
)3. Involuntary (Non-interruptible) Sleep (D
)4. Stopped (Suspended) Processes (T
)5. Zombie Processes (Z
:Runnable (R)-1 Runnable .
) ( runnable
. runnable
.
:Voluntary(Interruptible) Sleep (S)-2 .
network daemons httpd . )) (client (
.
:Involuntary (Non-interruptible) Sleep (D)-3
. block block .
. .runnable
:Stopped (Suspended)Process (T)-4 .
. CTRL-Z .
:Zombie Processes (Z)-5 zombie stat
. zombie process executing .
.
:
<: The process is running at high priority
N: The process is running at low priority.
L: The process has pages locked in memory.
s: The process is a session leader.
l: The process is multi-threaded.
+: The process is running in the foreground.
Services Daemons Daemons d
http =httpd ,vsftp =vsftpd
.

RHCSA/RHCE Egypt

68

Process Management

top ps

.
.

top top

gnome-system-monitor
top )(x server
system tools system monitor

Application

edit preference %cpu



.

RHCSA/RHCE Egypt

69

Process lifecycle

pgrep

]pgrep [SWITCHES] [PATTERN

PROCESS LIFECYCLE

Process Admin
1) Start
)2) End (Kill
- start-1 ) (start process :
-1 )(process creation
-2 )(command execution
:
.
- :
-1 ) (creating new process Forking
forking .
) (child ) (parent
. umask
-2 ) (new command creation Exec-ing
execing
.
execing . umask

:
forking execing network daemons execing forking login /sbin/init process Mother of all Process and Parent of it self
init kernel process management Scheduler
kernel
init pstree

RHCSA/RHCE Egypt

70

process SCHEDULING

pidof
pid

strace

redhat$sudo strace -p 5810

)(ending process
) (normal exit
) (signal ) status code (return value .
.status code
R S D T Z
PROCESS SCHEDULING

.
)(cpu .
) .(scheduling ) (dynamic value
) (fixed value .
) (priority ps top PRI
: backup 3 Access Data
30 3 Access Data
backup . Antivirus

.
static value niceness value 20- 19 0
)(priority
nice value )( priority )(
: 3
.
nice process niceness :

RHCSA/RHCE Egypt

71

process SCHEDULING

simulation 19
NI nice value PRI priority
20- 19
nice priority

renice niceness value R


pid

19 ) (- nice -19 19
Priority root
Priority 15 0 )(greedy process
load
- end-2 :end process signal kernel / .kill
signal
.
) Software interrupts( .

. .

RHCSA/RHCE Egypt

72

process SCHEDULING

) (signals kill l man 7 signal:

)(signals
signals .
Hardware exception
.
Software condition

Terminal Interrupts
ctrl + c signal 2 ctrl+z signal 20
Other process
signals
kill Kill signal .

signal
-1
:
) Terminate( : )(killed
) Ignore( :
:
Core
core .
: .
) Stop(
-3
-2
-4

RHCSA/RHCE Egypt

73

process SCHEDULING


kill 9
15 9 .
terminated (Default Signal) Process #kill -15: gracefully end
#kill -9: Force Kill
# kill -1: service

pkill

Killall


]pkill [-signal] [SWITCHES] [PATTERN

system monitor end process


Kill process top
k

RHCSA/RHCE Egypt

74

)Job scheduling (task


JOBS

) (job )(foreground
) (background & & $cat teba
job number ) (background jobs
&>$nohup <command

+
background foreground fg jobs bg

kill job %

) JOB SCHEDULING (TASK

: at crontab
Cron ) (cron services 10
. crontab
)(cron crond daemon .single user mode
cron )(/etc/cron.allow,/etc/cron.deny
)- :(/etc/cron.allow cron
cron ./etc/cron.deny
)- :(/etc/cron.deny .cron
).(root user
.

RHCSA/RHCE Egypt

75

)Job scheduling (task

anacron
anacron .
.
.
. anacron ./etc/anacrontab
:

cron table
cron table /etc/crontab cron table
-1 ) comment( )(#
-2 ) environment variable( =name
-3 ) cron command (cron table .

crontab crontab .crond daemon


crontab var/spool/cron/
crontab vi .
crontab:
]Syntax: crontab [-u user] [option
-e
Edits the users crontab
-l
Lists the users crontab
-r
Deletes the users crontab
-i
Prompts before deleting the users crontab
.

RHCSA/RHCE Egypt

76

)Job scheduling (task

) (root user crontab crontab


.
Crond daemon crontab .
Crond daemon .crond
service .chkconfig

/etc/crontab /etc/cron.d
crontab crontab :
./etc/crontab
. run-parts
crontab /etc/cron.d crond

/etc/cron.d ./etc/crontab /

crontab crontab :
-1 crontab /var/spool/cron
crontab .
-2 crontab

) (run as administrator in windows .
/etc/cron.d . sysstat
./etc/cron.d
run-parts /etc/cron.hourly/
anacrontab run-parts .cron.period
: /etc/cron.d/ 0hourly anacrontab run-parts
/etc/cron/hourly

run-parts .
.

RHCSA/RHCE Egypt

77

)Job scheduling (task

/etc/cron.hourly/ 0anacron
anacron . /etc/cron.d/0hourly
anacron run-parts .

)( )(
. >crontab
) /tmp/ crontab (


:tmpwatch /tmp/
240 /tmp/
.
. crontab /etc/cron.daily
.
at) atd daemon (at "
" 2:00 am . :

at atd daemon
) (/etc/at.allow , /etc/at.deny cron .
atd daemon at f
at [-f filename | -m] TIME
-d
-c
Ctrl+d
-l

batch at

:at
# at 9am
# at now + 3 days
# at 1:30 3/22/10
# at 10:07am
>at
at> wall Hello World
>at> <EOT

RHCSA/RHCE Egypt

78

df

DF

df

DU
df
df

.
-h
) ( -s

RHCSA/RHCE Egypt

79

Working
With Shell & script

.
.
/
-1 : kernel .

.

-2 : FSF
emacs gcc .
-3 : . .
-4 CLI GUI
/ . " "Package
.
package manger
.
SHELL


"" shell /.

) . (shell scripts .
:
-1 history
history terminal .login
./bach_history c history c history
!! !-5 !c .c

-2 tab
tab .

RHCSA/RHCE Egypt

80

TYPE OF SHELL

TYPE OF SHELL

Shell

)(Description
.
/ Bash
AT&T . ) $ root .(#

Sh
Bourne shell

bash

) .( Bourne-Again Shell / .
) ( AT&T
.$
- C .

Ksh
Korn shell
ash


-
) (alias
. .%
.
. tcsh

csh

.zsh

Bash . .
) ( . .
SHELL CONFIGURATION FILE
sh

/.profile

ksh
tcsh
zsh
bash

) (
/.kshrc & /.profile

~/.history,~/.login,~/.cshdirs

) (

~/.cshrc

/etc/csh.login

/etc/csh.cshrc

/etc/zshenv,~/.zshenv,/etc/zprofile,~/.zprofile,/etc/zshrc,~/.zshrc,/etc/zlogin,~/.bashr

/etc/bashrc

~/,bashrc

~/.bash_profile

/etc/profile.d/*.sh

/etc/profile

/etc/profile login state /etc/bashrc non-login state


. / etc/skel/
shell :
.2 wildcards * ? $
. 1
.-4 .
.3 / | &".
-6 .
.-5 .
shell . shell
BASH SHELL INITIALIZATION
Login, Non-login, Interactive, and Non-interactive Shells
- :login shells-1 . CLI virtual
console ssh login shell
X X login shell
.non-login shell interactive non-interactive

RHCSA/RHCE Egypt

81

TYPE OF SHELL

subshells X .interactive shell


. Non-interactive shell

-1 : /etc/profile . login shell


PATH USER HOSTNAME HISTSIZE
/etc/profile
-2 ) /etc/profile.d/*.sh RPM
. RPM RPM
.
. RPM
-3 ) (home directory
~/bach_profile
$/HOME/bin PATH
-4 ~/. bashrc
- :Non-login shell (Interactive)-2 ) (console ). (Terminal
) (alias shell login shell
non-login shell ~/. bashrc home
./etc/bashrc/ /etc/bashrc
users default umask. PS1
- :Non-login shell (non-interactive)-3
.BASH_ENV login shell ~/.bash_logout
.

RHCSA/RHCE Egypt

82

shell script

/etc/skel
.
. . home directory
)(.

- );(

subshell ) (

subshell bash sub shell exit


echo $SHELL ------- $SHELL .chsh l shell /etc/shells
]#chsh [-s shell] [-l] [-u] [-v] [username
) ( ) ( /.
shell configuration file scripts
>$type <command
type

) (script file > file <scriptname


#!/ bin/name name bash, sh, csh, ksh
Cygwin
built-in built-in
) (built-in
> enable n <built-in app enable . n
SHELL SCRIPT

: , automation ) (script
.
interpreter . interpreter
) /bin/bash ( /bin/sh . ) (interpreter
.
Prog:
prog App:
)Window : .exe or .msi (Microsoft Installer
Linux .bin

RHCSA/RHCE Egypt

83

shell script

Compiler & interpreter


Compiler

Interpreter


binary file




Bash PerlPython
C++C

compile exe bin


compiled lang. compiled Interpreter Java byte code
bin Interpreter lang.
Script
)(script :
-1 :
) (interpreter
)!(#
#!/bin/python
Python Interpreter Python

-2
-3 ) (executable chmod
>#chmod u+x <scriptname
Script
) (script foo.sh ) (home directory
foo.sh ) ("no such file or directory" error.

. PATH PATH

-1 ./script ~/script ) (.

-2 PATH
-3 /bin root ~/bin

RETURN VALUE
.
) (requesting process parent child child .
) ( return value .exit status
parent ) return value ( child.
.

RHCSA/RHCE Egypt

84

shell variable

return value 0 , 255 return value


.
return value 0 0 .
return value )?( return value
?$echo $

return value 0


description
code
Description
Successful completion of the command
128
Invalid exit argument
General unknown error
128+x
Fatal error with Linux signal x
Misuse of shell command
130
Command terminated with Ctrl+C
The command can't execute
255
Exit status out of range
Command not found
RUNNING MULTIPLE COMMAND CONDITIONALLY

code
0
1
2
126
127


-1
-2
-3 ;
-4 && || EXIT STATUS
&& | | . .
return value .
.
.

&& return value .0


mkdir . mkdir
| | . " "
return value . .


.
SHELL VARIABLE

) (A=apple )" ("dereferenced $


, echo $A ) (environmental variable
. child process export local variable .environmental variable set env printenv
environmental variable shell variable

shell variables
shell variable .
) (shell variable ) (scripts .
environmental variable -2
)local variable -1 (shell variable
.

RHCSA/RHCE Egypt

85

shell variable

local variable

environmental variables

environmental
. .
environment .

#echo $variable_name
echo $ - :
local variable
#A=apple - : A apple
)=( .

$VAR syntax. VAR=value


- : ) (a-z )(1-9 )_( capital small
( ) quotas:

.
.

. .
environmental



ALIASES


.

variable
BASH
BASH_ALIASES
BASH_ARGC
BASH_ARGV

RHCSA/RHCE Egypt

shell variable

86

BASH_CMDS

BASH_COMMAND

BASH_ENV

BASH_EXECUTION_STRING The command(s)passed using the bash c option
BASH_LINEO

BASH_REMATCH

BASH_SOURCE

BASH_SUBSHELL
.0 .
(minor & major)
BASH_VERSION
BASH_VERSINFO
(major)
If set to a valid file descriptor (0,1,2), then trace output generated from the set x debugging option can be
BASH_XTRACEFD

redirected. This is often used to separate trace output into a file.


-X'. ( '210)
.

BASHOPTS
BASHPID
COLUMNS
COMP_CWORD
COMP_LINE
COMP_POINT
COMP_KEY
COMP_TYPE
COMP_WORDBREAKS
COMP_WORDS
COMPREPLY

DIRSTACK
EMACS
EUID
FCEDIT
FINGNORE
FUNCNAME
GLOBIGNORE
GROUPS


PID




The nal key used to invoke the current completion of a shell function.
An integer value representing the type of completion attempted that caused a completion shell
function to be invoked.
The Readline library word separator characters for performing word completion
A variable array that contains the individual words on the current command line.

A variable array that contains the possible completion codes generated by a shell function.
TAB
A variable array that contains the current contents of the directory stack.
Indicates the emacs shell buer is executing and line editing is disabled, when
set tot.
EMACS
The numeric eective user ID of the current user ID
The default editor used by the fc command
A colon-separated list of suxes to ignore when performing le name completion.

The name of the currently executing shell function


A colon-separated list of patterns dening the set of le names to be ignored
by le name expansion.
A variable array containing the list of groups of which the current user is a
member.

RHCSA/RHCE Egypt

shell variable

histchars
HISTCMD
HISTCONTROL
HISTFILE
HISTFILESIZE
HISTIGNORE
HISTSIZE
HISTFILE
HOSTNAME
HOSTTYPE
IGNOREEOF
INPUTRC
LANG
LC_ALL
LC_COLLATE
LC_CTYPE

Up to three characters, which control history expansion.


The history number of the current command. HISTORY

Controls what commands are entered in the shell history list.
(./bash_history) history
history
A colon-separated list of patterns used to decide which commands are ignored for the history le.
history
Contains the name of the le that should be read when the shell needs to
complete a hostname.
DNS server
A string describing the machine the bash shell is running on.
The number of consecutive EOF characters the shell must receive before
exiting. If this value does not exist, the default is 1.
The name of the R eadline initialization le (the default is .inputrc).
The locale category for the shell.
Overrides the LANG variable, dening a locale category.
Sets the collation order used when sorting string values.
Determines the interpretation of characters used in le name expansion and
pattern matching.

LC_MESSAGES

Determines the locale setting used when interpreting double- quoted strings preceded by $.

LC_NUMERIC

Determines the locale setting used when formatting numbers.

LIENO

The line number in a script currently executing.

LINES

Denes the number of lines available on the terminal.

MACHTYPE
MAILCHECK
OLDPWD
OPTERR
OSTYPE
PIPESTATUS
POSIXLY_CORRECT
PROMPT_COMMAND
PROMPT_DIRTRIM
PS3

87

A string dening the system type in cpu-company-system format.


How often (in seconds) the shell should check for new mail, (default is 60).
The previous working directory used in the shell.
If set to 1, the bash shell displays errors generated by the getopts command.
A string dening the operating system the shell is running on.
A variable array containing a list of exit status values from the processes in the foreground
process.
If set, bash starts in POSIX mode.
If set, the command to execute before displaying the primary prompt.
An integer used to indicate the number of trailing directory names to display when using the \w and
\W prompt string escapes. The directory names removed are replaced with one set of ellipses.
The prompt to use for the select command.

PS4

RHCSA/RHCE Egypt

88

shell variable

The prompt displayed before the command line is echoed if the bash -x parameter is used.

PS4

The current working directory.

PWD

Returns a random number between 0 and 32767. the random number generator.

RANDOM

The default variable for the read command.

REPLY

The number of seconds since the shell was started. Resets the timer to the value.

SECONDS
SHELL


A colon-separated list of enabled bash shell options.
Indicates the shell level, incremented by one each time a new bash shell is started.
A format specifying how the shell displays time values.
read

Directory name where the bash shell creates temporary les for its use.

SHELLOPTS
SHLVL
TIMEFORMAT
TMOUT
TMPDIR
UID

The numeric real user ID of the current user.


) (shell variable
) .(environmental variable
process id user id .current working directory
child process
.
) (environmental variable
-1 )=(
-2 ) (environmental variable export
-3

) (environmental variable
. ) (environmental variable
LANG . unset environmental variable local variable
.

-1 set local variable environmental variable

RHCSA/RHCE Egypt

89

shell variable

-2 env environmental variable


-3 export p exporting

.
- :set )> (set [-/+] <option ) (- on ) (+
off ) (set +m .
) (set o
)> (set [-/+]o <set_name ) (- on ) (+ off set_name ). (set o
shopt set shopt shopt-p
shopt-s on shopt-u off
)(using parameters in shell script

i i love you
) (positional parameter $n } ${n n , 2 , 1, 0
3
} ${0 ./teba.sh


i hate love you i love you


* $

} ${#
} ${:- } ${1} ${2
PATH
PATH

RHCSA/RHCE Egypt

90

command line expression

PATH :

PATH


COMMAND LINE EXPRESSION

) ) ( (wild cards .
) (file globing .
.

} {

history

) brace expansion (
}{c,b,r . cat , bat , rat ) brace expansion (
postfixes prefixes .
brace expression
.

RHCSA/RHCE Egypt

91

command line expression

~
tilde expression ~ home
~username home .

variable expansion $var_name }${var_name


arithmetic expansion . * - + /
.

$((...))-1 .
* - + / .
. ** )) $((2**8 256
C man bash arithmetic opera

=<< =>> >> <<


10010010 >>5
00000100 LshRsh
& | bit byte binary :
&
example
|
example
True & True = True
1&1=1
7&5=5
True | True = True
1|1=1
8 | 7 = 15
True & False = False
1&0=0
& 111
True | False = True 1 | 0 = 1
| 1000
False & True = False
0&1=0
101
False | True = True 0 | 1 = 1
0111
False & False = False
0&0=0
101
False | False = False 0 | 0 = 0
1111
.

RHCSA/RHCE Egypt

92

command line expression

-2 $[1 + 2] brackets

-3 expr

* \ ) (back slash
expr 5 \*2
escape character * *\

-4 bash calculator bc
bc q

bc script - :

bc .
command substitution .
command substitution ) (back tick ` `command
) $(subcommand .
$

)pathname expansion (file globing preventing expansionquoting expansion


redirection . *&
double quoting-2 escaping -1

RHCSA/RHCE Egypt

93

command line expression

single quoting-3

) \ ( Backslash
Quoting prevents expansion
o Single quotes (') inhibit all expansion
o Double quotes (") inhibit all expansion, except:
$ (dollar sign) - variable expansion
` (back quotes) - command substitution
\ (backslash) - single character inhibition
! (exclamation point) - history substitution

single quotes back quotes


''...
single quota
`...` Back quota
SHELL CUSTOMIZATION
shell builtin .

built-ins shell

shell built-ins help

ALIASES
aliases .built-in command))alias
ls

RHCSA/RHCE Egypt

94

command line expression

aliases dir ls
alias NAME=VALUE
dir

aliases alias p

alias local variable


~/. bachrc non-login shell /etc/skel/.bashrc
alias
unalias

; .
SHELL PROMPT
) (prompt .
RETURN

PS1 PS2 .capital


shell ] [[root@localhost ~]# . .
shell prompt $ # . root ~ home

RHCSA/RHCE Egypt

95

command line expression

[root@localhost ~]# echo $PS1


[\u@\h \W]\$
"[root@localhost ~]# PS1="[\u@\V \W]$
[root@4.1.2 ~]$

PS1

DNS

ASCII

12 )(HH:MM:SS


)(cwd


\d
\h
\j
\n
\s
\T
\u
\V
\W
\#
\nnn
[\

ASCII 07
esc 033
FQDN DNS
)(terminal
enter
24 )(HH:MM:SS
24 )(am , pm


history number
$ # )(root

\a
\e
\H
\l
\r
\t
@\
\v
\w
!\
\$
\\
]\

BASH SHELL FLAGS AND SHELL OPTIONS


) (built-in command
set single letter flags
shopt
shell flag
set-1 ) (set )shell flags (unset
-2 )(local $ environmental variable

shell option shopt bash option shopt


shopt -s optionname sets the option optionname
shopt -u optionname unsets the option
shopt optionname displays the current option state
shopt displays all shell options

RHCSA/RHCE Egypt

96

Standard I/O and Pipes


SOURCING SHELL SCRIPTS

sourcing the scripts .


.sourcing source prompts

Standard I/O AND PIPES


.
) Standard In (stdin .
) Standard Out (stdout terminal display
)( .
-1 ) (graphical programs .X
.
-2 ) (screen programs ). (Text console
. virtual console
vi nano .
-3 ) (terminal programs
simply commands ls
grep useradd
shell .
$dosomething < inputfile > outputfile
: .(standard input STDIN) 0
: terminal .(standard output STDOUT) 1
: terminal .(standard error STDERR) 2

shell
.
shell :
.1 ) :(redirection /
.
.
. 2) : (Pipes .
.3 :
. .
.1 ) :(redirection .
command operator_file_name

RHCSA/RHCE Egypt

97

Standard I/O and Pipes

operator file name


< : . STDIN
> : STDOUT .

>> : ) > ( )(.


> :2 STDERR .
&> :2>&1 or + STDERR ).(STDOUT

<< : .
#mail s please call jana@example.com <<END
> hi
> please give me a call
> END
: /dev/null
/dev .
; )(..
semantic } {.
syntactic ) (ls; pwd ;file } { ls; pwd ;file

$cat /etc/jana 3>file1.txt 4>file2.txt 5>file3.txt

.2) : (Pipes .
command 1 | command 2 | command 3

.

RHCSA/RHCE Egypt

98

Standard I/O and Pipes

tee pipes
$uniq | tee /tmp/x.x | awk -f transform.awk
.3 : & shell
. ps .
.

-1 - :echo built-in command

.
.
echo
wild cards.
echo :

echo ) (. ) (.
.

-2 - :printf built-in command echo


]printf FORMAT [ARGUMENT
:
printf built-in command library call C
.

% .

%f floating
%c char
%s string
%d decimal
%o octal
%x hexadecimal
%u
jana s jana c
j
echo n
printf
\c
\t \b TAB backspace
\n

RHCSA/RHCE Egypt

99

Standard I/O and Pipes


left align - )(right align +
) (field width 0
field width
) Precision (. s c g
flages d x ou

-1 10 JANA -2 10 JANA
%5.10s 10 5 %10.5d 10 2
.

-3 - :read built-in read


REPLY

OPEN FILE & FILE DESCRIPTER



. .file descriptor
file descriptor /proc
/proc PID (file descriptor) FD
/proc/pid/fd

RHCSA/RHCE Egypt

100

Standard I/O and Pipes

:
test expressions expression ] [
) return value (exit status . test
. .
return value 0 0
:
-1
-eq
=
-ge

-gt

-le

-lt

-ne

-2
=:
=
=!

-n

-z
>

<

\ >\ <\

-3

-r


-x


-4
!
not
-o
OR
-a
AND
- : ) (
.
-f
-w
-G

-d
-s
-O

SCRIPTING :
.1 : if then .
.2 : if then else , command 1
. command 2

RHCSA/RHCE Egypt

101

Standard I/O and Pipes

.3 : if then else if else if.

]If [expression
then
commands
]elif [expression
then
commands
else
commands

fi
expression command ] [
exit status exit status = 0
:
:
#!/bin/bash
$ ./test1
# testing the if statement
Sat Jan 23 14:09:24 EDT 2011
if date
it worked
then
$
echo it worked
fi
:
#!/bin/bash
$ ./test2
# testing a bad command
./test2: line 3: asdfg: command not found
if asdfg
we are outside of the if statement
then
$
echo it did not work
fi
echo we are outside of the if statement
IF THEN
if command; then
commands
fi
:IF THEN
(( expression )) Double parentheses . [[ expression ]] double Brackets else if fi elif .fi .4 select case .
switch case if statement
: yes no .
) (syntax :
case string1(variable) in
)str1
;;commands
)str2
;;commands
)*
;;Default commands
esac

RHCSA/RHCE Egypt

102

Standard I/O and Pipes

y small script Y Capital


y small
y small , Y Capital , yes , YES script
) (y | Y | yes | YES .pipe

script .
case statement while statement .

.5 :for )(loop
)(loops .
)(Iteration )(loop
) (Iteration .

for c :
(( for
variable
; assignment
; condition
iteration
)) process

RHCSA/RHCE Egypt

103

Standard I/O and Pipes


1 - 10
2-9
3-8
4-7
5-6
6-5
7-4
8-3
9-2
10 - 1

1
2
3
4
5
6
7
8
9
10

.6 :while

] while [ expression
do
commands
done

x=0 Infinite loop


Loop :
done
break continue

1) Break

2) let x=$x+1 :

read
- n Input
.7 until while
] until [ expression
do
commands
done
.8 functions
{ ) ( fname
commands
}

{ ) fname2 ( arg1, arg2, argN
commands
}

RHCSA/RHCE Egypt

104

Storage
Device

- :
) (partition
partitioning .

) (mount /.
) ( )(dmesg
/proc/partition
) (cfdisk, sfdisk parted

fdisk

fdisk
cfdisk-1 ) partition table ( partition table
. fdisk
fdisk-2 BSD disk label) (other non-DOS partition Table
sfdisk-3 fdisk cfdisk .
parted gpt.
- :
-1 /etc/fstab ) (mounted ) (boot .
. .
-2 - :mount )
(/proc/ ./etc/mtab
-3 - :df -h .
-4 : /proc/partitions
) ( )(HARD DISK

!
!
!
!
!
!
!
!
!
!
7200 15000

!!

RHCSA/RHCE Egypt

105

raw device
.
) (HARD DISK ) (
) Intel/IBM/PC/DOS(

) (partition MBR Inode table sun gpt.

- :
-1 Intel/IBM/PC/DOS (Logical block address) LBA
BIOS

)(MBR, PARTATION, Inode table


Master boot record
-1 MBR
) (sector 512 ) .(512 byte
partition partition .boot sector
-:
)1- Partition table (64byte
)2- Magic No. (2byte
3- Boat loader
)(446byte
Inode table-2
MBR partition ) (meta data:

) ( .
scheme of partition partition table
.
Partition-3
- :
-1 2 ) (232 = 2 tera 2.
-2 ) 4 (.


primary-1- : .
extended-2 .
). (logical partition
partition - :
Logical part

RHCSA/RHCE Egypt

106

partitioning

) (partition ) (primary ) (extended


) (partition 63 IDE or SATA partition 15 SCSI
) (extended 4 ) (primary partition
. ) (logical part .5
-2 (Extensible firmware interface) EFI ) (BIOS

)(GPT, PARTATION, Inode table


- :
-1 ) (273 2.
-2 128 .
)(IDE | SCSI | SSP | SATA | SAS) - : (HARD DISK
)1- IDE (PATA
hdx x H.D )(a,b,c,d
) (mother bored )(primary , secondary
Primary
secondary
slave
hdd

master
hdc

master
hda

slave
hdb

24 (48 pin)parallel 24
.
)2- SATA (serial
sdx x )(a,b,c,d
)(sda, sdb, sdc, sdd, sde -------------------------------------------------and soon
)3- Other (SCSI, SSD, SAS, FLASH DRIVE, CD-ROM
sdx x )(a,b,c,d
)(sda, sdb, sdc, sdd, sde -------------------------------------------------and soon
- : ) (hot removable .
/dev /dev/sda
PARTITIONING

Parted
MBR, GPT

)1- CLI (parted


)2- GUI (gparted, qtpated

fdisk


MBR

2

- : partition kernel )(reboot


kernel partition table ) (force kernel reading .
#partprobe /dev/sda
:
-1 fdisk kernel parted kernel.
]#fdisk [options] [device
l fdisk


. u
-c
DOS compatibility mode
:
#fdisk -cul

RHCSA/RHCE Egypt

107

partitioning

fdisk
/dev/sda1 /dev/sda2 /dev/sdb.
Device-1
) (bootable partition * .
Boot-2
) (cylinder .
start and end-3
partition block block .1024 bytes
Blocks-4
hexadecimal ).(partition id no.
Id-5
Id .
System-6
-2 parted l :
]#parted [options] [device

CREATE PARTITION

-1 fdisk

fdisk :

partition n
m fdisk

partition d
w

(MBR GPT) partition table o
partition table p
q
F.S partition t
w

RHCSA/RHCE Egypt

108

partitioning

partition fdisk
partition n
partition
partition
partition
partition
partition p

-2 sfdisk
fdisk gpt
:
-1 partition
-2 partition
-3 partitions
-4 (repartitioning) partition
-1 partition s
]#sfdisk -s [device

device device
.

RHCSA/RHCE Egypt

109

partitioning

-2 partition l

-3 partition V

-4 partition repartition
)> (#sfdisk <device ) (partitioning
) (standard input ) (partition table .

sfdisk
-T

]-g [device

-N number
# sfdisk /dev/hdb -N5
-A number

active inactive
sfdisk :
><start> <size> <type [E,S,L,X,hex]> <bootable [-,*]> <c,h,s> <c,h,s
> <start> <size ><type
) (,
L is (LINUX_NATIVE (83)) (default) , S is LINUX_SWAP (82), E is EXTENDED_PARTITION (5),
and X is LINUX_EXTENDED (85).
sfdisk

partition
u sfdisk
uS -uB ) ( -uC -uM
-uS, -uB, -uC, -uM: accept/report in units of sectors/blocks/cylinders/MB

RHCSA/RHCE Egypt

110

partitioning

5 ) (5 partition ) 50 (/dev/sdd1
uM sfdisk ) 50 (/dev/sdd2 ) 200 (/dev/sdd3
) 2 (/dev/sdd4 ) (/dev/sdd5 .

: 1 .OS/2 Boot Manager 50


DOS partition extended 20
DOS partition 16 swap .
T
x extended .
- : ) (partition table partition
- :
)#sfdisk /dev/hdd -O /hdd-partition-sectors.save (file_name

/dev/sda
I O:

) (partition table c
b :
.

RHCSA/RHCE Egypt

111

partitioning

-1 ) (partition table d
#sfdisk -d /dev/hda > /hda.out
-2
#sfdisk /dev/hda < hda.out
sfdisk gpt
gpt sgdisk
partition map (partx) kpartx
multipath
image

-3 parted
gpt parted
) (parted parted .

help

partition parted

RHCSA/RHCE Egypt

112

)(File system

-1 select device_name
-2 ) (partition table gpt MBR
-3 partition :
-4 print
)mkpart (primary/extend) (fs type) (start) (end

partition

parted quit
)(FILE SYSTEM

/ .
-1- : / ext2 2.4
ext3 ext4 ext2 journaling
. Reiser
-2 / NTFS VFATMSDOS : FAT16
FAT32 .NTFS HFS.HFSplus
-3 - CDs/DVDs ISO9660.UDF
-4 JFS2 XFSReiserfs
-5 NFS.SAMBA

-7 /proc//sys/
: GFS.Coda
-6
partition
file system )(name and ID

)support to 8 tera in LBA system (MBR

ext4

) (file system - :
genisoimage ISO9660 Joliet HFS #genisoimage-ocd.isocd_dir

mkfs ) (create partition


/sbin /bin:

]mkfs [-t fstype] [fs-options] filesys(device) [blocks


t ) (file system ext2
c
.

RHCSA/RHCE Egypt

(File system)

113

ext4 partition
#mkfs -t ext4 /dev/sda

or

#mkfs.ext4 /dev/sda

#mkfs.ext2 /dev/sda

or

RHCSA/RHCE Egypt

- : ext2
#mkfs -t ext2 /dev/sda
or
mke2fs /dev/sda
.

114

mounting media

mke2fs .ext2

)(block size

inode

#dumpe2fs /dev/sda1

dumpe2fs ) (file system :


MOUNTING MEDIA
/ mount point .
) root (/ /floppy/ /win//cdrom/ /mnt/
/mnt/cdrom/ /media/ .
mount ) (access on device

/dev mount .
) (mount - :

-1 )device name mount (fstab


-2 ) label mount (fstab
-3 ) UUID mount (fstab
-4 automounter
-1 mount fstab

mount ) - : ) (mount point


) (file system mount (.
) (mount point ) device name (
#mount [options] device _name mount_point
) ) Directory(mount point (#mount -t (file system type)Device

OPTIONS

/etc/fstab
(verbose) mount
)(file system
) (device
) (device
label
UUID
) ro rw loop (
) Check=none (
label e2label
) (file system = F.S no F.S
mount -a -t nomsdos,ext

-a
-v
-s
-r
-w
-L
-U
-o

-l
-tF.S

RHCSA/RHCE Egypt

115

mounting media

] #mount -a [-t type] [-O optlist ) (boot script mount


/etc/fstab O a
#mount -a -O no_netdev mount _netdev
#mount a t ext2 -O _netdev mount ext2 _netdev
) (Mount Option o fstab
Mount Option Description
Data is read and written asynchronously. sync

async

) (inode no. noatime

atime

/etc/filesystems partition
) (floppy )(removable device

auto

rw, suid, dev, exec, auto, nouser, and async.

defaults

) (character & block device ) (device nodev

dev

) (compiled program) binary( noexec

exec

suid sgid nosuid

suid

root unmount user

nouser

/etc/fstab

remount

ro

rw

mount ]umount [directory | device

- : ) (mount )(device ) (mount point


.

)(mount

)/etc/fstab (file system table .mount

Check order

Dump

Option

Fs type

Mount point

) (device

)(mount configuration file


/etc/fstab -1 .
/etc/mtab -2 ) (mount mount

- :/etc/fstab
-1 ) (device name ./dev/sda1
-2 ).(mount point
-3 ).(file system type
.

RHCSA/RHCE Egypt

116

secure erase

-4 ) (option #mount -o option


Dump-5 user . . 0
Dump 1 Dump . 2 1

Check order-6 fsck . 0 1 2
1 .2
0 fsck.
label
devices devices mount
label device label
#e2label /dev/sda1 data or #mount -l /dev/sda1 data
#e2label /dev/sad1
label device
#findfs LABEL
device label
>Syntax: findfs LABEL=<label>|UUID=<uuid
fstab device name ) (Label=data data label
-2 ]UUID [universal unique identified
format partition
#blkid
UUID partition
fstab device name ) NO. (UUID=NO. UUID partition
umount device :
#fuser [options] MOUNT_POINT | FILE SYSTEM
OPTIONS

-c
)(mounted
-k
) (device
-m
) (device
-u
user id
-v

#lsof device
#lsof -m device

.mount iso image
#mount -o loop mage-name mountpoint
cdrecord
SECURE ERASE


) (RECOVERY TOOLS 2000 PATA
SATA recovery
. secure erase
-1 recovery .
-2 )(magnetic trace
.
)-: (secure erase
DOS HDDErase .
/ - :
-1 hdparm ) (root user - :
1-#hdparm --user-master u --security-set-pass password /dev/sda
)2-#hdparm --user-master u --security-erase password /dev/sda (or --security-erase-enhanced password
u 1 2
password NULL
- : hdparm
) (firmware PATA SATA
) (power option noise reduction )(read only flag

.
.

RHCSA/RHCE Egypt

117

secure erase

- :
#hdparm [flags ] [device] ..

)1-(#hdparm -I /dev/sda
)2-(#hdparm -i /dev/sda
)3-(#hdparm
)4-(#hdparm -t --direct /dev/sda

)5-(#hdparm tT /dev/sda
hdparm tT t ) (device read timingT
.(cache read timing) cache

4 5 .
)6-(#hdparm -d1 /dev/sda
DMA
DMA .
hdparm -dx x DMA.
)7-(#hdparm -S 24 /dev/sda
)(24*5=120sec
)8-(#hdparm /dev/sda

)9-(#hdparm X66 /dev/sda
d

RHCSA/RHCE Egypt

118

swap

34 is used to select multiword DMA mode2 transfers


)66 is used to select UltraDMA mode2 transfers (for systems which support UltraDMA burst timings
)68 is used to select UltraDMA mode4 transfers (for systems which support UltraDMA burst timings
)10-(#hdparm M 254 /dev/sda
acoustic management AAM
) (HEAD movement . 0 .254 128
254 . ) /(
128 .254 3 .
128 0 254 .
)11-(#hdparm -m 16 /dev/sda
I / O )( . " "MaxMultSect
I . 16
.8-4
)12-(#hdparm -c3 /dev/sda
0 to disable 32-bit I/O support
1 to enable 32-bit data transfers
3 to enable 32-bit data transfers with a special sync sequence
hdparm -y .
hdparm -C power management state

/etc/hdparm.conf
-2 #ddif=/dev/zero of=/dev/sdabs=1kcount=512
MBR
:
#dd if=/dev/urandom of=/dev/sda bs=1k count=512
512 MBR
if = input file
of=output file
-3 shred
)#shred [option(s)] file(s)_or_devices(s
-4 ) Dariks Boot and Nuke(dban.org ) (boot disk
SMART - :
.
Red Hat SUSE
.smartmontools
services smartd

SWAP

:( .RAM(
RAM swap space
virtual memory
RAM RAM
) (swap space ) (swap partition
). (swap file
Swap partition

Swap file
) (virtual memory swap RAM
=2*RAM
:
- :/etc/fstab swap fdisk /proc/swaps

RHCSA/RHCE Egypt

119

swap

- :ps .
- :top ps . .
- :free . m
.

- :vmstat .

- :dstat ) swap( top

- :slabtop
- : sar sysstat

#sar 10 5
10
#sar B to see paging #sar r to see ram usage #sar W to see swap activity
#sar q to see run queue #sar u traditional cpu usage #sar w

swap
swap :
mkswap swap
swapon swap swapoff
dd
-2 file
-1 partition
-1 partition
partition
F.S partition swap swap
mkswap swap sfdisk fdisk :parted

swap swapon
.

RHCSA/RHCE Egypt

120

LVM

- : partition swap swapon -s /proc/swaps

fstab F.S swap


swap
swap
defaults
0 0

/dev/sde1

-2
swapfile :
#dd if=dev/zero of=/swapfile bs=1M count=2012
F.S swapfile swap :
#mkswap /swapfile
swap swapon
#swapon /swapfile
partition swap swapon -s
fstab F.S swap

LVM
) (advanced partition management .
Logical Volume Manager LVM
) HP-UX

(HP LVM2 .
LVM :
: .
-1 : Physical Volumes PV
) software RAID (RAID hardware VG
physical extent PEs 4
-2 : Volume Groups VG .
LV PV
-3 :Logical Volumes LV
LV .
)
(
.
:
-1 )(resize
-2 ) LVM1 / (snapshot) (LVM2
RAID0-3 1 5 LVM RAID
LVM .
-4 .
): 1 PV )2 VG )3
.

RHCSA/RHCE Egypt

121

LVM

LVM ) (physical extend logical extend physical extend


) (volume group logical extend ) (logical volume logical extend
) (map physical extend
LVM - :

-1 partition LVM partition .


-2 partition .
-3 VG .
-4 LV .

-1 : ) (partitions )(8e) (Linux LVM



-2 : ) (partition ) (Linux LVM
) (partition (physical volume) PV pvcreate- :

) (PV ) (one physical disk ) (one partition


pvdisplay PV pvs
pvcreate
-3 (VG) volume group vgcreate VG
PV ) PE (physical extend 4M :
#vgcreate -s PhysicalExtentSize [bBsSkKmMgGtTpPeE] VG_name PV_path
B=byte
M=mega
T=tera
)(#vgcreate s 8M vg0 /dev/sdb1 /dev/sdc1 /dev/sdd1

vgdisplay VG vgs .
-4 LV lvcreate- :

-l PE_vol PE
.

-L= --size -n = --name

RHCSA/RHCE Egypt

122

LVM

30M 30 3G 3
lvdisplay LV lvs .
/dev/vg0/lv5
-5

) (logical volume
RESIZING LOGICAL VOLUME

) (logical volume lvextend lvreduce


L --size . lvresize

resize2fs ) ext2 ext4 ext3


( resize2fs

unmounted.
LVM ) (volume group .
SCSI / dev/sdb1 .
SCSI / dev/sde1 :
.

RHCSA/RHCE Egypt

123

LVM

-1 vg pv :

-2 vg0 /dev/sdb1
/dev/sdb1
vg pvmove

pvmove physical extent


#pvmove /dev/sdb1 /dev/sde1
#vgreduce /dev/vg0 /dev/sdb1
#pvremove /dev/sdb1

-3 /dev/sdb1 VG
-4 pv
12G ( resize)20G
-1
-2 ) (physical volume
-3 old volume group vgextend
-4
#lvextend --size +8G /dev/vg0/lv5
or
#lvresize -L 20G /dev/vg0/lv5
-5 ) (logical volume
#resize2fs /dev/vg0/jana
20G (resize) 8G
unmount
-1 umount
#umount /backup
-2 F.S e2fsck-f
)(force check
#e2fsck -f /dev/vg0/jana
-3 20G 8G
#resize2fs /dev/vg0/jana 8G
-4 ) (logical volume
#lvreduce --size -12G /dev/vg0/jana or #lvresize -L 8G /dev/vg0/jana
#mount /dev/vg0/jana /backup
3 4
#lvreduce -r --size -3G /dev/vg0/jana
resize to Inode table resize to volume
Resizing the root partition
partition/LVM umount .
) (root partition
) (unmount . ""
" rescue" disk/CD/DVD .
LVM .
rescue mode .mount
-1 rescue-mode
-2 skip shell start shell

RHCSA/RHCE Egypt

124

LVM


-3 LVM vgchange a y vg
a y yes:

-4 VG mapping VG .
VG root partition lv_rootlv_swap

-5 e2fsck f

-6 lv-root resize2fs

-7 lvreduce

15G
- :logical volume
- : LVM1-1 2.4 basic LVM
- : LVM2-2 2.6 LVM1
:
snapshots-1
logical volume
backup LV )(active
.

RHCSA/RHCE Egypt

125

LVM

LVM1 snapshot ) (read only .


LVM2 snapshot ) (read/write .
#lvcreate --snapshot
or #lvcreate -s
stripping-2

Mirroring-3
LVM LVM.
Physical volume
Volume group
Logical volume
Create
pvcreate
vgcreate
lvcreate
Inspect - Display
pvdisplay - pvs
vgdisplay - vgs
lvdisplay - lvs
Modify
pvchange
vgchange
lvchange
check
pvck
vgck
lvck
extended
vgextend
lvextend
reduce
vgreduce
lvreduce
remove
pvremove
vgremove
lvremove
rename
vgrename
lvrename
scan
pvscan
vgscan
lvscan
lvresize = lvextended & lvreduce

Logical Volume Management
yum install system-config-lvm

Administration

system


.
logical volume :
LVM physical volume

RHCSA/RHCE Egypt

126

RAID

PV VG
LVM Volume Group )PEs (physical extend size

VG ""add
volume group ) (mount F.S.

RAID
Redundant Array of Inexpensive Disk
RAID
.
.
.
RAID ) (
.
.

) (
) RAID disk matrix (RAID array .
100
100 ) 30 (70
.
/etc/raidtab RAID
RAID software RAID hardware RAID . hardware RAID
hardware RAID ) (RAID controller ) (H.D
.

RHCSA/RHCE Egypt

127

RAID

RAID controller )(streaming duplication mirror

) RAID
( :
- :(stripping) (RAID0)-1

.


.
- :(mirror) (RAID1)-2
)( )
( .
) (
.
. )
( .
.
- :(RAID2)-3
bit
) (parity
32

39.
- :(RAID3)-4

) (bytes ) (parity blocks


. RAID 4 .
)(.
- :(RAID levels 1+0 & 0+1)-5 RAID0.RAID1

RAID1+0=RAID10
RAID0+1=RAID01

RHCSA/RHCE Egypt

128

RAID

- :(stripping with distributed value) (RAID5)-6





) (for recovery .

3
) ( raid6
2 ) (.
RAID - :
-1 .
-2 .
-3 RAID .
-4 .
-5
RAM .
-6 .
RAID .
- : RAID .
(multiple disk) md
modconf .
mdadm .

)-:(RAID
-1 Linux raid auto fdisk.parted
-2 .RAID
>#mdadm [mode] <raiddevice> [options] <component-devices

Basic create mode option


>-l<number> or --level=<number
>-n<number> or --raid-devices=<number
>-x<number> or --spare-devices=<number

)(10 ,5 ,1 ,0

spare
RAID
RAID1

RAID5
/dev/md0 RAID
level=5 RAID )(RAID5
raid-devices=3 RAID
) (
mdadm --detail or mdadm D
RAID /proc/mdstat

RHCSA/RHCE Egypt

129

RAID

-3
-4 ) (mount point- :
fstab

#mount /dev/md0 /backup


sda3 - :
-1 RAID sda3 :
.

RHCSA/RHCE Egypt

130

quota

#mdadm /dev/md0 -f /dev/sda3


#cat /proc/mdstat

-2 RAID
#/mdadm /dev/md0 -r /dev/sda3
-3 sde1
#mdadm /dev/md0 -a /dev/sde1
-4 synchronization RAID recovery RAID .
RAID
#mdadm --scan

)#mdadm --stop(-S

#mdadm -A --scan

#mdadm --remove raid_name

boot partition basic partition ) RAID1 partition(software RAID grub
hardware RAID GRUB .
QUOTA

- : quota
quota quota


.quota F.S .
: storage limitation .
) (Inode
). (disk block
) (disk block ).(Inode
quota soft limit hard limit
hard limit soft limit
hard limit hard block limit
.
soft limit soft block limit
hard limit
soft limit
soft limit ) (
soft limit hard limit
hard limit soft limit .
quota .
) (hard limit .

QUOTA - :
QUOTA F.S )(implement in kernel )(data base for quota quota - :
-1 (mount with quota support) quota
-2 (create dB for quota) quota
-3 quota ))(switch on quota (kernel
-4 (change/set quota) quota
#yum install quota
: RPM quota
-1 quota mount fstab
fstab
quota
:usrquota
:grpquota .
.

RHCSA/RHCE Egypt

131

quota

quotas
mount
/dev/sdc1
/opt/company_data
ext4 defaults,usrquota,grpquota 1 2
mount
#mount -o remount /mnt/exmple
Mount
#mount -o usrquota,grpquota device_name mount_point

-2 (create quota data base) quota


: aquota.user
: aquota.group
) etc/fstab/ usrquota (grpquota
#quotacheck -cvug /mnt/example
c v u g .
m overwrite

#setenforce 0
- : quota selinux :
selinux enforce permissive
#chcon --reference /home/ /data/
security policy home /data/ journal quota
-3 quota a quota
#quotaon /mnt/example
-4 quota quotas u -g :
#edquota -u user-name

aquota.user
:
soft limit 50
hard limit 100


#edquota -t

block grace period . days hoursminutes .


setquota
#setquota -u <username> <soft-blocks> <hard-blocks> <soft-inodes> <hard-inodes> quota_partition
#setquota -u neo 30000 70000 0 0 /home
.

RHCSA/RHCE Egypt

132

)ACL (access control list

#quotacheck -amvug
quota :
quota #repquota/data/

QUOTA #quota ahmed


quota #edquota -up user1 user2 user3:
)ACL (ACCESS CONTROL LIST
) (file permission ) (ACL) (SELinux
file_premession ACL
SELinux .
(Access Control List) ACL
) (permission
. ACL .
:ACL .
. ACL

(#chmod 701 /home/jana):
.ACL
ACL getfacl .

setfacl acl.
physic physics_theme
bob ventura .

getfacl 3

RHCSA/RHCE Egypt

133

)ACL (access control list

getfacl

(file system acl) acl setfacl m


x

:
-1 )(u|g|o|m
-2
.
-3 .

ACL

: ACL ACL) (standard ACL ACL)(default acl


ACL ) (standard ACL .
ACL ) (default ACL ACL

RHCSA/RHCE Egypt

134

)(miscellaneous filesystem management commands

. ACL ACL
default d
getfacl sgid ls -ld

ACL .
ls-l ACL ""+ .
mv ACL .
cp P ACL
ACL EXT3 .(acl mount) acl
5 EXT3 ACL .
mount fstab

acl fstab
/dev/sdc1
/opt/company_data
ext4 defaults,acl 1 2
- :
File based ACL chmod
Network based ACL .
File based ACL
ACL - :
-1 (mount with ACL support) ACL
-2 ACL ))(switch on ACL (kernel
#yum install acl
: RPM acl
-1 ACL mount fstab
-2 ACL
# setfacl -m u:user01:rwx /opt/backup/file1
#setfacl -x u:user1 /opt/backup/file1
acl x m:
#setfacl -b /opt/backup/file1
acl b:
)(miscellaneous filesystem management commands

-1 fsck
- : .
.
fsck
) (File System ChecK .

RHCSA/RHCE Egypt

135

)Autofs (Automount

(fsck.<version>) mkfs

t t ) (.
.
#fsck.ext2 = #fsck -t ext2 = #e2fsck
fsck .
.
fsck y .
ext2 /lost+found .fsck
fsck .
-2 tune2fs
tune2fs ext2 ext3 .
tune2fs ).(unmount
.tune2fs

ext2 ext4 tune2fs


)AUTOFS (AUTOMOUNT

mount partition umount


/etc/fstab automounting
autofs daemon .
/misc .
RHEL )(/etc/auto.master, /etc/auto.misc, and /etc/auto.net

Main config file for the service


Master map file
automounter /etc/sysconfig/autofs

autofs # /etc/init.d/autofs status
.

/etc/sysconfig/autofs
/etc/auto.master

DEFAULT_TIMEOUT=300
"DEFAULT_BROWSE_MODE="no

RHCSA/RHCE Egypt

136

)Autofs (Automount

automount )(map file


:Master-1 map map
:special-2 mount .
:direct-3 .Mount
:indirect-4 mount .
-1 /etc/auto.master
/etc/auto.misc
/misc ) (indirect map hosts hosts automount a network directory
(/jana
/net map )/etc/auto.jana

-2 /etc/auto.misc
automount

NFS directory
boot
floppy
SCSI
IDE slave

auotmount
cd
-fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
:
][Relative pathname
][Mount options
][Location
RHEL .autofs
/dev/cd automounter
ls /misc/cd automounter .ISO9660
))(RO ) .((nodev) (nosuid 300 automount /etc/sysconfig/autofs
# # automount
.

RHCSA/RHCE Egypt

137

)Autofs (Automount

-rw,sync

rhel01:/opt/company_data
mount NFS
*
-rw,sync
&:/home&/
mountuser home directory
: indirect map wild cards )&(*,
:direct map
/usr/data
-rw,sync
rhel01:/opt/company_data
indirect map direct map absolute pathname indirect map
.
-3 /etc/auto.net
NFS IP
DNS /etc/hosts ./net

512 sector
sector track
tracks cylinder

= head * cylinder * track * sector

company_data

RHCSA/RHCE Egypt

138

Installation
Of RHEL

:
-1 )(CD\DVD usb )(boot.iso
-2 ) (network manual automated
:CD/DVD

)( :
-1 )(Anaconda Stage 1
) (bootable media
.
:
installation disk-1
boot.iso image-2 4 CD
/images
diskboot.img-3 /images usb
(Pre eXecution Environment) PXE-4
-2 )(Anaconda Stage 2
rpm )(2-3G
:
-1 DVD
-2 HTTP server
-3 FTP server
-4 NFS server
) (CD\DVD :

(images/)-1 image ) (boot media .


(Packages/)-2 rpm .
(HighAvailability/ , LoadBalancer/ , ResilientStorage/ )-3 .repo
(README)-4 .
(RELEASE-NOTES-en)-5 .
(RPM-GPG-KEY-redhat-release)-6 Gnu Privacy public key private key
.
(EULA)-7 .
(GPL)-8 GNU Public License .
(repodata/)-9 yum .
.

RHCSA/RHCE Egypt

139

DVD
-1 . curl
curl

-C
-O

``url

) MD5 (finger print .md5sum


md5 md5 .

-2 :

) (boot menu enter


.

tab .

RHCSA/RHCE Egypt

140


VNC
)(graphical mode
)(text mode

) (X SERVER .
boot.iso
)(text mode

)(graphical mode
) (video card

RHCSA/RHCE Egypt

141

VNC

VNC Client vncviewer


vnc rpm .

next

"
"

)(Basic storage Devices

)(Specialized storage devices
5
iSCSI.
iSCSI

RHCSA/RHCE Egypt

142




) (upgrade an existing
).(Fresh installation

fresh installation ][next




) (host name.

configuration Network


)(NIC
. NIC IP

)(DHCP
IP
NIC )(wired
).(wireless

add
IP netmask
default gateway DNS
DHCP

.
. .

RHCSA/RHCE Egypt

143

NEXT NEXT



partition

PARTITIONING

RHCSA/RHCE Egypt

144

-1 -(mount point) 2 -(File system) 3


next boot loader

) (boot loader . BIOS .


) (
next

RHCSA/RHCE Egypt

145

RHCSA/RHCE Egypt

146

Network Installation

kdump
.
.
24
.
NETWORK INSTALLATION


boot.iso .
) (boot.iso
) (installer server FTP HTTP NFS
kickstart http .
:
-1 RHEL01 http :
#yum install -y httpd

-2 httpd:

-3 redhat http:
/var/www/ ) apache server (http server
client pub .
-4 /var/www/pub/:

-5 kickstart kickstart
):(/var/www/pub/kickstart/
.

RHCSA/RHCE Egypt

147

Network Installation

-6 kickstart /var/www/pub/kickstart:
selinux.firewall
-7 . iptables
.
port 80 http :

rules iptables /etc/sysconfig/iptables service

.
boot.iso Esc tab
:

linux askmethod tab


IP

-1 boot.iso install or upgrade Enter
-2 disk found skip Enter
-3
-4 URL

RHCSA/RHCE Egypt

Network Installation

148

Enter -5

: Enter -6

-7

Installation Virtual Console Commands and Functions
Command
Console and Function
CTRL-ALT-F1 Text installation display; if you're running in graphical mode
CTRL-ALT-F2 Accesses a bash shell prompt.
CTRL-ALT-F3 Lists the log of installation messages
CTRL-ALT-F4 Displays all kernel messages, including detected hardware and drivers.
CTRL-ALT-F5 Installation displays partition formatting
CTRL-ALT-F6 Graphical installation display; active only if installation in graphical mode
Interactive shell
.( CTRL-ALT-F2)
/mnt/source /mnt/sysimage /proc
SCPSSH FTP ping ifconfig interactive shell
:

RHCSA/RHCE Egypt

149

kickstart

KICKSTART

)(kick start script


ASCII .
. kickstart configurator
CD-ROM
TFTP
NFS
HTTP


https://access.redhat.com/site/documentation/enUS/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html
-3 )(post section
-2 )(package section
-1 )(command section
-1 )(command section
%package
.
.
.
-2 )(package section
%package
) % character (%
)( :
@ Component_Name
or
package-name
) (@Component_Name
capitalized .
@ Everything .
) (package-name .
%package --resolvedeps .
-3 )(post section
%post
.
.
kickstart :
Application
System Tools Kickstart
system-config-kickstart

yum install system-config-kickstart



/root/anaconda-ks.cfg .
kickstart script .
.

RHCSA/RHCE Egypt

150

Automating KICKSTART

5 kickstart ksvalidator pykickstart


kickstart

kickstart
ks boot Kickstart .
> ks=file:/<file
ks=file:/mydir/ks.cfg
> ks=hd:<device>:/<file
ks=hd:sda3:/mydir/ks.cfg
> ks=nfs:<server:>/<path
>ks=http:<server:>/<path
> ks=cdrom:/<path
ks for auto kfs from DHCP server

ks=http://rha-server/pub/ist191-ks/student-ks.cfg
AUTOMATING KICKSTART

kickstart ) (full automating


)(PXE boot TFTP server
TFTP SERVER-1
-1 tftp http syslinux:

-2 :

-3 http ) (initrd.img ,vmlinuz:


-4 ftp tftp ) (/etc/xinetd.d/tftp :

-5 :
-6 syslinux
:
.

RHCSA/RHCE Egypt

151

Automating KICKSTART

/tftpboot:

-7 default PXE :
# touch /tftpboot/pxelinux.cfg/default
:

tftp
PXE boot-2
) client ( .PXE boot
.
DHCP ip . .PXE
dhcp :
# yum install y dhcp
# rpm -qa | grep dhcp
dhcp-4.1.1-12.P1.el6.x86_64

# service dhcpd restart


Stopping dhcpd:
] [ OK
Starting dhcpd:
] [ OK
# chkconfig dhcpd on
PXE default :

RHCSA/RHCE Egypt

152

Hardware and Device CONFIGURATION

firewall:

bios
boot LAN PXE
HARDWARE AND DEVICE CONFIGURATION

.
:

.
:
.
.
https://hardware.redhat.com/

.

dmesg-1
) ) ( (add new device
).(boot
) (dynamic kernel buffer
.dmesg buffer /var/log/dmesg
dmesg " ".
.
dmesg dmesg

.
-2 hald lshal
)(hot attached device
USB
. ) (2.6 hald
)") ("Hardware Abstraction Layer Daemon (.
) (hald D-BUS system message bus .
6 D-Bus APIs
) (Hardware Abstraction Layer
hald lshal
.

RHCSA/RHCE Egypt

153

Hardware and Device CONFIGURATION

lshal m
USB .

-3 /proc
. ) (option parameter
) ( SysFsproc registry file
Solaris .ndd
) (proc ) (virtual file system
/proc .
proc
/proc/kcore RAM
512 512 .

)(virtual File system


/proc .
. .
:
File name
Content
) (CPU .

/proc/cpuinfo

(internet working service request) IRQ .

/proc/interrupts

) (registered port ) (I\O .

/proc/ioports

/proc/iomem

RAID .

/proc/mdstat

/proc/meminfo

lsmod .

/proc/modules

).(memory fragmentation
)(boot time parameter
. swap partition
.
.

/proc/kcore
/proc/buddyinfo
/proc/cmdline
/proc/swaps
/proc/version

RHCSA/RHCE Egypt

154

Hardware and Device CONFIGURATION

File name

Content
. scsi

*/proc/scsi/

) arp a .( arp

/proc/net/arp

/proc/net/dev

).(snmp

/proc/net/snmp

Statics on network socket utilization

/proc/net/sockstat

*/proc/sys/fs/


/proc/sys/net/core/
. 300
netdev_max_backlog
.0 ICMP
1 .

/proc/sys/net/ipv4/
_icmp_echo_ignore
all

.0 ICMP
broadcast address multicast address 1
.

/proc/sys/net/ipv4/
_icmp_echo_ignore
broadcasts

32768 .61000

/proc/sys/net/ipv4/
ip_local_port_range

0 off on
/proc/sys/net/ipv4/
.SYN flood attack
tcp_syn_cookies
/proc process id
)(PID .
. proc
. etc/rc.d/rc.local sysctl
sysctl.conf kernel

]Syntax: sysctl [options


Options:
-e Ignores errors
-w enables you to change a setting in the /etc/sysctl.conf file
-p Loads settings from the /etc/sysctl.conf file
-a Displays all settings currently available
#sysctl w kernel.hostname=jana.teba
=
#echo kernel.hostname=jana.teba >>/etc/sysctl.conf
usb
USB SCSI sdx
x .
USB floppy SCSI
lsusb USB .

IDE
IDE bus IDE
master.slave
IDE primary.secondary
IDE primary master primary slave
.

RHCSA/RHCE Egypt

155

Hardware and Device CONFIGURATION

Secondary master secondary slave

SCSI
sdx x .

.ISCI ID sda .sdb
sda
sdb label UID
/proc/scsi dmesg

SATA
scsi

KERNEL AND KERNEL MODULE

.
.
USB . device driver
) (device driver .
)( .
) (device driver :
Static kernel image
Kernel module
The static kernel image
. /boot
vmlinuz version version .

IDE .
) (device driver
) (boot loader grub lilo .
/proc/cmdline

) (static device driver


) (modular dives driver /etc/modprobe.d/*.conf

RHCSA/RHCE Egypt

156

Hardware and Device CONFIGURATION

The kernel modules


) (
.) kernel module (
/lib/modules/version version .
lsmod /proc/modules

(independencies) modules snd_hda_intel


Modules snd_pcm sndsnd_hda_codec
modprobe
module modules modules
) (dependency dependency
/lib/modules/kernel_version/modules.dep dependency

modules r

) (modules /etc/modprobe.d/*.conf
) (modules .
""demand /etc/modprobe.d/*.conf .
sb kernel ) (device driver ) (
type=N N
. /etc/modprobe.d/custom.conf
.sb kernel

:
) (modules .
.

RHCSA/RHCE Egypt

157

Hardware and Device CONFIGURATION

) (device driver ) (modules ) (modules


.

/proc/sys/
/proc/
/proc/sys/ /proc/sys/
. /proc/sys/
sysctl

sysctl /proc/sys/ .
/proc/sys/fs/file-max sysctl fs.file-max
(PCI DEVICE) PCI
PCI bus . x86 PCI
PCI hardwired VendorDevice IDs
PCI ) (expansion cards
) (bridge ) (devices PCI.
lspci PCI v

(Interrupt Request Line) IRQ


) (devices IRQ . x86 15 IRQ
) (devices IRQ.
.

RHCSA/RHCE Egypt

158

Hardware and Device CONFIGURATION

/proc/interrupts IRQ ) (device driver .

)(I/O ports
IRQ
.
x86 16 .I / O
I / O ) (device .
/proc/ioports .
.hexadecimal

Device Memory Buffers



.
/proc/iomem
hexadecimal digit

RHCSA/RHCE Egypt

159

Hardware and Device CONFIGURATION

(PCI device Configuration) PCI


.
) (device driver ) (kernel modules
.

.
PCI ) (Hardware Abstraction Layer
)(device driver PCI
/lib/modules/2.6.32-8/modules.pcimap device's vendor product id
.
/etc/modprobe.d/dist.conf
. lspci

RHCSA/RHCE Egypt

160

Hardware and Device CONFIGURATION

Assigning Resources

. boot time Plug n' Play protocol
PCI .
lspci -v .

) (assigning devices
modprobe.d/*.conf .
/usr/share/doc/kernel-doc-kernel_ver/Documentation/
. kernel-doc package :

FILE SYSTEM DEVICE NODE

: .
" )?(How do processes communicate with device drivers
.
. ) (process ) (device driver )(file system type
.device node
device node process driver
.
:device node
character device node-2
block device node-1
device node /dev
device node .

device node
)( . device node
character device node ) ""( .
. ) (terminal ) (serial ports
.

RHCSA/RHCE Egypt

161

Hardware and Device CONFIGURATION

Block device node .


.block device I\O block device
cash " " )(Page Cache , Buffer Cache , Cache
ls l block b char c

) (device driver :
) Major Number-1 ( .
/proc/devices
major number
block device character device pty
character device ) (major number 2 fd block device 2.

) Minor number-2 (
device node
floppy driver minor number 2
Primary IDE controller major number 3 minor number ) (partition
.

RHCSA/RHCE Egypt

162

Hardware and Device CONFIGURATION

) (device node .
) (device driver
device node .
device node
. ) (hot swappable devices
.
RHEL3 "pre-populating
device node /dev device node
RHEL4 2.6 .
) (notification device udevd
udevd
udevd
./etc/udev udevd device node
.node
udevd .device node
udevd hot swapped device
.
/dev device node device node
.
mknod device node ./dev
Node /dev udevd node
.
PERFORMANCE MONITORING

uptime

RHCSA/RHCE Egypt

163

Hardware and Device CONFIGURATION

load average
R D 15 15.
0.56 10.23 5
0.12 15.
- :top
top .
"q
top
.uptime
.
.


: (user) -us "" .
.
:(system) -sy "" )(services
) (
.
:(idle) -id runnable

(nice) -ni " "niced
(I/O wait) -wa I/O
I / O
(Hardware Interrupt) -hi ) (low level hardware
" "
.
(Software Interrupt) -si
.
(Stolen) -st
. ).(xen

RHCSA/RHCE Egypt

164

Hardware and Device CONFIGURATION

physical RAM
Swap
/proc/meminfo
) SysFs ( /sys/
proc
/dev driver udev ) (mange driver
dev/ )/sys/ (SysFs

SysFs

RHCSA/RHCE Egypt

165

Installation
Of Application

) (package manger .
) (software package repositories
) (package manger
) (dependencies
rpm dpkg
Kpackage rpm Gnome-apt dpkg
) (package
)}(Package_name)-(Version)-(release)-(architecture).(type of package {rpm or dpkg
postfix-2.6.6-2.el6.x86_64.rpm
Package_name
----
Version

Release

Arch
Noarch package
1386 32 bit and 64 bit
1586 Pentium I AMD
1686 Pentium I , II , III , IV AMD Duron , Athlon
X86_64 Intel core 46 bit AMD 64
Ppc 32 bit IBM
uname-a arch
cat /etc/redhat-release
lsb.release-a DebianUbuntu
(package manger
rpm&yum------------------------red hat based system as Fedora and RHEL
dpkg&apt ----------------------- Debian based system as Ubuntu,Kubuntu&debian
/ rpm
-1 )(source code installation
RPM-2
YUM-3
- 1 )(SOURCE CODE INSTALLATION

c c++ java )(compiler


binary .executable file

gcc .
/app.tar.gz #wgethttp://

#tarxvzfapp.tar.gz

#cd/app

#./configure

#make

#makeinstall

.

RHCSA/RHCE Egypt

166

2- )RPM (Red hat package manger

- 2 (RED HAT PACKAGE MANGER) RPM

Red hat package manager


.

. RPM configuration file
Binaries and pre-post script

rpm :
http://rpm.pbone.net
http://ftp.redhat.com
http://mirrors.kernel.org http://freshrpms.net
www.rpm.org
RPM
RPM
RPM
RPM data base package
) ( permission , ownership , dependencies /var/lib/rpm

RPM executable .rpm package


.rpm ) (root user
.
Package file rpm

rpm
-1 )(install update remove
-2 )(query
-3 )(verify
invocation

Use
.

rpm -i, rpm -U, rpm -F

rpm -e

(query the rpm database) rpm

rpm -q

)(Verify

rpm -V

Verify the integrity of a RPM package file

rpm --checksig

-1 RPM
package rpm -i --install:
]#rpm -ihv [name-version-release-arch.rpm

RHCSA/RHCE Egypt

167

2- )RPM (Red hat package manger

package rpm -U --upgrade:


]#rpm -Uhv [name-version-release-arch.rpm

package rpm -F
--freshen:
]#rpm -Fhv [name-version-release-arch.rpm
RPM

#rpm -ihv http://------------------------------------

v verbose
h ) progress bar (
package rpm -e --erase:
]#rpm -e [Package_name

RPM
--replacepkgs
.
--prefixnew_directory .

RHCSA/RHCE Egypt

168

2- )RPM (Red hat package manger

-2 rpm rpm q
) RPM (rpm query :


-c-d

rpm --requires --provides


rpm --requires --provides

RHCSA/RHCE Egypt

169

2- )RPM (Red hat package manger

Querying RPM Scripts: --scripts


RPM ) (shell script
. --scripts RPM :
Pre-install Scripts
Post-install Scripts
Pre-uninstall Scripts
Post-uninstall Scripts

--last
--last RPM .
.

RHCSA/RHCE Egypt

170

2- )RPM (Red hat package manger

) (configuration file -c:


#rpm -qc package_name
# rpm -qc rsyslog
-d documentation
# rpm -qd rsyslog
dependency
R:
)#rpm -qR vim(package_name
:
>#rpm2cpio <package

-3 )(package verification
verification package
verification package
) (data base rpm package .
RPM :
every file which is associated with an installed package
the file's user and group owners
)( permission
file length
MD5 MD5 finger print
.

RHCSA/RHCE Egypt

171

2- )RPM (Red hat package manger

-V .
RPM .
) (admin . pam
MD5 :

) ( )Verification error message (common flag


S
file Size differs
M
)Mode differs (includes permissions and file type
5
MD5 sum differs
D
Device major/minor number mismatch
L
readLink (2) path mismatch
U
User ownership differs
G
Group ownership differs
T
mtime differs
P
capabilities differ
(RPM verification) RPM :
) : (Debugging .
): (Security rpm -Va
/usr/bin/passwd /usr/sbin/sshd
RPM Package File Signatures
) (package rpm rpm
.repo
.
.signature
signature
private key

) (signature
GPG (Gnu Privacy Guard) private key.

rpm .
.GPG
GPG
:
-1 www.redhat.com
-2 RPM-GPG-KEY-redhat-release
-3 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
RPM rpm --import keyfile

RPM
.GPG-pubkey

RHCSA/RHCE Egypt

172

2- )RPM (Red hat package manger

:
:

#rpm -K package_name
#rpm --checksig packagefilename

#rpmbuild package.src.rpm

srpm rpm
/usr/scr/redhat
Converting an RPM Package into a cpio Stream
) (formatting RPM cpio .tar tar
" cpio )"(stream ) (standard in
). (standard out
rpm cpio rpm2cpio :

vsftpd cpio stream cpio


.cpio stream
cpio RPM .
. ./etc/vsftpusers .

: yum rhn_register
RPM :
-1 )(directory hierarchy
-2 .
-3 ).(spec file
-4 .RPM

RHCSA/RHCE Egypt

RPM (Red hat package manger) 2-

173

:/usr/src/ ( directory hierarchy) -1


BUILD
Contains scratch space used to compile software
RPMS
Contains the binary RPM that is built
SOURCES
Holds the source code for the RPM
SPECS
Contains the spec file(s) (one per RPM)
SRPMS
Contains the source RPM built during the process

: make rpm-build
# yum install y rpm-build make
: first_file mysample -2

SOURCES -3

specs : spec -4
Summary: This package is a sample for the Red Hat exams.
Name: mysample

Version: 1.0
Release: 0
License: GPL
Packager: Jana Tester
Group: Development/Tools
Source: %{name}.tar.gz
BuildRoot: /usr/src/fedora/tmp/%{name}-%{version}

BuildRoot source

%description
This package is just a sample for the Red Hat exams.
%prep
%setup n mysample


BUILD SOURCE

%install
mkdir p $RPM_BUILD_ROOT/opt/sample_pkge
cp R * $RPM_BUILD_ROOT/opt/sample_pkge
%files
/opt/sample_pkge
%clean
rm rf $RPM_BUILD_ROOT
%post
chown user01:user01 R /opt/sample_pkge
chmod 775 R /opt/sample_pkge
SPEC
#vim /usr/src/fedora/SPECS/mysample.spec
: rpm-build rpm -5
# rpmbuild v bb /usr/src/redhat/SPECS/mysample.spec

RHCSA/RHCE Egypt

174

3- )yum (yellow dog update modified

-6 rpm /usr/src/Fedora/RPMS RPM rpm i


# cd /usr/src/redhat/RPMS/x86_64
# rpm -ivh mysample-1.0-0.x86_64.rpm
]Preparing... ########################################### [100%
]1:mysample ########################################### [100%
(source rpm) rpm
c c++ java
) (compiler binary .executable file src.rpm
SRPMS/ rpm

rpm rpm -i
binary ( (rpm package) ) rpm :
-1 binary
) dependency (
-2
-3 ~/rpmbuild/SOURCES/ ~/rpmbuild/SPECS/
.
) (source rpm :
-1 " ) "(pristine source .tar
-2 " ) " (patch files .
-3 ) " (spec files
) (patches )(compile RPM.

rpm rpm repository


yumdownloader foobar yumdownloader --source foobar yumdownloader is provided by yum-utils.
rpmbuild -ba specfile rpm.

~ / rpmbuild / BUILD rpm


binary ~ / rpmbuild/RPMS
rpmbuild )(a for binary and source rpm b for binary c for compile source code
)( i for install l for list s for source rpm p unpacks the source code and apply any patch
- 3 (YELLOW DOG UPDATE MODIFIED) YUM

rpm
dependency yum
) (library file YUM .dependency +
yum (yum repository) yum .

RHCSA/RHCE Egypt

175

3- )yum (yellow dog update modified

(yum repository) yum RPMS )(metadata


RPM HTTP .FTP
.

) (repository ) (Yum Client


/etc/yum.repos.d/ .repo

) (unique repository id
(baseurl) rpm
) (repo YUM .
.YUM
yum tetex-dvips dependency .tetex-fonts
yum.
yum ) (repository library
.

RHCSA/RHCE Egypt

176

3- )yum (yellow dog update modified

yum
install package_name

update

update package_name

search package_name

remove package_name

erase package_name

info package_name

list

resolvdep dep_name
dependency
update up2date

#yum
#yum
#yum
#yum
#yum
#yum
#yum
#yum
#yum

RHCSA/RHCE Egypt

177

3- )yum (yellow dog update modified

yum

) (yum clean all cache yum .yum


(yum repo.) yum
rpm stanza
/etc/yum.repos.d/

RHCSA/RHCE Egypt

178

3- )yum (yellow dog update modified

yum update
update yum
" " . )(yum list update
tar .yum

system-config-packages
repo :
-1 createrepo
#yum install createrepo
-2 ftp
#rpm -ivh vsftpd.rpm
#service vsftpd start
-3 ftp
#cp rpm /var/ftp/pubs
-4 repo
#mkdir /opt/yum/myrepos
#cd /opt/yum/myrepos
#cp ~/nano-2.2.6-1.x86_64.rpm /opt/yum/myrepos
-5 repo
#createrepo /opt/yum/myrepos
or #createrepo /var/ftp/pubs
-6 /etc/yum.repos.d repo
#cd /etc/yum.repos.d
#nano myrepo.repo
][base
name=My Custom Yum Repository
baseurl=ftp://rhel01/opt/yum/myrepos
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
repo package
ftp repo
baseurl=ftp://rhel01/opt/yum/myrepos
repo
][iso-repo
Baseurl=file:///mnt/cd
enabled=1
.

RHCSA/RHCE Egypt

yum (yellow dog update modified) 3-

179

(www.rpmfusion.org repoforge google repo adobe repo epel) repo


: dvd repo
# mkdir /mnt/cd
# mount o loop /dev/cdrom /mnt/cd
# cd /mnt
# createrepo . or createrepo /mnt
# yum clean all
# vim /etc/yum.repos.d/iso.repo
[iso-repo]
Baseurl=file:///mnt/cd
enabled=1
.( createrepo -update)
rpm
http://dag.wieers.com/packages
http://fedora.us
http://freshrpms.net
http://rpmfind.net
http://rpm.pbone.net
http://www.fedoraproject.org/wiki/Extras
http://atrpms.net
ftp://www.ibiblio.org/
http://rpm.livna.or
rhnsd rhn_register
IN DEBIAN & UBUNTU

rpm dpkg -1
#dpkg option action package_name
action
-i

--configure

-r

-P

-p

-I

-l

yum aptitude -2
#aptitude search package_name
#aptitude install package_name

#aptitude full-upgrade
#aptitude safe-upgrade

#aptitude dist-upgrade
#aptitude remove package_name

#aptitude purge package_name

apt-get -3
#apt-get install package_name
(update[ ] upgrade[ ] remove [Package_name] check[) ]
#apt-cache search [package_name]

#apt-cdrom [package_name]

RHCSA/RHCE Egypt

180

BOOT UP
SEQUENCES

)(Boot sequence overview


.

system
ready

system
V init

kernel

Boot
loader

Bios

) ]( BIOS [BASIC INPUT/OUTPUT SYSTEM


) ROM (
-a bios ) POST (POWER ON SELF TEST
) (Hard ware device bios del
-b ) (device initialization
IRQ ) (I/O ports device ]IRQ [interrupted request
.plug n play
-c ROM portal device
Floppy Drive, CD-ROM, IDE or SCSI Hard Disk, PXE compliant Network Card
-d ) IPL (initial product load boot loader
: F2 , F10 or Delete
MBR
) (Master Boot Record 512
) (512 byte partition partition boot sector

Boot loader 446 byte -1
Partition table 64 byte -2
Magic number 2 byte -3 recovery
dd if=/dev/sda of=/tmp/COPY_OF_MBR
MBR
MBR /dev/sda /tmp COPY_OF_MBR
BOOT LOADER INITIALIZATION
boot loader
BIOS RAM
) initrd (
initrd modules initrd-kernelversion.img RHEL4 RHEL5
RHEL6 initramfs-kernelversion.img
boot loader
-a Lilo linux loader /etc/lilo.conf
-b Grub grand unifid boot loader
NTLoader -c
.

RHCSA/RHCE Egypt

181

GRUB

GRUB

Grub
grub lilo
grub minimal shell shell .bash


)(Fedora, red hat enterprise linux, open SUSE, Ubuntu, Mandrake and other
file sys ext3,2fat
)(multi boot specification
Grub /etc/grub.conf ----- shortcut
/boot/grub/grub.conf-------
MBR Grub - :

-a ) (stage_1 MBR
) stage_2 (stage_1_5
-b ] [actual image stage_2 optional image stage_1_5
stage_1_5 stage_1 stage_2 x_stage1_5 x
) (File system type ] [ext4, ext3, and other stage_2.
fat fat_stage_1_5

file system
stage_2
(GRUB CONFIGURATION) GRUB

/boot/grub/grub.conf .
grub GRUB grub :
.

RHCSA/RHCE Egypt

182

GRUB


grub ) (floppy disk CDROMhard disk
0 grub IDE SCSI ) (hd 0,0 kernel


-1 : primary master IDE hd0
" " BIOS Drive #1 . GRUB HD0 /dev/hda
-2 :partition
partnum 1 .GRUB 0
dev/hda1
-3 df

/dev/sda1 /boot /grub/splash.xpm.gz


/boot/grub/splash.xpm.gz
grub
}(hd0, 0) /grub/splash.xpm.gz{grub reading} = /boot/ grub/splash.xpm.gz{kernel reading
}(hd0, 2) /etc/passwd {grub reading
}= /etc/passwd {kernel reading
}(hd0, 6) /log/dmesg {grub reading
}= /var/log/dmesg {kernel reading
(hd0, 0) /vmlinuz-2.6.32-131.4.1.e16.x86_64 = /boot/ vmlinuz-2.6.32-131.4.1.e16.x86_64
grub grub
grub )(#

RHCSA/RHCE Egypt

183

GRUB


grub

grub
Splashimage


os
gimp

xpm

GRUB
5

GRUB :
Secure mode :
grub.conf
grub.conf
.

RHCSA/RHCE Egypt

184

GRUB

basic mode :
grub .
:
Grub Boot Options:
e Edit the commands before booting
a Modify or append the kernel arguments before booting
c Open the GRUB command line
Edit mode :
. grub
grub.conf .
.
(grub.conf) stanza b
Esc basic mode
) (boot only
grub .

:Append mode

run level run level .quit
) (edit & append mode :
Single-User Mode
)Used to perform maintenance tasks or if you forget the root password (1 or s
Runlevel 2 or 3
Used to load only partial services during the boot process
)(2 or 3
Emergency Mode
Used to perform tasks on an unbootable system
)(emergency
Rescue Mode
Used to fix boot issues or reinstall GRUB
)(need boot-cd
Command mode :
grub.conf grub
initrd . Esc
.
boot loader NTLDR BOOT.ini
(GRUB INSTALL) GRUB

boot loader
boot loader
. MBR
. grub stage_1 bootloader MBR
GRUB
grub-installgrubs native command line

boot.iso rescue mode


.

RHCSA/RHCE Egypt

185

GRUB

LINUX DVD tab linux rescue

-2

-4 No

-6 /mnt/sysimge

-7 shell start shell

-1

-3 rescue cd/dvd

-5 continue

/ CD-ROM
/mnt/sysimge
/ /mnt/sysimge
chroot /mnt/sysimge
/ exit
stage1 MBR
grub-install /dev/sda

RHCSA/RHCE Egypt

186

GRUB

grub grub shell


grubs commands shell rescue mode command mode
grub shell terminal rescue grub

root root )(hd0,0

root floppy root

stage_1

stage1
grub boot loader MBR

.quit
/ DVD reboot
c grub shell
: root OS run level 1 grub
Kernel e quiet 1 s S OS run level 1
) (#passwd exit root.
grub
.

.
.grub.conf ) (not plaintext password
root password
terminal

#grub-md5-crypt
md5

grub.conf /boot/grub/grub.conf
.

RHCSA/RHCE Egypt

187

INIT PROCESS

password --md5 password_key

lock

KERNEL
- :
-a )) initrd (initial RAM drive) (initramfs Grub
RAM kernel
kernel device modules kernel device
.drivers
) kernel kernel) modules(initrd kernel
modules kernel
kernel
modules on or off
-b kernel
Mount to (root file sys (/)) -c
Remount (root file sys (/)) -d read &write
)(dmesg |less
-e )initial process (init
grub

INIT PROCESS

INIT PROCESS
upstart
1) /etc/rc.d/rc.sysinit
then run upstart
2) /etc/rc.d/rc?.d/
3) /etc/rc.d/rc.local
4) X display manger #startx
open GUI in run level 3
process init
/etc/inittab process
run level /etc/inittab initdefault :5
/etc/inittab ./etc/init
) init(upstart ./etc/sysconfig/init

RHCSA/RHCE Egypt

188

INIT PROCESS

)init(upstart
/sbin/init
process ID .1 init .
process Id 1 .(signal 9) SIGKILL
init
. /etc/inittab system
V 6 upstart
.
upstart /etc/inittab
/etc/init/ (system v) V . inittab
init boot non-kernel process
initupstart ) (jobs ) (boot
run level ) (jobs ./etc/init/
) init(upstart .
UPSTART .
/etc/init ) (event /etc/event.d
.SYS V init RHEL6 UPSTART )
syslog ( )(events
.system script
upstart

tty.conf ) init (upstart .gettys


getty .tty
) ENTER ( . login . ) init(upstart getty . /etc/init/tty.conf gettys active_consoles
) tty( /etc/init/start-tty.conf /etc/sysconfig/init

6 6 ) (virtual console tty 6


/etc/sysconfig/init ) init (upstart
.

RHCSA/RHCE Egypt

189

INIT PROCESS

3 5 /etc/init/prefdm.conf 5
/etc/X11/prefdm X server
getty virtual console 2
. .
init ) init (system V
/etc/inittab ) init(upstart /etc/inittab
/etc/init
/etc/sysconfig/init /etc/event.d
initctl
initctl
) init (upstart
upstart service :
>#initctl [start stop restart reload status list] <job_name

inittab

) (run level 5
.

RHCSA/RHCE Egypt

190

INIT PROCESS

run level
runlevel
- halt

- Single User Mode
- Multi-user Mode without NFS

- Multi-user Mode

- unused

- Multi-user with X

- reboot

run level runlevel who -r

0
1
2
3
4
5
6

N
init
init Unix init telinit
init telinit
init 0 )(shutdown
shutdown :
-1 at crontab
-2 ) (broadcast .

shutdown hprc 1
:

) (root user .
hprc :shutdown




shutdown

)-h (halt the machine


)-p (power off the machine after halting
)-r (reboot the machine
)-c (cancel a pending shutdown

RHCSA/RHCE Egypt

191

INIT PROCESS

shutdown
-k

-F
FSCK
-n

-t SECS
halt shutdown now poweroff
reboot
/etc/init/rcS.conf
/etc/init ) init(upstart
boot :
-1 ) /etc/rc.d/rc.sysinit (script
system initialization .
-2 /etc/inittab ) . (run level
runlevel . rcS.conf .boot
run level ./etc/inittab
-3 ) (runlevel /etc/rc.d/rc?.d
.
/etc/init/rcS.conf

) (script .
/etc/rc.d/rc.sysinit
rc.sysinit
) (root file system ) (mount .
-1 /etc/sysconfig/network ).(set hostname
-2 ) (mount /proc
-3 selinux (activate udev and selinux) a relabeling of the system
-4 /etc/redhat-release .
-5 RAID array
LVM (encrypted partition .
-6 rc.sysinit fsck -T -t noopts=_netdev -A $fsckoptions
fsck -A ) (file system .
) (root file system fsck
. fsck
) (read only) (root file system
/etc/fstab ).(rescue shell
-7 ) (root file system

#mount -o remount,rw /
#mount -a -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs O \ no_netdev
)(mount other local file system
fstab
-8
o Sets kernel parameters in /etc/sysctl.conf
o Sets the system clock
o Loads keymaps
o Enables swap partitions
o Enable disk quotas

Cleans up stale locks and PID files

init init
init q
.

RHCSA/RHCE Egypt

192

Red Hat Enterprise Linux Service Scripts

RED HAT ENTERPRISE LINUX SERVICE SCRIPTS

rcS.conf rc.sysinit
/etc/rc.d/ /etc/init/rc.conf

/etc/rc.d/ ) (runlevel :

symbolic
etc/rc.d/init.d/

/etc/rc.d/init.d/
/etc/rc.d/init.d
. ) (scripts ) (run level .

) start( ) stop() restart () reload


( ) status (.
)(scripts ) (services daemon

RHCSA/RHCE Egypt

193

Red Hat Enterprise Linux Service Scripts

/etc/rc.d/init.d/sshd /usr/sbin/sshd daemon


) (server

) (services stop

)(services
)(scripts /etc/rc.d/init.d
)(service
service

/etc/rc.d/init.d/service_name command

) (daemon

daemon ) (scripts
./etc/rc.d/init.d/
daemon daemon .
service httpd start
service sshd status
command

/etc/rc.d/rc
runlevel runlevel
.
.

RHCSA/RHCE Egypt

194

Red Hat Enterprise Linux Service Scripts

/etc/rc.d/rc?.d
) (directory runlevel . service ? runlevel
) (soft link service /etc/rc.d/init.d
L S runlevel K
runlevel dd service_name
rc K .S
init runlevel rc
-1 first booting rc ) (run level .
" ("kill") "K rc .
) (service script .
-2 rc ) (run level . ""S
)" ("start rc .
) (service script .
chkconfig .
:
]--list [name

>--add <service_name

>--del <service_name

>--level <run_levels

><service_name> <on|off|reset

--list )(run level

--list

chkconfig on off reset


. 35

23 5 http smb . reset

RHCSA/RHCE Egypt

195

Red Hat Enterprise Linux Service Scripts

/etc/rc.d/rc.local
) (boot up .rc.local
) (script .
). (Script rc.local
.
S99local



-1 /etc/rc.d/rc.local
-2 etc/rc.d/init.d/
rc.local init.d

service runlevel
#chkconfig --level2 servicename on
#chkconfig --level2 servicename off
Xserve

in openSUSE

#yast2 runlevel

service
service
.

system > Administration > Server Settings


system-config-services

in Ubuntu

#sudo services-admin

#chkconfig --del service_name


#chkconfig --add service_name

RHCSA/RHCE Egypt

196

Red Hat Enterprise Linux Service Scripts

ntsysv
#ntsysv --level 35

3 5

chkconfig .

MANAGING VIRTUAL CONSOLES

upstart gettys 6 6 ) (tty 6


. 12 .
. X
ttyn n

Observing the Boot Sequence


.
boot process .
4 quiet
rhgb . .
:
/etc/grub.conf grub quiet rhgb
grub boot loader
grub :

. grub initial ramdisk


.

RHCSA/RHCE Egypt

197

Red Hat Enterprise Linux Service Scripts

) (mount initial ramdisk root partition init


init rc.sysinit


.
. name=value
) . (Env variable ).(first process

.
) (two .
-1 ):(run level 1


) (init 1 ""1 . " "1
.init
init "1 1
.
-2 (bypass init process) init
fstab /etc/inittab
etc/rc.d/rc.sysinit 1 . init
.
/sbin/init ) (interactive shell
init .
.

RHCSA/RHCE Egypt

198

)(kernel

init=/bin/sh init=/bin/bash .
init=boot_prameter = init

) (/
exit

) (

) (interactive shell PID PID=1 .
exit:

init

)( KERNEL
)/( :
.
kernel
open source code
kernel
BSD
) (Hardware
.
.
) ( :

.1
.2
.3
.4
.5

. :
: management


:

) :(I/O ) (terminal .
: .
: .

RHCSA/RHCE Egypt

199

)(kernel

" "
" "


""patch




.

: ""

2.6

production
) Experimental
1.3 2.1 (2.5
) 1.2 2.0 2.2 2.4(

.

.
) ( .
.
: X.Y.Z X Y


: Y
Z
http://www.kernel.org
:

): (monolithic kernel .
-1
-2 / )(modules

RHCSA/RHCE Egypt

200

)(KERNEL

-3 .symmetric multiprocessing SMP


64 .
.
)VFS (virtual file system

-4 :

. .

-1 ) (monolithic kernel
:


:

-2 Microkernels



-3 Hybrid (or) Modular kernels
XP ) (Mac OS
) (Microkernels

-4 nanokernelsexokernels
)(KERNEL


-1
-2
-3 ALSA 2.6
OSS ntfs
-4 SM56
2.4.5
-5
modules
-6
kernel

SCSI
: Stable .
:
-1 yum update
rpm rpm i
.www.kernel.org

rpm:
rpm U i
.
-2 src.rpm rpmbuild:
-1 ftp://distro.ibiblio.org
ftp://ftp.redhat.com
kernel-2.6.38.6-26.rc1.fc15.src.rpm
rpm rpm
. (BUILD,SOURCE,RPMS,SRPMS,SPECS,tmp) rpm
.

RHCSA/RHCE Egypt

201

)(KERNEL

-2 rpm mockbuild
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
mockbuild system
#useradd s /sbin/nologin mockbuild
or #useradd r mockbuild


src.rpm rpmbuild ${HOME}/
. /{HOME}/rpmbuild/SOURCE$
linux-3.6.38tar.xz patch-3.6.38.xz
-3 SPECS SPECS rpmbuild:

.rpm
-4 ${HOME}/rpmbuild/RPMS/i686/

kernel-3.6.10-4.fcl8.root.i686.rpm
kernel-smp-3.6.10-4.fcl8.root.i686.rpm
kernel-debuginfo-3.6.10-4.fcl8.root.i686.rpm
: debug
-3
configurationcompiling

)(configuration & compiling


.1 : http://www.kernel.org
) (FTP .
.2 :
bzip2 gzip xz ) (linux-2.4.0.tar.bz2

tar kernel .
gcc make
) (compiling

modutil ncurses menuconfig


) (
#yum install qt3-devel gcc-c++ libxi-devel ncurses-devel
In openSUSE
#yast -i qt3-devel
)
.3 :

Config . (.

:
y (no & yes) n
:make config
.

:make oldconfig ) .config (

make config
:make menuconfig


) n y - ?- m (loadable module
:make xconfig . x window tcl/tk .

RHCSA/RHCE Egypt

202

)(KERNEL

.
. make config make menuconfig

:make gconfig make xconfig GTK :make defconfig -

)#make mrproper- (old kernel


kernel kernel
#make clean


-1 Pentium I Pentium IV
-2 SMP !!
-3 modules
kernel module loader loadable module support
.
-4 ext2 ext3 vfat msdos minix Reiserfs
ntfs hpfs jfs xfs
: menuconfig export TERM=linux export TERM=ansi
make xconfig
.4 ) :(compiling make 2.6
make bzImage make modules make
#make

.bz
.
-5 : :
#make modules
#make modules_install
#make install
make /boot/
GRUB modules /lib/modules make install modules
make modules_install /boot/ .
:make install
cp arch/i386/boot/bzImage /boot/
cp system.map /boot/

RHCSA/RHCE Egypt

203

patching the kernel

/boot/ /boot/
bzImage

vmlinuz . .
. system.map

.

initrd ) (drivers RAID


.
initrd mkinitrd:
[root@dhcppc4 boot]#mkinitrd -f /boot/initramfs-3.4.60.img 3.4.60
grub
.6 : GRUB
) vmlinuz system.map ( initrd /boot/ grub.conf
grub



/boot/
initrd / . Install
) mkinitrd 2.6.12( mkinitramfs
-4 new-kernel-package initrd
grub .
]new-kernel-package [-v] [--mkinitrd] [--rminitrd] [--dracut] [--initrdfile=initrd-image [--depmod
][--rmmoddep] [--kernel-args=args] [--remove-args=args] [--banner=banner] [--multiboot=multiboot
][--mbargs=mbargs] [--make-default] [--add-dracut-args] [--add-plymouth-initrd] [--host-only
><--install | --remove | --update | --rpmposttrans> <kernel-version
PATCHING THE KERNEL

ASCII
) :(patch

. ) (man patch
)(
. ) (
. .

.

patch hotfix patch kernel hotfix

-1 patch
)(patch . ) (http://www.kernel.org
)(patches .
http://www.linuxhq.com

""
) ( ) (NVIDIA
-2 patch bz2
)bzip2 bunzip2 gzip (.gz
patchxxxx-2.6.21-pversion.bz2
:


xxxx

2.6.21 )(patch
pversion
readme
) (
:
-3 kernel
( cd /usr/src/linux

/usr/src/linux2.6.21
)

bunzip2 patch-xxxxx-2.6.21-version.bz2
-4 patch p1
patch -p1 < patch-xxxxx-2.6.21-version or patch d patch_name -p1
.

RHCSA/RHCE Egypt

204

patching the kernel

: patch patch p1 -R
)(MODULES
kernel
-1 vmlinuz----- core
-2 initrd----- modules /lib/modules
)( )
1.2


( . )) ((driver

modules ) (driver
) kmod
2.0 (kerneld modprobe
.
/etc/modules.conf

lib/modules/version_kernel/modules.dep/ .
( insmod
) /lib/modules/version_kernel
#uname -r
: Modules ) (Modules ) (Driver
.

modutils module-init-tools 2.6
:lsmod.1 ) (/proc/modules
.
#lsmod usb_storage
lsmod

:modprobe.2 r
#modprobe -r usb_storage
:insmod.3
:depmod.4 .
:rmmod.5 .
.6 : modinfo
ksyms 2.4 ) (/proc/ksyms
insmod .
DMA .IRQ:
#insmod soundx io = 0x320 irq = 5
: KERNEL
1- kernel-PAE (SMP) support
x86 ------up to 32 processes & 16G RAM
2- Kernel
support x86 ------up to 32 processes & 4G RAM
x64 ------up to 64 processes &512G RAM
3-kernel-xen
support
)x86 ------up to 32 processes & 16G RAM (Dom0 limits
)x64 ------up to 126 processes&512G RAM (Dom0 limits

#modprobe usb_storage

RHCSA/RHCE Egypt

205

The CUPS print system and system-config-printer

11

System
Admin Tolls

THE CUPS PRINT SYSTEM AND SYSTEM-CONFIG-PRINTER


.(Line Printer Daemon) LPD
: / BSD
.
LPD LPD .
LPD Ghostscript postscript
. system V

. CUPS
LPRng CUPS / .
) CUPS (LPRng
lpr
BSD System V
:
:BSD LPD
CUPS LPRng .BSD LPD LPD
.
LPD .
:LPRng

(Common Unix Printing System) :CUPS


BSD .
) .(LPRng
/ :
BSD LPD LPRng CUPS
)( : ) (serial or parallel cable or usb
.

) HP
: TCP/IP

LDAP( TCP/IP ) IPP (CUPS ) JetDirect


(HP.

) : (filtering system .
: / CUPS
) Epson(HP Gimp
; Foomatic Ghostscript.

:
) (print queue CUPS
:lpr
.
LPD ) (job number
) (print queue ) (pint filter ) (spooling directory
)(backend device

RHCSA/RHCE Egypt

206

The CUPS print system and system-config-printer

:lpq .


15 lprm -P Epson 15

cups
BSD LPD
) IPP (http CUPS CUPS
.
PPD

CUPS ) (print queues


.
) (print queues hp_color salesreally_slow_dot_matrix.
cups )(cupsd daemon
)(cupsd daemon ) (configuration /etc/cups
log cups daemon :
/var/log/cups/
/var/log/cups/access_log
/var/log/cups/error_log.
.

RHCSA/RHCE Egypt

207

The CUPS print system and system-config-printer

cupsd daemon /usr/sbin/cupsd

(cups printing system) cups :


system-config-printer
)(lpr, lprm, lpstat, lpadmin and other
http TCP 631 http://localhost:631

cupsd daemon cups services .


:
)#service cups start (stop, restart, status
)#chkconfig cups on (off, --list

(Creating a CUPS print queue) cups



-1 ). (new queue
-2 cups ) (backend device .
) (device node
/ dev/lp0 / dev/usb/lp0
) ( .
.

RHCSA/RHCE Egypt

The CUPS print system and system-config-printer

208

.( appropriate filter) -3
.system-config-printer

Figure 1 the system-config-printer
Figure 2 selecting a Queue type

Figure 3 Selecting Print Filter (ex. select Epson)

Figure 5 Naming a New Printer Queue

RHCSA/RHCE Egypt

Figure 4 Choosing a Print Filter

Figure 6 Newly Installed Queue

209

The CUPS print system and system-config-printer

Adding a Remote CUPS Print Queue


) (print queue
. lplaser print.example.com
.
: system-config-printer new selecting a Queue type
network printer Find Network Printer ) instructor.example.com. (hostname
FIND Remote Printer

Figure 1.11. The system-config-printer Application

Figure 1.13. Choosing a Print Filter

)Figure 1.12. Selecting Print Filter (ex. select Generic

RHCSA/RHCE Egypt

210

The CUPS print system and system-config-printer

Figure 1.14. Naming The New Remote Printer with system-config-printer Application

Setting the Default Print Queue


CUPS ) (system default print queue
-P ). (Print environmental variable
.
system-config-printer
"" " " .
system-config-printer . ) (printer
" " Properties . .


system-config-printer ) (cups printing queue
:
SERVER SETTING

RHCSA/RHCE Egypt

211

The CUPS print system and system-config-printer

printer properties policies

BROWSING FOR AVAILABLE PRINT QUEUES


cups "" ) .(cups queue
cups IP .
" ) " (Show printers shared by other systems
" ) " (Server Settings .
system-config-printer
"."remote printer
system-config-printer ) (cupsd daemon HTTPD
) (port 631 http://localhost:631
system-config-printer

RHCSA/RHCE Egypt

212

The CUPS print system and system-config-printer

cups ). (print queue


cupsd Daemon ) (localhost interface
) . (administrative interface cups
.
.

RHCSA/RHCE Egypt

213

System Logging

lpadmin cupsenablecupsdisable
lpadmin
.

cupsenable cupsdisable .

system-config-printer cups
System-config-printer
:
.
) (network sharing )(browsing.
:
.
.
cups
:
) .(links
.
:
.
.

:
automate
.
.
.
:
.
.
SYSTEM LOGGING
:rsyslog
rsyslog ) (log message .
rsyslog) facility( ) priority( .
facility

RHCSA/RHCE Egypt

214

System Logging

priority

) (message ) (facility ) (priority rsyslogd daemon


rsyslogd daemon rsyslog
service.chkconfig
/etc/rsyslog.conf
/etc/rsyslog.conf rsyslogd daemon

) (mail facility /var/log/maillog


) info (priority ) (mail.none authpriv
cron ./var/log/messages
facility.priority action
/etc/rsyslog.conf )(two separated tokens
.
facility.priority )(specific facility
) (specific priority .
facility.priority );( ) (semicolon
)*( ) (facility ).(priority

RHCSA/RHCE Egypt

215

System Logging

rsyslogd daemon

:
-1
-2
-3 ) (application or facility .
-4 process ID .
-5

RHCSA/RHCE Egypt

216

System Logging

The kernel login


) . (log message
.rsyslogd daemon ) (kernel log message
.dmesg
.
dmesg dmesg ). (standard out
/proc/kmsg
rsyslogd daemon imklog
imklog .rsyslog message proxy / proc / kmesg
rsyslogd daemon )(kern facility
/var/log/messages .
.rsyslog .
.
/var/log

logger
logger log server .
(debugging the rsyslog service) rsyslog .
logger .

RHCSA/RHCE Egypt

217

System Logging

logger
logger /var/log/messages

log server 514


rsyslogd daemon
log .
log .
RHEL logrotate .
) (time stamp
. secure secure.20110801 secure.20110724
secure.20110807 secure.20110814. logrotate

logrotate secure
. crontab
/etc/cron.daily/

logrotate /etc/logrotate.conf
/etc/logrotate.d/ logrotate

RHCSA/RHCE Egypt

218

logrotate 4

- : /etc/motd
x windows /etc/x11/xorg.conf
) (system login )(lastlog faillog
lastlog
Lists login records
faillog
Lists failed login attempts

lastlog:
-b DAYS
Displays results older than DAYS

-u LOGIN
Displays results for the user LOGIN

faillog:
-a
Displays all events

-l SEC
Locks the account for SEC seconds after a failed login
-u LOGIN
Prints records for user LOGIN

Encoding Encryption Hashing


) Encoding(- : binary

.
.
. )(ASCII, Unicode, URL Encoding, Base64
) :(encryption )
) (readable form ) (Unreadable form
.decryption
: how are you x131$h?z398178 .

) (key
. ) (cipher text) (algorithm ) (key
) .(decryption )(AES, Blowfish, RSA
) Encryption algorithm (
).(performance
)- :(hashing encoding encryption .

) ( . ""
.digest

. MD5 Tiger.SHA-1
authentication hashing
public key
.

RHCSA/RHCE Egypt

219

)encfs (((directory encryption

encryptionhashing
encryption password key data unreadable form decryption key data data ).(readable
hashing (readable form) data ) (unreadable form key salt .one way salt
hashing
#passwd redhat
redhat salt (MD5 hash) hash rehashing .
- : encryption
((DIRECTORY ENCRYPTION) ) ENCFS

) (directory encryption user space FUSE kernel module Library


) (2 directory ) (source directory ).(mount point directory
mount point directory ) (readable form
source directory source directory ). (unreadable form
FUSE Library kernel encfs
encryption volume key source directory decryption
. password

:
-1 ) (2 directory encrypted decrypted
decrypted .

-3 encrypted encfs

encfs /encrypted )(source directory


/decrypted ) (mount directory encfs :
p-1
x-2 :

1 AES Blowfish

RHCSA/RHCE Egypt

220

)encfs (((directory encryption

) (key volume
) (Block Null stream = block
.

-3 ) source directory (/encrypted
) mount directory (/decrypted mount directory
mount umount

mount umount fusermount:


Unmount fusermount -u

Mount encfs


encfsctl

.
.

RHCSA/RHCE Egypt

221

partition)(file encrypted

PARTITION )(FILE ENCRYPTED

-1 1 :

-2 partition losetup e :

losetup ) cipher (
aes :
-1 yum install util-linux util-linux
-2 ) (cryptoloop_modules aes_modules
partition :

-3

-4 :

-5 unmount loop losetup d:


-6 :

umount
5 .
fstab :
/secret.img
/mnt.encrypted
ext4 defaults,noauto,loop,encryption=aes,user 0
0
(DISK AND FILE ENCRYPTION) LUKS

LUKS = Linux unified key setup


: -
.

RHCSA/RHCE Egypt

222

)LUKS (disk and file encryption

-1 block device encryption device


off single user mode
-2 key encryption .
-3 key.8
-4 file encryption.disk encryption
-5 kernel device mapper dm-crypt module
encrypted_device .cryptsetup
- : LUKS KEY passphrases encrypted device
passphrases .
partition : LUKS
-1 partition fdisk lvm raid
-2 Luks cryptsetup:

encryption disk Luks


partition delete partition
Luks partition :

exit status 0 && exit status


.
device Luks :

-3 partition :

RHCSA/RHCE Egypt

223

)LUKS (disk and file encryption

encrypted
partition luks-data /dev/mapper/luks-data/
-4 ex4 :

-5 luksClose cryptsetup:

UUID:

- : Luks 8 ).(8 key


encrypted partition with luks luksClose teba.conf:
partition teba.conf .
mount encrypted partition ) (reboot mount
mount encrypted partition /etc/fstab
mapper name /dev/mapper/luks-data
partition . /dev/sdb1 mount directory encrypted device dev/sdb1
. .'unknown filesystem type 'crypto_LUKS

rc.sysinit:
[root@www ~]#vim /etc/rc.d/rc.sysinit
fstab .auto mount fstab
encryption .crypttab fstab /etc/crypttab
.encrypted file system
.

RHCSA/RHCE Egypt

224

)LUKS (disk and file encryption

mount (/etc/sdb1) encrypted partition fstab .


-1 crypttab vim .
[root@localhost /]# vim /etc/crypttab
Mapper_name
source_partition
key encrypted_type
luks-data
/dev/sdb1 /teba.conf luks
mount sdb1 (mapper name) luks-data /teba.conf key
.(luks) encryption
-2 fstab vim :
/dev/mapper/luks-data /jana ext4 defaults 0 0
-3 ) (insecure mode for root
key ls l permission Readable permission
readable ).(chmod 400 test2

CHECKSUM


). (MD5, Sharp
hi
checksum

file vim checksum .

test checksum
- : checksum checksum
.
checksum
)md5sum (128 bit ))sha (sha1sum (160 bit) , sha256sum (256 bit) , sha512sum (512 bit
checksum redhat checksum
checksum checksum
torrent peer to peer
.
ATTRIBUTES ACL
chattr chattr
" "root DOS attrib
) (:
: A "Access time" .
: a , ).(append
: c "(compression) "kernel
: D , .
: d (no dump) dump
: i ).(immutable
: s ). (secure deletion
.

RHCSA/RHCE Egypt

225

)LUKS (disk and file encryption

: S D , .
: u , ). (undeletable
: j journaling
h (hidden) - T (top of directory hierarchy) - t ( no-tail merging) - e (extend attribute) :
chattr:

lsattr lsattr .chattr

i .
) (attribute
.(mount option) user_xattr
UUID=661ab9f1-c381-4962-bcfc-0b5e2aab1ce9 /home
ext4 defaults,user_xattr,acl
12
setfattr setfattr ) (set extended attribute to filesystem
extend attribute name
:
-n name = --name=name
attribute
-v value = --value=value
attribute
-x name = --remove=name
attribute
Extend attribute name
) (metadata )
( . ) (extend attribute
. attribute .chattr
).(character encoding of a plain-text, a checksum, cryptographic hash or digital signature
ext2 ext3 ext4 JFS XFS Reiserfs .Btrfs ) extend attribute (.
) (extend attribute ).(metadata
- : ) .( name. :
)(user trusted - security system
user.mime_type - trusted.md5sum - system.posix_acl_access - security.selinux
. ) (extend attribute
user space program
extend attribute 2.6 BeagleDropbox
Beagle is a search system for Linux and other Unix-like systems
Dropbox is a file hosting service operated by Dropbox
security attribute security kernel modules .selinux
security_attribute security security module
security_modules
) CAP_SYS_ADMIN (.
system attribute kernel system object ACL .CAPILITES
system_attribute system_attribute .
.

RHCSA/RHCE Egypt

226

)LUKS (disk and file encryption

trusted attribute ) CAP_SYS_ADMIN


( . ) user space (
.
user attribute the mime type
( .character set or encoding of a file ).(chmod

getfattr getfattr )(get extended attribute to filesystem


-n name pathname...
-d pathname...
d attribute
n attribute
attr XFS
attrname [-V attrvalue ] pathname
= setfattr -n
attrname pathname
= getfattr
attrname pathname
= setfattr -x

#getfattr
#getfattr

#attr -s
#attr -g
#attr -r

RHCSA/RHCE Egypt

227

NETWORK MANGER

NETWORK

NETWORK MANGER
- : IP dynamic ) static (
) IP (submask .
6 )(Network manger

) (wirless . .
.

:
-1 )- :(connect automatically .
-2 )- :(Available to all users
. .ifcfg
) (network manger
.
.

RHCSA/RHCE Egypt

228

NETWORK MANGER

) (bonding ) (adaptor
load_balance ). (network manger
ip forwarding ) (network manger
. router
. chkconfig
.

.
IP addressing. netmask
. default gateway
. DNS
.
Ifconfig .ip addr
. route
. System-config-network-tui
.
./etc/sysconfig/networks
. /etc/sysconfig /network-script/ifcfg-ethX
./etc/hosts
. /etc/resolv.conf
)(NIC
) (Network Interface Card) (NIC . PCI
. lspci

NIC
) (device node /dev/ NIC
NIC ). (network interface
NIC ) (network interface eth0 tr1
) (type of underlying data link technology
.

wlan0 . wifi
ip addr RHEL6 ) ifconfig ( .
.

RHCSA/RHCE Egypt

229

ip :
}#ip [options] object {command | help
}Object: = {link | addr | addrlabel | route | rule | neigh | tunnel | maddr | mroute | monitor
}]Options: = {-V[ersion] | -s [tatistics] | -r [esolve] | -f [amily] {inet | inet6 | ipx | dnet | link} | -o [neline

-1 ip addr add
#ip addr add local address dev dev_name

eth 1 ip 10.1.1.8 netmask 255.0.0.0


del add
#ifconfig eth0 ip_address netmask netmask_address
ifcong
.

RHCSA/RHCE Egypt

230

) IP( ). (multihomed host


:

ip link set:

ip link set up = ifup

ip link set down = ifdown


-2 ifcfg-ethX
ethX )(eth0 eth1 eth2 -.
Unix IP ) (startup script
./etc/rc.d/rc.sysinit
ifcfg-eth0 :
/etc/sysconfig/network-scripts/ifcfg-ethX
:

ip.
ifcfg-ethX
Variable
Ex.
Description
eth0

DEVICE


MAC

MAC address

HWADDR

IP

192.168.16.1

IPADDR

static NIC dhcp dhcp

none|static|dhcp

BOOTPROTO

netmask

255.255.255.0

NETMASK

yes no
.

yes | no

ONBOOT

no
yes .

Yes | no

USERCTL

192.168.0.254

GATEWAY

gateway.
.

RHCSA/RHCE Egypt

231

Description
NIC yes = NetworkManager no=network
TYPE=Ethernet

Ex.

Variable

NM_CONTROLLED Yes | no
Etherent|Wirles

TYPE

System eth0

NAME

IP aliases
IP IP aliasing
255 ) (additional aliases
: (eth0:1 eth0:191) : label ip addr add:

ifcfg-ethX

RHCSA/RHCE Egypt

232

IP

Virtual LAN
VLAN
Virtual LAN ) ( .
eth0 eth0:2 eth0.2
eth0 /
eth0:2 Alias IP
Subnet .
eth0.2 VLAN LANs
Switch Sub Interface
VLAN
.1 : ifcfg-eth0.2
DEVICE=eth0.2
VLAN=yes
.2 : vconfig
VLAN vconfig add
VLAN /proc

VLAN
VLAN vconfig

IP

IP ) .(router IP
) (network part ) . (host part IP
) (netmask .
IP .
)(netmask ) (network part .IP IP
. ). (CLASS A CLASS B CLASS C

.IP
4 IPv4 IP 20 . " " IP
IPv4 .
6 IPv6 inet6.
IPv6
.

RHCSA/RHCE Egypt

233

IP

IPv6 128 ) (,
) hexadecimal 0000 .(FFFF
) (netmask . prefix
prefix / 64 .
/ 48 65535 .
IPv6 :
:0db8: :db8: :0000: :0:
::
2001:db8:0:0:0:0:0:1 - : 2001:db8::1 0:0:0:0:0:0:0:1 ::1
IPv6 broadcast address multicast address
.
unicase (::1): IPv6 127.0.0.1 IPv4
MAC address
IP address MAC address

MAC )NIC (Network Interface Card . )(


MAC firmware .
The ARP cache (address resolution a protocol) arp
192.168.10.51 MAC 192.168.10.8
)(segment
IP MAC .ARP cache

The Routing Table


). (routing table
.

RHCSA/RHCE Egypt

234

)DNS (Domain Name Service

) (routing table ) (network interface


.

) (routing table route:

192.168.16.0/255.255.255.0
eth0 hosts
gateway
)(internet
) (route table gateway IP
n :route

ip route ) (routing table .


.
.ip
gateway
. gateway )(ip route del default
gateway (ip route add default via IPADDR): IPADDR IP
gateway.

gateway ifcfg-eth0 :
GATEWAY=192.168.16.1
# route add default gw 192.168.1.1 eth0
(Domain Name Service) DNS

.DNS
DNS IP .
resolv library
ip resolv library /etc/hosts )(static lookup
/etc/resolv.conf )(dynamic lookup
.

RHCSA/RHCE Egypt

235

)DNS (Domain Name Service

)STATIC LOOKUPS (/etc/hosts


.IP
IP IP:

)DYNAMIC LOOKUPS (/etc/resolv.conf


ip ip
.DNS IP
.
/etc/resolv.conf resolv library ) (name server DNS
)(search nameserver domain

nameserver
nameserver IP DNS .
nameserver primary nameserver
. secondary nameserver DNS primary name server
secondary nameserver.
search
(FQDN) Fully Qualified Domain Name
station5.example.com
Domain
. station5 Domain /etc/resolv.conf
. search
nameserver Domain
server1 server.isp.net : .server1.example.com :
domain
search domain search
domain

Proxy server
) (station ). (proxy server
FTP IP .
DNS .
DNS /etc/resolv.conf
)(hostname
hostname
.
hostname .

hostname
.
.

RHCSA/RHCE Egypt

236

)DNS (Domain Name Service

/etc/sysconfig/network
) (hostname
/etc/sysconfig/network .

network
Description

Ex.

Variable

Yes no

yes | no

NETWORKING

No ip 6 yes

yes | no

NETWORKING_IPV6

localhost.localhost

Jana.teba

HOSTNAME

NIS

RHA130

NISDOMAIN

192.168.0.254

gateway
ip dhcp eth1
gateway

eth1

GATEWAY
GATEWAYDEV

:
=ifdown
=ifup

#service network stop


#service network start
#service network restart

ip forwarding /etc/sysctl.conf
) ( ) (network interface ip .
) (gateway .
.
ip
IP .IP forwarding
IP forwarding .
.
/etc/sysctl.conf
net.ipv4.ip_forward = 1
0 sysctl p

RHCSA/RHCE Egypt

237

)DNS (Domain Name Service

DHCP
)(IP GATEWAY NETMASK DNS
DHCP dhclient daemon dhcp
dhclient daemon :
/var/lib/dhclient/dhclient-name.leases
)name = eth0 (example

system-config-network-tui

.
.

) (Device configuration Enter RETRUN


> <New Device
.

RHCSA/RHCE Egypt

238

)DNS (Domain Name Service

> <New Device enter return

Etherent Enter Return

ok
network ifdown ifup
dhclient dhcp

RHCSA/RHCE Egypt

239

: Network Diagnostic Utilities

: NETWORK DIAGNOSTIC UTILITIES

ping
ping 2 IP
ping ) ICMP (echo request ICMP
) (echo replay .
CTRL + C:

ping

host
DNS lookup ip

traceroute
.

RHCSA/RHCE Egypt

240

: Network Diagnostic Utilities

tcpdump
CTRL + C

WIRESHARK
wireshark
:
yum clean all
yum install wireshark wireshark-gnome
wireshark

RHCSA/RHCE Egypt

241

: Network Diagnostic Utilities

netstat
" "netstat
.
t tcp u udp n ip a
r routing table p process id e
:
:Proto )(UDP ,TCP
:Local Address )( , ". ":
:Foreign Address , ".":
:State " ,ESTABLISED " "TCP "."UDP
netstat -ntap
netstat:
" "listen:

" "listen :

netstat -ntlp

RHCSA/RHCE Egypt

242

Etherent Bonding

nslookup
:

dig nslookup
ethtool
mii-tool

ETHERENT BONDING

Etherent Bonding ) (network interface bandwidth


. channel bonding interface
: 2 :
-1 dev ) (text editor ( Alias bond0 bonding) :

options bond0 max_bonds=2 miimon=100 mode=1


.
-2 eth0 etc/sysconfig/network-scripts/ifcfg-bond0
text_editor ip :

-3 : :
)DEVICE=eth1 (eth1 and eth2
BOOTPROTO=none
.

RHCSA/RHCE Egypt

243

)NFS (The Network Filesystem

ONBOOT=yes
MASTER=bond0
SALVE=yes
USERCTL=no
#ifconfig bond0 up
:
)NFS (THE NETWORK FILESYSTEM
)(NFS ) (directory.
.NFS NFS
.NFS
server1 /var/ftp/pub .readme

NFS
NFS (NFS server) NFS ). (NFS client
station7 (SERVER1) NFS /mnt/pub.

NFS mount
mount ) remote hostname-1 NFS
directory-2 NFS
Remote Hostname: Directory
.
NFS protocol CIFS protocol NFS CIFS
rpcbindnfslock
nfs
t .mount

) (mount point NFS


ls:

umount:
.

RHCSA/RHCE Egypt

244

)NFS (The Network Filesystem

mount NFS .
fstab

) (admin .
noauto fstab :
noauto mount user
.

showmount -e ) (admin NFS


. showmount.
showmount NFS sever.NFS client
#showmount -e hostname
NFS hostname:

CIFS network filesystem )(common internet filesystem



smbclient samba-client CIFS
.

RHCSA/RHCE Egypt

245

)NFS (The Network Filesystem

#smbclient -L cifsserver.domain
#mkdir /remote2
#mount //cifsserver.domain/sharename /remote2
NFS
NFS mount .hard mount ) (NFS mount NFS
.uninterruptible sleep D
) (uninterruptible sleep uninterruptible kill
CTRL + C .
intr:
interruptible sleep S D
NFS soft mount:

ls 30 .
/etc/auto.net automounter NFS
/net/hostname/exported/path
/var/ftp/pub /rha/data NFS
/net.

/net ls /net/rha-server rha-server


NFS .

automounter NFS .
IP /net DNS etc/hosts/
.net/
access file remotely

RHCSA/RHCE Egypt

246

)NFS (The Network Filesystem

connect to server

places

windows share NFS autofs /net/host


.
(Remote shell access) ssh
ssh .telnet
)(ssh) ----------------------- (secure connection
)(telnet) ---------------------- (not secure connection
(ssh) --------- Communication between two encrypted hosts
:
#ssh remotehost
or #ssh remoteuser@remotehost
or #ssh remotehost hostname
#ssh -x host_ip

ssh ) (public-key , private-key :
#ssh-keygen

./ssh
)(600 -----public key , 644 ---- private key
#ssh-copy-id -i .ssh/id-rsa.pub root destination_ip
public key
)#ssh-keygen (create public key
)ssh-copy-id (copy public key
manage system clock
system-config-date data&time management
Synchronize date and time over the network

administrator

system

add www.ntp.org
advanced options speed up initial synchronization .
:
#ntpq -p

RHCSA/RHCE Egypt

Selinux

247

SELINUX

,National Security Agency (NSA) Enhanced Security linux




(log on only no protect) permissive mode-2
(log on - protect) enforcing mode-1
(disable) third mode-3
/etc/selinux
setenforce mode

sestatus selinux
: selinux
sestatus
getenforce
setenforce
getsebool
setsebool
chcon
restorecon

Shows the current status of SELinux


Shows the enforcing status of SELinux
Changes the enforcing status of SELinux
Returns the Boolean value of a service option
Sets the Boolean value of a service option
Changes the context of a file, directory, or service
Resets the context of an object

RHCSA/RHCE Egypt

exams

248

EXAMS

Every questions in this is mandatory for you to complete.example.com and remote.test has 192.168.0.0
and 192.168.1.0 network respectively.
You have one system with one virtual system in build
Packet filtering should not affect the network integrity.
Yum baseurl is baseurl=ftp://192.168.0.254/pub/rhel6/dvd.
Exam time: 2 1/2 hrs.
Questions 1 | CREATE LVM
Create the "LVM" with the name volgrp by using with the extends of 10 from the volume group named as
logical. Consider the PE size as "16MB". Mount it on /lvm1 with filesystem vfat.
Questions 2 | USER'S GROUPS AND PERMISSION:
Create a group named "manager"
A user sarah and natasha should belongs to "manager" group as a secondary group . A user harry should not
have access to interactive shell and he should be a member of "manager" group as secondary. passwd for all
user created should be "jenny".
Questions 3 | DIRECTORY COLLABORATION:
Create the Directory "/home/manager" with the following characteristics. Group ownership of
"/home/manager" should go to "manager" group. The directory should be have full permission for all
members off "manager" group but other users don't have any permissions accept "root". Files created under
"/home/manager" should get the same group ownership is set to the "manager" group.
Questions 4 | UPDATE THE KERNEL:
Install the appropriate Kernel from ftp://instructor.example.com/ftp/pub/updates. Your machine should boot
with updated kernel.
Questions 5 | CRON JOB:
The user sarah must configure a cron job that runs today at 23:14. and executes "/bin/echo "linux Is
freedoM" and deny the user max for creating cronjob .
Questions 6 | RESIZE LVM:
Resize the lvm "/dev/vgsrv/home" so that after reboot size should be in between 90MB to 120MB..
Questions 7 | BIND THE "LDAP" FOR USER AUTHENTICATION:
Note the following. BASE DN: dc=example,dc=com ldap path ldap://instructor.example.com/ Download the
certificate from "ftp://instructor.example.com/pub/EXAMPLE-CA-CERT" ldapuserX should login into your
system . Where "X" is your system no.
Questions 8 | "NTP" CLIENT:
Configure your system as "NTP" client for "instructor.example.com".
Questions 9 | AUTOMOUNT THE HOME DIRECTORY FOR LDAPUSER
Note the following. instructor.example.com(192.168.0.254) "Nfs exports" /home/guests to your system
where "x" is your station ip. Ldapuser's home directory is instructor.example.com:/home/guests/ldapuserX.
Ldapuser's home directory should be automounted locally beneath at /home/guests/ldapuserX. While login
with any of the ldapuser then only home directory should accesible from your system that ldapuserX.
Questions 10 | ACCESS CONTROL LIST:
Copy the file /etc/fstab to /var/ and configure the "ACL" as mention following. The file /var/fstab is owned
by the "root". The file /var/fstab belongs to the group "root" The file /var/fstab should not be executable by
other's. The user "sarah" should able to read and write to the file. The user "natasha" can neither read nor
write to the file. other users (future and current) shuold be able to read /var/fstab.
Questions 11 | CONFIGURE FTP SERVER:
Configure FTP access from your system. Clients within the example.com should have anonomyous FTP
access to your system.
Questions 12 | CONFIGURE "web server":
Configure your system as "web server" for the site http://serverX.example.com . Download the web page
from ftp://instructor.example.com/pub/updates/station.html Rename the the downloaded page as
"index.html" Copy the "index.html" page to the "document root" Do not make any modifications to the
content of index.html.
Questions 13 | ADD USERS:
Create the user "john" with uid 4223 with password john.

RHCSA/RHCE Egypt

SOLUTION

249

Questions 14 | EXTEND SWAP SPACE:


Extend the SWAP space with "250" MB dont remove the existing swap.
Questions 15 | LOCATE THE FILES:
locate the files of owner "john" and copy those files to the /root/john.
Questions 16 | Find words:
Download file from "http://192.168.0.254/test/cracker.txt" Search lines which contains alpha-numeric
words( combination of alphabets and number) and copy those lines is sorted order to /root/lines (output
should not contain any blank lines).
Questions 17 | SEARCH FOR WORD:
List all lines which have string "full" from "/usr/share/dict/words" file and copy the lines in /root/directory
file.
SOLUTION

Solution 1partprobe
fdisk -l
pvcreate /dev/sdb
vgcreate -s 16M logical /dev/sdb
lvcreate -n volgrp -l 10
mkfs.vfat /dev/logical/volgrp
mount /dev/logical/volgrp /lvm1
Solution 2groupadd manager
useradd sarah -p -G manager
useradd natasha -p -G manager
useradd harry -p -G manager -s /sbin/nologin
Solution 3ckdir -p /home/manager
chown root:manager /home/manager
chmod 770 /home/manager
chmod g+s /home/manager
Solution 4Wget ftp://instructor.example.com/ftp/pub/updates/kernel.rpm
Rpm -ivh kernel.rpm
Solution 5Crontab -e
14 23 * * /bin/echo "linux is freedoM"
echo "max" > /etc/cron.deny
Solution 6 partprobe
lvs
umount /dev/vgsrv/home
e2fsck -f /dev/vgsrv/home
----to reduce
resize2fs /dev/vgsrv/home 100m
lvreduce -l 100m /dev/vgsrv/home
----to increase
lvextend -l +100m /dev/vgsrv/home
resize2fs /dev/vgsrv/home
Solution 7system-config-authentication
To ensure getent passwd username_name(ex ldapuser1)
Solution 8system-configure-date

RHCSA/RHCE Egypt

SOLUTION

250

To ensure use this #ntpq -p


Solution 9chconfig autofs on
vi /etc/auto.master
/home /etc/auto.ldap
cp /etc/auto.misc /etc/auto.ldap
vi /etc/auto.ldap
ldapuser40 -rw,soft,intr 192.168.0.254:/home/guests
service autofs relaod
showmount -e 192.168.0.254
su - ldapuser40
Solution 10cp /etc/fstab /var/fstab
chown root:root /var/fstab
chmod 770 /var/fstab
setfacl -m u:others:r /var/fstab
setfacl -m u:sarah:rw /var/fstab
setfacl -m u:natasha:--- /var/fstab
getfacl /var/fstab
Solution 11yum install vsftp
vi /etc/vsftpd/vsftpd.conf
anonymous_enabled=yes
chkconfig vsftpd on
Solution 12yum install httpd
vi /etc/httpd/conf/httpd.conf
edit bottom as needed
cd /var/www/html/
wget ftp://instructor.example.com/pub/updates/station.html
mv station.html index.html
Solution 13useradd john -u 4223
Solution 14fdisk -l
partprobe
mkswap /dev/sda5
blkid
vi /etc/fstab
uuid=xxxxxx swap swap defaults 0 0
swapon -a
swapon -s
Solution 15find / -user john > /root/john
Solution 16wget http://192.168.0.254/test/cracker.txt
cat /cracker.txt | grep '[[:alnum:]]' | tr d [[:blank:]] | sort > /root/line
Solution 17grep /usr/share/dict/words "full" > /root/dictionary

RHCSA/RHCE Egypt

You might also like