Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views64 pages

Day3 - Linux Complex Workflows

Uploaded by

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

Day3 - Linux Complex Workflows

Uploaded by

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

FILE SYSTEM HIERARCHY SYSTEM

Linux uses single rooted, inverted tree like file system hierarchy
The directories and their description
a. / this is top level directory
it is parent directory for all other directories
it is called as ROOT directory
it is represented by forward slash(/)

b. /root it is home directory for root user(super user)


it provides working environment for root user

c. /home it is home directory for other users


it provide working environment for other users(other than root)

d. /boot it contains bootable files for linux


like vmlinuz(kernel) ..... ntoskrnl
initrd(INITial Ram Disk)and
GRUB(GRand Unified Bootloader).... boot.ini, ntldr

e. /etc It contains all configuration files


like /etc/passwd..... user info
/etc/resolv.conf... Preffered DNS
/etc/dhcpd.conf.... DHCP server

f. /usr By default software’s are installed in /usr directory


(Unix Sharable Resources)

g. /opt It is optional directory for /usr


It contains third party softwares

h. /bin It contains commands used by all users


(Binary files)

i. /sbin It contains commands used by only Super User(root)


(super user's binary files)

j. /dev It contains device files


like /dev/hda ... for harddisk
/dev/cdrom ... for cdrom
similar to device manager of windows

k. /proc It contain process files


Its contents are not permanent, they keep changing
It is also called as Virtual Directory
It's file contain usefull information used by OS
like /proc/meminfo ... information of RAM/SWAP
/proc/cpuinfo ... information of CPU

l. /var It is containing variable data like mails, log files

m. /mnt It is default mount point for any partition


It is empty bydefault
n. /media It contains all of removable media like cdrom, pendrive

o. /lib It contains library files which are used by OS


it is similar to dll files of windows
library files in linux are SO(shared object) files

p. /tmp It stored temporary files

Creating Files:- We Can Use 'Touch' Or 'Cat' Command

cat command is used to create file and diplay the contents of file also

syntax # cat > <new filename>

ex.1) # cat > file1

Type the contents of file here


This is a
Sample data stored
In the file with out opening using cat command
................
press ctrl + d to save the file

Note: If we use the same file name which already exits it will overwrite the old file with new file.

How To See Contents Of File

ex # cat file1
type the contents of file here
This is a
Sample data stored
In the file with out opening using cat using cat command

To append the entried to already existing file.

# cat >> file I.e it will add the text

To copy the contents of a one file to another.

# cat file1 >> file2

To copy the contents of a both files to third file.

# cat file1 file2 >> file3

To display the file with line numbers:

# cat -n file

Touch command is used to create multiple files with zero bytes size.
syntax # touch <filename>

ex # touch file1
ex # touch file2 file3 file4

To create a directory
mkdir..... make directory
syntax # mkdir <dirname>

ex 1: # mkdir dir1

ex 2: # mkdir dir1/dir2

ex 3: # mkdir dir1/dir2/dir3

We Can Use -P Option To Create Dir Inside A Dir (Subdirs)

ex 4: # mkdir -p india/ap/hyd/galaxy

To Change The Directory


cd..... change directory

syntax # cd < dir name >

ex : 1 [root@sys10~]# cd /var/log
[root@sys10 log]# pwd
/var/log
[root@sys10 log]# cd /root
[root@sys10~]# pwd
/root

a. cd - means switch directory to previous directory


b. cd ~ means go back to home directory of user
c. cd .. means go to parent directory
d. cd ../.. means go to 2 level parent directory
e. cd means go back to home directory of user

Moving, copying, and deleting files


Commands for moving, copying, and deleting files are fairly straightforward. To change the
location of a file, use the mv command. To copy a file from one location to another, use the cp
command. To remove a file, use the rm command. Here are some examples:
$ mv abc def
$ mv abc ~
$ cp abc def
$ cp abc ~
$ rm abc
$ rm *

Of the two move (mv) commands, the first moves the file abc to the file def in the same
directory (essentially renaming it), whereas the second moves the file abc to your home
directory (~). The first copy command (cp) copies abc to the file def, whereas the second
copies abc to your home directory (~). The first remove command (rm) deletes the abc file;
the second removes all the files in the current directory (except those that start with a dot).

NOTE: For the root user, the mv, cp, and rm commands are aliased to each be run with the -i
option.
This causes a prompt to appear asking you to confirm each copy and removal, one file at a time.
For file moves, the -i option will prompt you if the move would overwrite a file, but you may still
unintentionally move a file, so be careful. This is done to prevent the root user from messing up a
large group of files by mistake.

To temporarily get around an alias, type the full path to the command (for example,
/bin/rm -rf /tmp/junk/*).

how to copy file:


# cp command is used to copy a file

syntax # cp <source> <destination>


ex 1: # cp /root/file1 /usr

This command will copy file1 file to /usr directory with same name.

Ex 1: # cp /root/file1 /root/one/two/three/file123
this command will copy file1 file to three directory with file123 name.

ex 2: # cp a* /var

This command will copy all files starting with the alphabet a to /var directory.

By default cp command will not copy directory we have to use -r (recursively) switch to copy directory

Ex 3: # cp -r /root/dir2 /usr

This command will copy dir2 directory to /usr location.


Ex 4: # cp -r /root/dir1/* /var

This command will copy all the contents of dir1 directory to var directory

Note:- we can use wildcard characters


* means multiple characters
? means single character

To delete a file:

rm command is used to delete a file/directory

syntax # rm < file name >

ex 1: # rm /root/file1
it will ask for confirmation, press y to delete file
ex 2: # rm -f /root/file2
it will not ask for confirmation

to remove a directory also we have to use -r option


ex 3: # rm -r /root/dir1
this command will delete dir1 directory with all its contents,
with confimation.

ex 4: # rm -rf /root/dir2
this command will delete dir2 directory with all its contents,
without confimation. f for (forcefully)

rmdir .... to delete an empty dir


syntax # rmdir < dir name>

ex 1: # rmdir one error...... Directory not empty

If the directory is not empty u will get this message.

Ex 1: # rmdir one/two/three
Ex 2: # rmdir one/two
Ex 3: # rmdir one

mv ..... to move file/dir this command is also used to rename file/dir

syntax # mv < source > < destination >


ex 1: # mv /root/file1 /boot
this comamnd will cut file1 file and paste it in /boot directory

ex 2: # mv /root/file2 /root/newfile
this command will rename file2 file to newfile

Note : if we provide a newfile name it will rename a file/dir

if we provide a existing file name or directory name it will move.

Nautilus is a tool with which we can check the files/dirs in GUI mode. run the command in terminal in gui mode.

# nautilus /usr To list the contents of usr dir in gui mode.

# nautilus / To list the contents of / dir in gui mode.

# nautilus & will list the contents of pwd.

BASIC COMMANDS

This command is used to list the contents of a directory generally following options are used with 'ls' (list
directories)

a. #ls -l long listing


b. #ls -m list all files/dirs with commas
c. #ls -a list all files and directories including(hidden)
d. #ls -R Recursive order
e. #ls -r reverse order
f. #ls -i to list inode numbers
g. #ll same as 'ls -l'
h. #ll -h list all files/dir with size's in MBS,GBS,KBS.

The output of ll command shows following information:-

file type (field 1)


permissions
links (field 2)
owner of file (field 3)
owner's group name (field 4)
size of file in bytes (field 5)
date and time of modification (field 6)
file name (field 7)

pwd.... print present working dir

a. [root@sys10~]# pwd
/root

b. [root@sys10boot]# pwd
/boot

date...... to display date and time


a. # date (press enter)

b. # date -s " " to change the date

who ........ to see who is logged in


# who( press enter )

whoami ..... to show who is working on present terminal


# whoami (press enter)

cal... to show calender


# cal to show present month's calender
# cal 2008 to show calender of year 2008
# cal 4 2008 to show calender for april 2008

# bc to open calculator

Help commands :-

To get the information of a particular command can use whatis command.

ex: 1 a. # whatis ls

b. # whatis mkdir

To know the usage of a particular command.


ex: 2 a. # ls --help To get the documentation of a particular command.(man pages)

b. # man ls
(or)
# info ls

To copy the output of man pages 2 a file.


# man ls >> file1

Detailed Doc in /usr/share/doc directory.

VISUAL DISPLAY EDITOR


VI visual display editor
VIM visual display editor improved

this is command mode editor for files other editors are emacs, gedit vi editor is most popular it is having 3 modes:

1. command mode
2. insert mode (edit mode)
3. execution mode
vi filename edit filename starting at line 1
vi -r filename recover filename that was being edited when system cra

Command mode:
dd to delete a line (cut)
4dd to delete 4 lines (cut)
dw to delete a word
dl (or) x to delete a character
yy to copy a line (yank)
10yy to copy 10 lines (yank)
yw to copy a word
yl to copy a character
p to paste lines below cursor position
10p to paste line 10 times
P to past lines above cursor position
r to replace a character
u to undo
ctrl+r to redo
/<find> to find a text inside a file
shift zz to save and quit from command mode
3w to move cursor after 3 words

To get into insert mode to add the data.


i Insert at current cursor position
I insert at start of line
a Append at current cursor position
A Append at the end of line
o Insert line below cursor position
O Insert line above cursor position

Execution mode:
:w to save the file
:wq to save and quit
:x to save and quit
:q to quit without saving
:q! to quit without saving (forcefully)
:wq! to save and quit file (forcefully) {used for read only files}
:se nu to set line Number
:se nonu to remove line Number
:14 to move cursor to line no. 14
:/find word to find for a word
:r /root/file1 to read the contents of file1 file in the present file
:w >> /root/file2 to append the data of present file to /root/file2
:1,$d to delete entire contents of a file

How to find and replace in execution mode:-


:<range>s/<find what>/<replace with>/<options>
range can be:

ex: :1,$s/this/that
% complete file
10,$ from 10th line to last line
15,20 from 15th line to 20th line

.s will replace the cursor line only

option can be:


g to replace all the occurrence in same line
i to ignore case sensitivity
c to replace with conformation

To find cat, CAT, Cat, cAT and replace with dog in complete file
ex. :1,$s/cat/dog/gi

To remove the word (this) from the file.


:1,$s/this//

USER GROUP ADMINISTRATION

Whenever a USER is created in linux :-


1. its home directory is created(/home/username)
2. its mail box is created(/var/spool/mail)
3. unique UID & GID are given to user

UID for system users 0 to 499


UID for normal users/regular users 500 to 60,000

Redhat Enterprise Linux and fedora used UPG scheme


UPG... User Private Group
it means that whenever a user is created is has its own private group

Create USER:
syntax. # useradd <option> <username>
options are
-u user id
-G Secondary group id
-g primary group id
-d home directory
-c comment
-s shell
-o overwriting the id

ex. 1 # useradd user1 user1 is created

ex. 2. # useradd -u 1001 -d /anydirectory -s /bin/sh user2


user2 is created with uid=1001,home=/anydirectory,shell=/bin/sh

All of user information is stored in /etc/passwd file. It contains 7 fields:


user1:x:500:500::/home/user1:/bin/bash
1 2 3 4 5 6 7

1 user login name


2 mask password
3 uid
4 gid (primary group id)
5 comment (bydefault no comment)
6 user's home directory
7 user's login shell

After creating users we can modify its properties by using usermod:


syntax. # usermod <options> <username>
options are:
all of the options which are used with useradd command and,
-l to change login name
-L to LOCK account
-U to UNLOCK account

ex. 1: # usermod -l newname oldname


ex. 2: # usermod -L newname
ex 3:. # usermod -U newname

Note:- when a account is locked it will show !(exclamation mark) in /etc/shadow file.

To set password:
syntax. # passwd <username>
ex. 1 # passwd user1
enter the password

re enter the password

ex. 2 # passwd root


enter the password

re enter the password

To delete a user account:


syntax. # userdel <option> <username>
ex. # userdel user1
it will delete user1 but home directory will not be deleted
ex. # userdel -r user2
it will delete user2 and home directory will also be deleted

GROUPS
To create a group:
syntax. # groupadd <option> <groupname>
options:
-g to set GID
ex. 1: # groupadd -g 1010 sales

ex. 2: # groupadd mktg

To add/delete secondary users to group


syntax # gpasswd <options> <user> <groupname>
ex. 1: # gpasswd -a user1 sales to add a single user

ex. 2: # gpasswd -M user2,user3,user4 sales to add multiple users

ex. 3: # gpasswd -d user1 sales to delete secondary user from member list

To delete group (group must not contain any primary user )


syntax. # groupdel <groupname>
ex. 1: # groupdel sales

note: All information of group is stored in /etc/group file it contain list of secondary members also.

PASSWORD POLICY:

To set the password policy for the user password.


# chage <username>

To list the password settings.


# chage -l <username>

The password information is stored inside /etc/shadow file


1. it contains encrypted password
2. linux uses MD5 and DES algorithms for encrypting passwords
3. MD5 Message Digest version 5 (128 bit)
4. DES Data Encryption Standard (64 bit)

To check the password encryption standard of the user password.


# passwd -S <username>

To change the password encryption standard


# authconfig-tui

To remove the password for user.


# passwd -d <username>
STRING PROCESSING
wc..... word count
# wc file1
it will show no. of lines, no. of words, no. of characters

# wc -l file1 shows only no. of lines

# wc -w file1 shows only no. words

# wc -c file1 shows only no. of characters.

More and less commands are used to see the contents of a file page wise.
syntax. # more <filename>
ex 1. # more file1
Now to see contents page wise press space to see contents line wise press enter

Less command is same as more but to quit less command we have to press q
#less <filename>
#less file1

head ........ this command is used to see first 10 lines of a file.


ex. # head file1

To see the first 'n' lines


ex. # head -n file1
# head -15 file1 [lists first 15 lines of a file]

tail ....... this command is used to see last 10 lines of a file.


ex. # tail file1

To see the last 'n' lines:


# tail -n file1
# tail -15 file1 [lists last 15 lines of a file]

REDIRECTION
This command will APPEND the contents of file1 to file2.
# cat file1 >> file2

This command is used to append the output of ls -l to file1.


# ls -l >> file3

The output of 'ls-l' is saved inside file3 file.

pipe (|) is used to give output of one command to another command

sort command is used to sort the lines in a file.

# sort file1

# sort -b file1
Cut:
cut is used to give the output of selected fields of each line of a file.
# cut -f1 -d /etc/passwd

ADMINISTRATIVE TOOLS

Task Automation by using 'cron' and 'at'

1. cron daemon is used to automate any task,


2. by using cron daemon we can run any task in background on particular
date and time, this is similar to schedule task of windows
3. main configuration file is /etc/crontab
4. daemon name is crond

To add a new task :-


# crontab -e

This will open a blank file,


It is having following fields:
# min hr date month day of week task(command)
05 15 24 04 * mkdir /root/auto

This task is to create "auto" dir in /root at 03:05pm on 24/04/08 The task will be completed in background

To restart cron service:


# service crond restart

To see current pending task:-


# crontab -l

To remove any task:-


# crontab -r

At or batch this command is used to schedule task for one time only:
# at 13:30 or batch 13:30
at> touch /root/breaktime
at> (press ctrl+d to save)

To check it
# atq it will diplay task no. and time

To remove any task :


# atrm < task no.>

ex.
# at 13:29
at> eject
at> ctrl+d
# at 13:30
at> eject -t
at> ctrl+d
# at 13:31
at> eject
at> ctrl+d

Check task list:


# atq
2
3
4
Remove any particular task
# atrm 4

atd service should be running.


# service atd restart.

BACKUP & RESTORE

TAR:- Tape archive this command is used to create archive.


syntax: # tar <option> <destination> <source>
options are:-
-c to create a new archive
-v verbose mode
-f to create archive of files also

-x to extract archive
-z to zip archive using gzip
-j to zip archive using bzip2

Ex 1: # tar -cvf /var/home.tar /home


to create archive of /home directory inside /var directory
Ex 2: # tar -tvf /var/home.tar
to see the contents of home.tar archive without extracting
Ex 3: # tar -xvf /var/home.tar
to extract /var/home.tar inside /var
Ex 4: # tar -xvf /var/home.tar -C /home
to extract /var/home.tar to /home directory
Ex 5: # tar -cvfz /var/home.tar /home
to create a tar of /home and zip it using gzip utility
Ex 6: # tar -xvfz /var/home.tar
to extract home.tar using gunzip utility
Ex 7: # tar -cvfj /var/home.tar /home
to create tar and zip it using bzip2 utility
Ex 8: # tar -xvfj /var/home.tar
to extract home.tar uing bunzip2 utility

After creating tar how to zip there are two zip commands used, gzip/gunzip and bzip2/bunzip2 bzip2 is more
powerfully than gzip

cpio - copy input & output

To take a backup of 1 file1.


# ls file1 | cpio -o > back.cpio
To take a backup of 2 files.
# ls file1 file2 | cpio -o > bkp.cpio

To take a backup of all files starting with alphabet a.


# ls a* | cpio -o > bkup.cpio

To take a backup of all files in a current directory.


# ls * | cpio -o > bkup.cpio
DUMP
Dump is a tool used on Tape Drives.
# dump -0uf <destination> <source>
# dump -0uf /dev/hda8 /home

0 -[zero]full backup.
u - updates in dumpdates file.
f - file.

Note: While using dump command v need to create a new filesystem here /dev/hda8 is a new unformated
filesystem.

Restoring:
# cd /home

# restore -if /dev/hda8


add: *
extract: enter
set owner/group: yes

PERMISSIONS:-

Permissions associated with files and directories in Linux were designed to


keep users from accessing other users’ private files and to protect important system files.

Permission bits appear as rwxrwxrwx. The first three bits apply to the owner’s
permission, the next three apply to the group assigned to the file, and the last three apply to all
others. The r stands for read, the w stands for write, and the x stands for execute permissions.
If a dash appears instead of the letter, it means that permission is turned off for that associated
read, write, or execute.

To see the present permission on any file or directory:-


# ls -ld <filename> //This is used to check the directory/file permissions.

You can see the permission for any file or directory by typing the ls -ld command. The
named file or directory appears as those shown in the following example:
$ ls -ld ch3 test
-rw-rw-r-- 1 chris sales 4983 Jan 18 22:13 ch3
drwxr-xr-x 2 chris sales 1024 Jan 24 13:47 test
The first line shows a file (ch3) that has read and write permission for the owner and the
group. All other users have read permission, which means they can view the file but cannot
change its contents (although a user may be allowed to remove the file, since the ability to
remove a file is based on directory permissions). The second line shows a directory (indicated
by the letter d before the permission bits). The owner has read, write, and execute permission,
while the group and other users have only read and execute permissions. As a result, only the
owner can add, change, or delete files in that directory. Any other user, however, can only
read the contents, change to that directory, and list the contents of the directory. (Note that by
using the -d option, the test directory entry is listed without listing its contents.)
If you own a file, you can change the permission on it as you please. You can do this with the
chmod command. For each of the three sets of permission on a file (read, write, and execute),
r is assigned to the number 4, w to 2, and x to 1. So to make permissions wide open for
yourself as owner, you would set the first number to 7 (4 plus 2 plus 1). The same would be
true for group and other permission. Any combination of permissions can result from 0 (no
permission) through 7 (full permission).

Permission are applied on three Access levels:-


owner or user level - u
group level - g
others level - o

Access modes are of three types:-


r read only -4
w write/edit/delete/append - 2
x execute/run a command - 1

Access modes are different on file and directory


File Directory
read - file can be open, read contents of dir can be listed(ls)
write - contents of file can b changed. contents of dir can be deleted, created.
execute - command/script can be run user can enter into dir using(cd)

Here are some examples of how to change permission on a file and what the resulting
permission would be:
chmod 777 files 􀁼 rwxrwxrwx
chmod 755 files 􀁼 rwxr-xr-x
chmod 644 files 􀁼 rw-r—r
chmod 000 files 􀁼 ---------
You can also turn file permissions on and off using plus (+) and minus (-) signs, respectively.
This can be done for the owner user (u), owner group (g), others (o), and all users (a). For
example, each time starting with a file that has all permissions open (rwxrwxrwx), here are
some chmod examples with resulting permissions after using a minus sign:
chmod a-w files 􀁼 r-xr-xr-x
chmod o-x files 􀁼 rwsrwsrw
chmod go-rwx files 􀁼 rwx------

The output of ls -ld command shows following properties


-rw-r--r-- 2 root root 54 15 march ..... file1
`````````` `` ```` ```` `` `````````````` ```````
filetype + permission, links , owner, grp name of owner, size in bytes, date of modification, file name.
file types:-
- normal file
d directory
l link file(shortcut)
b block file(harddisk,floppydisk)
c character file(keyboard,mouse)
Permission can be set on any file/dir by two methods:-
1. absolute method(numerical)
2. symbolic method(alphabetical)

To set the permission on file/dir 'chmod' command is used bydefault permissions on file and dir:-
file dir
root 644 755
normal user 664 775

here,
read=4
write=2
execute=1

To set permission on file/dir in symbolic mode:-

syntax. # chmod <permission> <file/dir name>


ex. # chmod 646 /file1
or
# chmod u=rw,g=r,o=rw /file1
or
# chmod o+w /file1

This command is used to give full permission to all.


# chmod ugo=rwx /file1
or
# chmod 777 /file1

This command is used to remove all permission to all.


ex. # chmod 000 /file1
or
# chmod u=-,g=-,o=- /file1
or
# chmod ugo=- /file1

Note:- UMASK- is the number which is removed from full permission of file / dir.

Formula:-
full permissions - umask = default file/dir permissions.

default umask of root user is 022

default umask of unprivledged user is 002

For root user:-


file dir
default perm. 666 777
subtract UMASK 022 -022

Resulting permission 644 755

For normal user:-


file dir
def. perm. 666 777
subtract UMASK -002 -002
Resulting perm. 664 775

To check the present umask value.


# umask

To change the umask value temporaryly.


# umask 0044

To change the umask value perminently.


# vi /etc/bashrc

To change the owner of a file/dir.


# chown <user> <file/dirname>
# chown sam file1

To change the group of a file/dir.


# chgrp <group> <file/dirname>
# chgrp sales file1

The umask value represents the permissions that are not given on a new file. It masks the
permissions value of 666 for a file and 777 for a directory. The umask value of 022 results in
permission for a directory of 755 (rwxr-xr-x). That same umask results in a file permission
of 644 (rw-r--r--). (Execute permissions are off by default for regular files

TIP: Here’s a great tip for changing the permission for lots of files at once. Using the -R options of
chmod, you can change the permission for all of the files and directories within a directory structure
at
once. For example, if you want to open permissions completely to all files and directories in the
/tmp/test directory, you can type the following:
$ chmod -R 777 /tmp/test
This command line runs chmod recursively (-R) for the /tmp/test directory, as well as any files or
directories that exist below that point in the file system (for example, /tmp/test/hat,
/tmp/test/hat/caps, and so on). All would be set to 777 (full read/write/execute permissions).

ADVANCE FILE PERMISSIONS


There are 3 types of adv. permissions:

SUID userlevel
SGID Grouplevel
Stickybit others level

To set adv permissions by using numeric method we use


suid = 4
sgid = 2
stickybit = 1
SUID:- If suid is set on any command then any normal user can run that command with privileges of root user
like, Default ping command is having suid, so all users can run that command but if suid is removed then
'permission is denied'

# whereis ping
/bin/ping

# ls -ld /bin/ping
-rwsr-xr-x ..........
````` this means SUID is set bydefault

To remove SUID:
# chmod 0755 /bin/ping

# ls -ld /bin/ping
-rwxr-xr-x ................
```` this means SUID is removed

To check:
log in as normal user and try to ping
it will display error..... Operation not permitted

To set SUID again.


# chmod 4755 /bin/ping

SGID:- SGID is used for group inheritance, files and directories will Get groupname from their parent directory.
ex.
# mkdir /mywork
# chmod 777 /mywork
# groupadd sales
# chgrp sales /mywork
# chmod 2777 /mywork
# ls -ld /mywork

Now login with any user and create some files/dirs in /mywork directory and check the properties of files and
dirs, groupowner will be same as of parent directory. If sgid is disabled there will be a change in the group owner
for the files which r newly created.

Sticky Bit:- If sticky bit is set for a directory then only owner can delete the files/dirs in that dir.
ex.
# mkdir /mywork
# chmod 1777 /mywork
# ls -ld /mywork

It will display rwt.... for sticky bit


# su - user1
$ touch /mywork/file1
$ exit
# su - user2
$ rm /mywork/file1 error.... permission denied

To remove stickybit.
# chmod 0777 /mywork

LINUX SYSTEM ADMINISTRATION


Partitions:-
fdisk command is used in Linux to create, delete, view, manage partitions.
# fdisk -l

Disk /dev/hda: 41.1 GB, 41174138880 bytes

Device Boot Start End cyl Blocks Id File System


/dev/hda1 * 1 1020 8193118+ 7 HPFS/NTFS
/dev/hda2 1021 1033 104422+ 83 Linux

Note:- 1Block=1KB Id is used by system to identify the type of partition. * means it is a boot partition.

How to create new partition:-


# fdisk < device name >
# fdisk /dev/hda

command (m for help):


Commands are:-
n new partition
d delete partition
p print partition table
t set system id(tag)
w to save and quit
q to quit without saving
m prints this help
l to list system id

To create new partition:-


command(m for help): n
first cyl..........: (press enter)
last cylinder size in mb +sizeM.. :+100M

command(m for help): w

it will display warning:- kernel use old partition table.


# partprobe /dev/hda

To check partition:-
# fdisk -l

To delete partition:-
first note the partition no. by using 'fdisk -l' command.
for example----/dev/hda9
then,

# fdisk /dev/hda
command(m for help) : d
partition no.(1-9) : 9
command(m for help) : w

# partprobe /dev/hda

Note:- Do not delete the partitions which are already existing. Delete only those partitions which we have
created

To format partition:-
mkfs command is used to make file system.

To format partition using ext3 file system:-


# mkfs.ext3 /dev/hda9

To format partition using ext2 file system:-


# mkfs.ext2 /dev/hda9

To format partition using vfat file system:-


# mkfs.vfat /dev/hda9

To mount the formatted partition:-


mount command is used to create a link between physical partition and an empty directory. You can use /mnt
directory for mounting any partition or you can create your own dir. also

# mount <devicename+partitionno> <mount point>


# mount /dev/hda9 /mnt
# mount /dev/hda10 /galaxy

After mounting you can create file/dir in that partition:-


# cd /mnt
# touch 1 2 3 4
# mkdir one two three four

mount command is also used to check whether the partition is mounted or not.
# mount (press enter) it will show all currently mounted partitions

To unmount the partition


# umount <partition no> or <dirname>
# umount /dev/hda9 or /mnt

Label:- label of partition is name of partition


(ex. in windows .....disk1_vol1, localdisik)
(ex. in linux ..... /boot, /root)

To check current label:


# e2label <partition no>
# e2label /dev/hda1
# e2label /dev/hda2

How to assign label:


# e2label /dev/hda9 GatesDisk1
# e2label /dev/hda10 GatesDisk2
Mounting the partition using Label.
# mount LABEL=Myname /mnt

To Remove label:
# e2label /dev/hda9 ""
Note: unmount the partitions before converting/tunning.

How to convert ext2 to ext3


# tune2fs -j /dev/hda9 [-j stands for journal]

To convert ext3 to ext2


# tune2fs -O ^has_journal /dev/hda9 [-O stands for options] (capital O)

/etc/fstab - This is file used for permanent mounting.


/etc/mtab - This is file used for temporary mounting.

To check the free, used, available space on the disk.

df stands for disk free.

This command will list the free & used space of all the partitions which r mounted.
# df -h

This command will list the free & used space of a single partition which is mounted.
# df -h /dev/hda2

This command will list the free & used space and filesystem type of all the partitions which r mounted.
# df -hT

To Check the Disk Usage only:

This command will list the used space of each & every file/dir in the /usr directory.

# du -h /usr

Mounting the removable media's.

To Mount Cd Rom.
# mount /dev/cdrom /mnt
# cd /mnt
# ls

To Mount Dvd.
# mount /dev/dvd /mnt

To Mount floppy.
# mount /dev/fd0 /mnt

To Mount tape drives.[ide]


# mount /dev/ht0 /mnt
(or)
# mount /dev/ht1 /mnt
To Mount tape drives.[scsi]
# mount /dev/st0 /mnt
(or)
# mount /dev/st1 /mnt

LINKS
Links are shortcuts, pointers for easy accessing of a file/dir.
There are two types of Links:-

Hard link Soft Link

1.can't be created across partitions can be created across the partitions

2.size of both files are same. size of link file is equal to no.
of characters in the name of source file.

3. inode no's of both the files are same. inode no's of source and link files are different.
4. if original file is deleted then also link file can be if original file is deleted then link file
accessed. cannot be accessed

5. link file is a copy of source file. link file is dependent on source file.

Note: links should be always created from destination directory.

command used to create Hard link:-


syntax # ln <source file> <target file>

To check use:-
# ls -ali <source file> <target file>

command used to create Soft link:-


syntax # ln -s <source file> <target file>
to check use:-
# ls -ali

Compressing/zipping Tools.
# gzip <file name>
# gzip /var/file1

# ls -ld /var/file1.gz

To unzip using gunzip:-


# gunzip /var/file1.gz

To zip using bzip2:-


# bzip2 /var/file2
# ls -ld /var/file2.bz2

To unzip using bunzip2:-


# bunzip2 /var/file2.bz2
SWAP

swap is a file system, it is similar to virtual memory of windows


swap space is used to improve the system performance
How swap works?
system identifies the idle process in RAM(memory) and sends it to
swap space, so that RAM again becomes free.
swap space is created on Hard disk
Rule to create Swap?
if size of RAM < 2GB
then size of SWAP=2*RAM
else
size of SWAP= 2 + RAM

# free [to check ram size]


# more /proc/meminfo

To check swap status.


# more /proc/swaps
(or)
# swapon -s [-s option stands for status]

To increase Swap size


1. First create a new partition using fdisk command
ex. /dev/hda9

2. make it a swap partition:-


# mkswap /dev/hda9

3. Enable swap on this partition:-


# swapon /dev/hda9

check it by using 'swapon -s'

4.Disable swap on this partition:-


# swapoff /dev/hda9

ACL's
Acl's refers to assigning different privileges for users who come under others category. They are of 2 types.
1. user level [appling on individual users]
2. group level [appling on multiple users/groups]

Note: Remount the partition in which u have the files with acl permissions.

To remount the partition.


# mount -o remount,acl /

To create a file with some data in it.


# cat > /file1

To create users.
# useradd sam
# useradd john
To set acls for a user.
# setfacl -m u:sam:rw /file1 [-m modify,u user,]
# setfacl -m u:john:- /file1

login with users and check the permissions.

Create group.
# groupadd sales

Add new members in the secondary group.


# useradd -G sales vinay
# useradd -G sales suman

To set group acls for users.


# setfacl -m g:sales:rw /file1 [g group]

Login with group members and check the permissions.

To list the acls of users/groups on a file.


# getfacl /file1

To remove acls.
# setfacl -x u:sam /file1 [users]
# setfacl -x g:sales /file1 [groups]

DISK QUOTAS
quota's are used to restrict the amount of disk usage by any user, group on a particular partition.

QUOTA
user level . group level
blocks inodes .blocks inodes
(size in kb) (no. of files) .(size in kb) (no. of files)

inode:- Index node no. it is used by system to identify the properties of file like, file type, permission, owner,
group, size in blocks, no. of links, time stamps.

Inode no. is unique to a file.

To see inode no.......... # ls -il < file name>

Steps to implement quota:-


1. create a new partition.(fdisk)
2. format it(mkfs.ext3)
3. mount partition using usrquota,grpquota option(mount)
4. check mounted partition(mount)
5. create user,group
6. create quota file inside quota partition(quotacheck)
7. enable quota on quota partition(quotaon)
8. specify quota limits(edquota)

3. # mount -o usrquota,grpquota /dev/hdaX /mnt


4.# mount
5.# useradd user1; #useradd user2
# passwd user1
# passwd user2
6.# quotacheck -cugv /dev/hdaX

options:-
-c to create quota database files
-u user quota
-g group quota
-v verbose
Note: group level quota should b applied on primary groups only.

To check whether files are created or not:-


# ls /mnt
7 # quotaon /mnt

8 To set userlevel quota:-


# edquota -u user1

Provide full permissions for the directory.


# chmod 777 /mnt

Add a group.
# groupadd mrkt

Change the users primary group.


# useradd -g mrkt aryan
# useradd -g mrkt kiran

To set group level quota:-


# edquota -g mrkt

To check the report of quota's.


# repquota /mnt

Login with users and check the limit.

after 8th step quota file will open

here,
soft means --- limit after which warning message is displayed
hard means --- limit after which error message is displayed

To check quota limits, log on as user and create file/dir


or use "repquota <mnt point>" command
LINUX SYSTEM ADMINISTRATION

RAID
Redundant Array of Inexpensive/Independent Disk

2 or more hard disk are combined to create RAID, it is used in servers with SCSI Harddisk.

Redhat supports following RAID Levels:-

RAID 0 (striping) 2min 32max


RAID 1 (mirroring) 2min 2max
RAID 4 (striping with Parity disk) 3min 32max
RAID 5 (striping with distributed parity) 3min 32max

To implement RAID 5 on redhat:-


'mdadm' command is used for administration of MetaDisk in linux.

syntax. # mdadm -C <metadevice> -nX <device1> <device2>..... -lX


-C to create metadevice
-n to set no. of harddisk
-l to set RAID level

ex. 1 # mdadm -C /dev/md0 -n3 /dev/hda9 /dev/hda10 /dev/hda11 -l5


/dev/md0 is metadisk
/dev/hda9,10,11 are new partitions
-n3 means no. of harddisk=3
-l5 means RAID level=5
after creating RAID to check it:-

ex. 2 # mdadm -D /dev/md0


-D to display information

To use RAID Partition format it:-


ex. 3 # mkfs.ext3 /dev/md0

To make a mount point:-


ex. 4 # mkdir /cms
now mount RAID Partition on /cms

ex. 5 # mount /dev/md0 /cms


now create some files and directory in /cms.

To make any RAID Device faulty


ex. # mdadm -f /dev/md0 /dev/hda10
/dev/hda10 from /dev/md0 is now faulty

To check it:-
ex. # mdadm -D /dev/md0
it will show faulty device----- /dev/hda10

To remove any Faulty Device from RAID


ex. # mdadm -r /dev/md0 /dev/hda10
To check it:-
ex. # mdadm -D /dev/md0
it will show only 2 devices..... one device is removed.

To add newly created partition to already existing RAID:-


ex. # mdadm -a /dev/md0 /dev/hda12
here /dev/hda12 is newly created partition.

To check:-
ex. # mdadm -D /dev/md0
it will show spare building for some time. Then it will show active synchronous.

LVM....... Logical Volume Manager.

In linux, lvm is used to create logical partitions, called as logical volumes. we can easily resize logical volumes,
without data loss. LVM can be created using one or more harddisk. We will implement LVM on 3 different
partitions of single harddisk.

To create Physical Volume:-


# pvcreate /dev/hda9 /dev/hda10 /dev/hda11

To check Physical Volume:-


# pvdisplay | more

To create Volume Group (name of volume group is CMS):-


syntax # vgcreate <vgname> <pv1> <pv2> <pv3> .........
# vgcreate cms /dev/hda9 /dev/hda10 /dev/hda11

To check Volume Gorup:-


syntax # vgdisplay <vgname>
# vgdisplay cms

To create Logical Volume (name of Logical Volume is LINUX):-


syntax # lvcreate -L +sizeM <vgname> -n <lvname>
# lvcreate -L +100m cms -n linux

Another logical volume(name is CCNA):-


# lvcreate -L +50m cms -n ccna

Another logical volume(name is MCSA):-


# lvcreate -L +60m cms -n msca

To check Logical Volume:-


syntax # lvdisplay <lvname>
# lvdisplay linux
# lvdisplay ccna
# lvdisplay mcsa

To write data into Logical Volume:-


First format Logical Volume:-
# mkfs.ext3 /dev/cms/linux
then mount Logical Volume on a Directory:-
# mount /dev/cms/linux /mnt
now create some files/dir in mount point:-

# cd /mnt
# touch 1 2 3 4 5

To resize LV:-
syntax # lvresize -L +/-sizeM <lvname>
# lvresize -L +10M /dev/cms/linux
# lvresize -L -20M /dev/cms/linux

To remove LV:-
# lvremove /dev/cms/mcsa

How to add new Physical Volume to already existing Volume Group:-


first create new partition.......... /dev/hda12 using fdisk
now create physical volume:-
# pvcreate /dev/hda12

now add this physical volume to Volume Group:-


# vgextend cms /dev/hda12

LINUX SYSTEM ADMINISTRATION


RPM ADMINISTRATION

sample rpm file:-


vsftpd-2.0.5-10.el5.i386.rpm
pakagename-version-release.enterpriselinux5.architecture.extension

There are two way to install rpm:-


1. standalone installation(rpm file is on your sys/cdrom)
2. network installation(rpm file is on Server)

To install rpm Locally(standalone installation):-


first mount cd/dvd on /mnt directory:-
# mount /dev/dvdwriter /mnt
# cd /mnt
# cd Server
# ls vsftpd*
vsftpd-2.0.5-10.el5.i386.rpm

Install this pakage:-


# rpm ivh vsftpd-2.0.5-10.el5.i386.rpm
preparing..... ############################[100%]
#####################################[100%]

RPM options:-
i install package
U(capital U) Upgrade Package
v verbose mode installation
h hash
--force to forcefully install package, overwrite previous
Installation.
--nodeps to remove package but dependency will not be removed.

-e to erase/remove installed pakages


-q to query installed pakages
-qa to query all installed pakages
-qd to see documentations files inside pakage
-ql to see all files inside pakage
-qs to see the status of files inside pakage
-qi to see detailed information of installed pakage
-qip to see detailed info of not installed pakage

To install packages from network server:-


Note:- ip addr of server in lab is 192.168.10.10 share directory name is /var/ftp/pub/Server here all rpm are
already copied. on client machine:-
Method 1:- NFS
first ping server
# ping 192.168.10.10

then mount the shared directory from server to any local directory:-
# mount 192.168.10.10:/var/ftp/pub/Server /mnt
```````````` ``````````````````` ````
IP add of server:/location of shared dir local dir.

go to mount point
# cd /mnt

now install pakage:-


# rpm -ivh <pakage name + version>
# rpm -ivh vsftpd-2.0.5-10.el5.i386.rpm (try dialog rpm also)

Method 2:- FTP


first ping server
# ping 192.168.10.10

then install pakages using ftp method:-


# rpm -ivh ftp://192.168.10.10/pub/Server/<pakage name+version>
# rpm -ivh ftp://192.168.10.10/pub/Server/vsftpd-2.0.5-10.el5.i386.rpm

YUM
YellowDog Updater Modified
yum feature was available with fedora, now it is available in RHEL5 RPM feature is used to install pakages but
its main drawback is Failed Dependency Resolution. yum automatically identifies dependency in pakages,&
install those dependencies also.by using YUM we can install, remove, list pakages and group of pakages.

Repository:- it is the place where we create RPM Dump on server we copy all rpm from RHEL cd/dvd here a list
of all those pakages is created this list of packages is called Repository.

generally we copy all rpm of 'Server' directory of rhel cd/dvd to /var/ftp/pub/Server directory on Server.

Server side configuration:-


1. copy rpms from cd/dvd to /var/ftp/pub/Server
2. install pakage createrepo* from cd
3. create repository
4. edit configuration file /etc/yum.repos.d/rhel-debuginfo.repo

Client side configuration:-


1. check ip addr
2. ping server(192.168.1.10)
3. edit configuration file /etc/yum.repos.d/rhel-debuginfo.repo
4. start installing pakages using 'yum' command.

Steps for Server:-


if vsftpd pakage is not installed then install it
make dir... /var/ftp/pub/Server
1 # mount /dev/dvdwriter /mnt
# cp -r /mnt/Server/* /var/ftp/pub/Server
`````````````` ```````````````````
source target
# cd /mnt
2. # rpm -ivh createrepo*
3. # createrepo -g /mnt/Server/repodata/comps* /var/ftp/pub/Server/
source target
4. # vi /etc/yum.repos.d/rhel-debuginfo.repo
edit following lines:-
#baseurl (remove hash)
#enabled (remove hash)
baseurl=ftp://<server ip adr>/pub/Server
(192.168.1.10)
enabled=1

Steps for Client side configuration:-


just edit same file /etc/yum.repos.d/rhel-debuginfo.repo and start installing pakages using 'yum' command

yum command :-
# yum install <pakagename> rpm -ivh <pkgname>
# yum remove <pakagename> rpm -e <pkgname>
# yum list installed rpm -qa
# yum list installed <pakagename> rpm -q <pkgname>
# yum grouplist -----
# yum upgrade <pakagename> rpm -Uvh < pkg name>
# yum groupinstall <grpname> -----

LINUX SYSTEM ADMINISTRATION


BOOTING PROCESS of LINUX

1 POST=== POWER ON SELF TEST


to check the connectivity of necessary hardware.
2 BIOS===BASIC INPUT OUTPUT SYSTEM
to identify boot device
3 MBR====MASTER BOOT RECORD
it is first 512bytes of hard disk
it keeps the information of boot loader(GRUB)
4 GRUB===GRAND UNIFIED BOOT LOADER
GRUB is default boot loader for linux machine
it is loaded into memory(RAM) by MBR
it is capable of reading ext3 partition directly
GRUB is having 2 stages:-
1 STAGE
it loads second stage loader
2 STAGE
it reads /boot/grub/grub.conf file
and loads kernel(vmlinuz), and initrd
(Initial Ram Disk)
vmlinuz file is kernel of redhat linux
it is heart of operating system
it is responsible for establishing link between system
hardware and shell
then kernel loads initrd
initrd loads device drivers so that kernel can
communicate with hardware.
5 INIT===INITIALIZATION OF OTHER PROCESS
then kernel initialize first process that is init
init is responsible for running other process, like
auditd, syslog, portmap, cups, sshd, xinetd, vsftpd,
dhcpd, crond, atd, yum-updatesd, haldaemon.
all these deamons are inside /etc/init.d directory

6 Boot specific files:-


/etc/rc.d/rc.sysinit
/etc/rc.d/rc.local
/etc/inittab.... to define default runlevel
...to define prefdm(preffered display mangager)
.bashrc ..... inside user's home directory
..... to define user specific aliases
ex. alias vi=vim

7 Login prompt and after that if it is runlevel 5 then X11 server


is started and gdm/kdm/xdm will provide graphical desktop.
grub is the boot loader of linux which stands for [grand unified bootloader],
Configuration file of grub is /boot/grub/grub.conf or /etc/grub.conf.

To check startup & shutdown scripts.


# cd /etc/rc.d
# ls

To check the present runlevel.


# runlevel

To go to particular runlevel. runlevel 3


# init 3

To check the services in different runlevels.


# chkconfig --list | less
To view a particular service.
# chkconfig --list network

To switch on/off the service in a particular runlevel perminently.


# chkconfig --level 3 network off

To switch on/off the service in a multiple runlevels.


# chkconfig --level 345 network off
# chkconfig --level 345 network on

To start/stop the service temporarly.


# service network start
# service network restart
# service network stop
# service network reload

To add the virtual consoles[terminals].


# open vi /etc/inittab

Virtual Consoles ctrl+alt+f1 - ctrl+alt+f7.


/etc/inittab contains initdefault,virtual consoles,and runlevels.

Remote copy:-
scp---- secure copy this command is used to copy contents of remote system, we can take remote backup using
this command

syntax # scp -r <source> <target>


# scp -r 192.168.1.1:/home 192.168.1.2:/tmp
source pc target pc
this command will ask for root password of remote pc

Note:- this command is based on ssh

ssh is Secure Shell ssh is secure version on telnet it uses port no. 23 like telnet but the data, password sent using
ssh is secure because it encrypts data before sending using ssh we can SHARE REMOTE DESKTOP in text
mode. HOW?
# ssh <ip add of remote pc>
password of root:
To run a command on remote pc:-
# ssh <ip add of remote pc> <command>
# ssh 192.168.1.1 init 0
this command will shutdown 192.168.1.1 pc

FINDING & PROCESSING FILES. [UNIT - 15]


To search for a file.

Find command :-

# find / -name file1 -> will search for files having a name called file1 from / directory.

# find /home -name file1 -> will search for files having a name called file1 from /home

Directory.
# find / -name '*log*' -> will search all files having a word called log from / directory.

# find / -name *.log -> will search for all files having an extension called .log

# find / -user root -group root -> will search for all files having owner as 'root' and group as 'root'.

# find / -perm 622 -> will search for all files whose permissions are 622.

# find / -size 10k -> will search for all files having the size of 10 kb.

Locate command:-

Locate command will generally search for the database file called /var/lib/mlocate/mlocate.db
this is the database file which should b updated always.

To update the database.


# updatedb [command should b used]

# locate file1 will search for all files having a word called file1. may b [file1.txt or linuxfile1]

# locate -i file1 it will ignore case sensitive.


or
# slocate file1

# slocate -i file1

Searching the words in file using grep & egrep commands.


# grep linux file1 -> searches for linux word from file called file1.

# grep linux file1 file2 -> searches for linux word in 2 files [file1,file2]

# grep -i linux file1 -> searches for linux words [cap's & small letters] ignore case-sensitive.

# grep -n linux file1 -> searches for linux words with line numbers in a file1 file.

# grep -r linux /dir1 -> searches for linux words in all files existing in dir1 directory.
r stands for recursively.

egrep is used to search for multiple words in a file/files.

# egrep linux file1 -> searches for linux word in a file.

# egrep linux file2 file3 -> searches for linux words from 2 files [file2,file3].

# egrep 'linux | solaris| aix' file1 -> searches for 3 words in a file called file1.

# egrep -n linux file1 -> searches for a word called linux from file file1 with line numbers.
# egrep -i linux file1 -> searches for words called linux ignore case-sensitive.

# egrep -r linux /dir1 -> searches for linux words in all files existing under /dir1

LINUX SYSTEM ADMINISTRATION

Network Configuration:
ifconfig:-
Interface configuration(Network Interface Card)
it is used to set ip addr temporarily
it is also used to check ip addr

To set ip addr temporarily:-


# ifconfig eth0 192.168.1.X

To check ip add:-
# ifconfig eth0
it will display ip addr, hardware addr, subnet mask .....

netconfig:- network configuration is used to set ip addr,


subnet mask, preffered dns, default gateway

To set ip addr:
# netconfig ( press enter )
ok
192.168.1.X
255.255.255.0
enter
enter
ok
# service network restart
restart network service to update new ip addr

Note:- if netconfig is not working then pakage is not installed you can install this pakage by using rpm/yum.

# system-config-network
or
# neat( Network Administration Tool ) used to set ip addr in Graphical mode
or
# setup

When you assign ipaddress then it is stored in a file called ifcfg-eth0 which is in this directory.
# cd /etc/sysconfig/network-scripts
# ls
# cat ifcfg-eth0

ifup:- interface up
this command will enable lan card
# ifup eth0

ifdown:- interface down


this command will disable lan card
# ifdown eth0

ethtool:- used to check whether lan card is detected or not:


# ethtool eth0
yes

To assign Virtual Ips.


# netconfig --device eth0:1
# service network restart

To Assign Hostname:
hostname:- This command is used to set hostname temporarily and view hostname

To see hostname:-
# hostname (press enter)

To set hostname temporarily:-


# hostname sysX

To make hostname permanent:-


# vi /etc/hosts [also contains dns ipaddress]
192.168.1.X sysX
# vi /etc/sysconfig/network
HOSTNAME=sysX

To check log off and log in again and use 'hostname' command

To configure hostname:-
Hostname is pc name
it is used to identify the system on network
bydefault hostname is localhost.localdomain

To change hostname temprorily:-


# hostname <newname>

To see hostname:-
# hostname (press enter)

To change hostname permanently:-


open and edit configuration file:-
# vi /etc/sysconfig/network
HOSTNAME=sysX
#vi /etc/hosts
192.168.1.X sysX
logout and again login

NETWORK SERVICE & SECURITY ADMINISTRATION.

Network File Sharing Services


NFS - Network File system.

NFS server is used to share a dir between linux-linux or linux-unix machine


NFS SERVER:- system which share(export) its directory for network
NFS CLIENT:- system which mounts server's directory

NFS SERVER configuration :-

pakages:- nfs-utils*
portmap*

port no. 2049.... nfs


111.....portmap

configuration file /etc/exports

Services nfs
portmap

Daemon statd,mountd,lockd,nfsd

Steps:-
Server side:-
create share folder:-
# mkdir /share

give full permission:-


# chmod 777 /share

export(share) this directory:-


# vi /etc/exports
/share 192.168.1.0/255.255.255.0(rw,sync)

NOTE:-/share *(ro,async)

Restart service:-
# service portmap restart
# service nfs restart

Client side:-
mount server's dir on /mnt
# mount 192.168.1.10:/share /mnt

Check the contents:-


# cd /mnt
# ls

Note:- # showmount -e <ip add> this command is used to see what is shared on 'ip add'

To implement automounting on the client side.

Install The Package autofs.


# yum install autofs*
Open primarymap file.
# vi /etc/auto.master

/misc /etc/auto.misc --timeout=10

Open secondarymap file.


# vi /etc/auto.misc

linux -fstype=nfs 192.168.10.1:/nfsshare (nfs server ip & sharedfolder)

FTP SERVER
FILE TRANSFER PROTOCOL- used to upload and download files from ftpserver following are different ftp
server:-
wuftp washington university ftp
proftp
vsftp very secure ftp

FTP SERVER:- system which is having shared file/dir


FTP CLIENT:- system which is uploading/downloading file to server

Pakages:- vsftpd*.rpm
Port no. 20 for data transfer
21 for connection control
configuration file /etc/vsftpd/vsftpd.conf
/etc/vsftpd/user_list
/etc/vsftpd/ftpusers
services vsftpd
Daemon vsftpd

Steps:-
1. Check for installed pakages
# rpm -q vsftpd
if not installed then install it using nfs method
# mount 192.168.1.10:/var/ftp/pub /mnt
# cd /mnt
# cd /Server
# rpm -ivh vsftpd*

2. Create shared dir inside /var/ftp


# cd /var/ftp
# mkdir upload
# mkdir download
give write permission on upload directory
# chmod ugo+w upload
create some files in download directory
# cd download
# touch one two three

3. Open main configuration file:-


# vi /etc/vsftpd/vsftpd.conf
you can change any of the following options:-

line no.
12 anonymous_enable=YES
to allow anonymous user to log into ftp server user name for anonymous users are,
ftp anonymous
15 local_enable=YES
to allow local users that are created on server machine to log into ftp server from
client side example of local users is user1,user2,raj,ravi
27 anon_upload_enable=YES
to allow users to upload file to ftp server by default any user is not permitted to upload files to server, he
can only download
115 userlist_enable=YES

4. restart ftp service


# service vsftpd restart
or to reload service without shutting down use:-

# service vsftpd reload

Client Side configuraion:-


1. Connect to ftp server:-
# ftp 192.168.1.10 (ip addr of server)
it will ask for username, password default user is ftp/anonymous
default password is ftp/anonymous or you can also use any username that is created on server(local user)

2. download files go to download directory


ftp> cd download
ftp> get one

3. upload file go to upload directory


ftp> cd upload
ftp> put localfilename

4. disconnect ftp server


ftp> bye

Note:- if local_enable=YES is given in vsftpd.conf file it means local users of server can also login from client
side
ex. of local users are user1,user2, and even root but bydefault root user is NOT allowed to login from
network so to deny any local user to login into ftp server, enter its name in ftpusers file or user_list file,
and reload the service

To access FTP Server in graphical mode:- open web browser( mozila filefox ) type addr
ftp://<ip addr of ftp server>
like
ftp://192.168.1.10(press enter)

SAMBA SERVER
Windows OS share file/folders using SMB(server message block) protocol
Windows OS share file/folder over tcp/ip by using CIFS(common internet file sharing) method
Linux uses SMBD/NMBD to share file and folders with windows machine for this we have to configure samba
server on linux machine

pakages samba,samba-common,samba-client,swat
portno. 137 NetBIOS name service
138 NetBIOS datagram service
139 NetBIOS session service
configuration file /etc/samba/smb.conf and /etc/samba/smbpasswd
service smb
Daemon smbd, nmbd

Server side configuration:-


1. install the pakages if not already installed
# yum install samba*

2. open main configuration file


# vi /etc/samba/smb.conf

go to last line
copy last 8 lines(press yy)
paste at the bottom of file (press p)
now edit last 8 lines by removing ;(comment)
[myshare] .......... this is share name
comment = This is CMS shared directory .... you can type any comment
path = /var/share ................ this is path of shared directory
valid users = user1 ............... space separated list of users
public = no .................... to make folder visible to all
writable = yes .................. to give write permission on folder
browseable = yes .... to see icon of shared folder in my'network places'

3. create your shared dirctory


# cd /var
# mkdir share
# cd share
# touch file1 file2 file3

4. start the service


# service smb restart

Client Side configuration:-


There are 2 methods in which we can access samba server from linux client
NFS:-
# mount //<ip add of samba server>/<share name> <mountpt> -o
username=smbusername
# mount //192.168.1.10/myshare /mnt -o username=user1

FTP method:-
# smbclient //<ip add of server>/<share name> -U username
# smbclient //192.168.1.10/myshare -U user1
smb>ls
smb>get file1
smb>put anyfile
smb>quit

Note :- on samba server you must create user and provide smb password
# useradd user1
# smbpasswd -a user1
*****
*****

To access samba server in graphical mode in linux go to


places----> Network Servers--------> system name
here you will find shared folder

To access samba server from windows machine:-


go to my network places
entire network..... find linux machine icon
here you will find shared folder

PROCESS MANAGEMENT

To manage different process:- system identifies any process by its process id(PID)
To see pid of a running process:-
# service vsftpd status
vsftpd is runnig (3954).......
(this is pid)
or
# ps -ef | grep vsftpd
Note:- PID for init is always 1

To start any process(daemon)


# service vsftpd start

To stop a process
# service vsftpd stop

To restart any process


# service vsftpd restart

To reload the process


# service vsftpd reload

When we restart the service is shutdown and again started, it takes time when we reload service only changes are
reloaded, it is fast

If any service is not responding then we can use kill command to abnormally terminate that process:-
# kill <pid of that process>
# kill 3954
note :- first check the pid of process, then kill it.

To make any process to run permanently in any runlevel?


chkconfig command is used
like,
# chkconfig vsftpd on
to make vsftpd run bydefault in all possible runlevels
# chkconfig --level 35 vsftpd on
to make vsftpd run bydefault in runlevel 3 and 5 only
# chkconfig --list | grep vsftpd
to see present on/off status of vsftpd service
# chkconfig vsftpd off
to turnoff vsftpd service in all possible runlevels

NETWORK SERVICE & SECURITY ADMINISTRATION.

DHCP---- DYNAMIC HOST CONFIGURATION PROTOCOL

pakage dhcp-3.0.5-3.el5
configuration file /etc/dhcpd.conf
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
/var/lib/dhcpd/dhcpd.leases

port no. 67 bootp server


68 bootp client
service dhcpd
Daemon dhcpd

To configure dhcp server:- check for dhcp pakage install:-


# rpm -q dhcp

if it is not installed then install it:-


# yum install dhcp*

now copy sample file to main configuration file:-


# cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcpd.conf
source sample file target main file

edit main configuration file


# vi /etc/dhcpd.conf

define the subnet with its class if ip addr


go to line no. 21
range dynamic-bootp 192.168.1.128 192.168.1.254;
start range end range
save and exit

Restart the service:-


# service dhcpd restart

On client side issue following command to obtain ip addr automatically

From dhcp server:-


# dhclient
or
# netconfig
Yes * use dynamic IP configuration[bootp/dhcp]

Then restart the service


# service network restart
or
user graphical method

# system-config-network
or
# neat

Check the new ip addr


# ifconfig eth0

To give DHCP reservation:- We can bind any MAC addr to a IP addr by using dhcp ip address reservation first
we have to find out the mac addr of client:-
# ifconfig it will show hardware addr

now on dhcp server open main configuration file:-


# vi /etc/dhcpd.conf
Modify following lines:-

hardware ethernet 12:34:56:78:AB:CD;


fixed-address 192.168.1.150;

save and exit, then restart dhcp service

Note:- if you want to see mac addr of client from server machine then
# ping 192.168.1.X
# arp -a (press enter)

NETWORK SERVICE & SECURITY ADMINISTRATION.


DNS--- Domain Name Server/Service

DNS server is used to resolve Hostname to IP addr and IP addr to Hostname. DNS server maintains Zone files.
Zonefiles are database which contains information about different server and thier corresponding ip addr
there are two type of zone database files:-

Forward Lookup Zone file:-


This file contain Hostname and corresponding IP add
It is used in Hostname to Ip addr resolution

Reverse Lookup Zone file:-


This file contain IP addr and corresponding Hostname
It is used in Ip addr to hostname resolution

When Hostname is added to Domain name it becomes FQDN


sys10.cms.com.
sys10-- hostname
cms--domain name
.com--top level domain
. root domain

A DNS server will have following records:-

SOA record Start Of Authority record


First record created when a dns is configured
Used for defining replication between DNS and Backup DNS

A Address record
Used to show it Ip Addr of any hostname
PTR Pointer record
Used to show hostname of any IP Addr

NS Name Server record


Used to identify nameserver(dns server)

CNAME Canonical Name record


Used to provide alias/duplicate names to server

MX Mail Exchange record


Used to identify Mail server

There are two types of DNS servers:-


Master and Slave
Master is having all zone records; its SOA no. is always greater than Slave.
Slave is having backup of zone records of Master server, when any new
entry is entered in master server's zone file, it is automatically
replicated to slave, its SOA no. is always smaller than Master

To configure Master DNS in Linux:-


pakages bind* caching-nameserver*
portno. 53
main conf file /etc/named.rfc1912.zone
/etc/named.caching-nameserver.conf
Service named
Daemon named

Note:- DNS works on BIND(Berkely Internet Name Domain) version 9 In RHEL we call bind as
named(nameserver daemon)

Steps:-
check ip addr:-
# ifconfig
if it is not correct set ip addr
# neat
or
# netconfig
restart network service:-
# service network restart

Check hostname
# hostname
if it is not correct then set hostname
# hostname sysX.cms.com
make it permanent:-
# vi /etc/hosts
192.168.1.X sysX.cms.com sysX
# vi /etc/sysconfig/network
hostname=sysX.cms.com
now logout and login again to check hostname

check for pakage:-


# yum list installed bind*
if it is not installed, then install it:
# yum install cach*
# yum install bind*
total 9 pakages

edit configuration files:-


# vi /etc/named.caching-nameserver.conf

listen-on port 53 { 127.0.0.1;192.168.1.10; }; [line 15]

allow-query { localhost;192.168.1.0/24; }; [line 23]

match-clients { localhost;192.168.1.0/24; }; [line 32]

# vi /etc/named.rfc1912.zones

copy line no. 21 to 31 ( 11 lines) paste it below line no. 31 edit these lines:

zone "cms.com" IN {
type master;
file "cms.for";
};

zone "1.168.192.in-addr.arpa" IN {
type master;
file "cms.rev";
};

change directory:-
# cd /var/named/chroot/var/named

copy and rename file localhost.zone


# cp -p localhost.zone cms.for

copy and rename file named.local


# cp -p named.local cms.rev

modify zone database file:-


# vi cms.for

$TTL 86400
@ IN SOA sys10.cms.com. root.cms.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum

IN NS sys10.cms.com.
IN A 127.0.0.1
sys10.cms.com. IN A 192.168.1.10
sys9.cms.com. IN A 192.168.1.9
sys2.cms.com. IN A 192.168.1.2

# vi cms.rev
$TTL 86400
@ IN SOA sys10.cms.com. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS sys10.cms.com.
10 IN PTR sys10.cms.com.
9 IN PTR sys9.cms.com.
2 IN PTR sys2.cms.com.

open resolv.conf file and enter the ip addr of dns server this file is similar to prefered dns of windows os
# vi /etc/resolv.conf
nameserver 192.168.1.10

Now restart service:-


# service named restart

Client Side Configuration:-


Provide the ip addr of dns server in relov.conf file(preffered dns)
# vi /etc/resolv.conf
nameserver 192.168.1.10

query dns server and check the output:- we can check dns server by two commands:-
nslookup and dig
# nslookup

enter the server name the output will be ip addr of server


# dig sys10.cms.com.
or
# dig -x 192.168.1.10

KICKSTART INSTALLATION
It is similar to RIS/Unattended installation of Windows os By using kickstart installation we can install linux on
remote machine all the installation files are present on kickstart server client is booted from linux bootable cd(cd
no.1) and then it will take installation files from server along with answer file. Answer file is a file generated on
kickstart server which provides all answers of questions which are asked during installation process.

Requirements for kickstart server:-


all the files of RHEL cd/dvd
dhcp server
kickstart answer file
nfs/ftp server

Requirements for kickstart client:-


first cd/dvd of RHEL
To configure kickstart server:- first configure your system as dhcp server, providing valid ip addr range
Method 1:-
if we are using 5 cds then, copy all the contents of 1st cd to
/var/ftp/pub
then copy contents of Server dir of remaining cds to /var/ftp/pub/Server

Method 2:-
if we are using 1dvd then simply copy complete dvd to /var/ftp/pub now configure nfs server to share this
location
# vi /etc/exports
/var/ftp/pub *(rw,sync)
# service nfs restart
check it
# showmount -e
or

now configure ftp server to share this location just install the vsftpd package and configuration is completed
because bydefault ftp server shares /var/ftp/pub location itself
# service vsftpd restart

Now create kickstart file:-


for this we need a package system-config-kickstart if this package is not installed then install it first form
cd/dvd/yum then
# system-config-kickstart(press enter)

it will open a wizard configure the options, after configuring options you have to add pakage list manually to the
kickstart file give following command:-
# yum grouplist >> /var/ftp/pub/ks.cfg

it will transfer all group names to end of kickstart file now modify that file
# vi /var/ftp/pub/ks.cfg

at the bottom write


%pakages
@ editors
@ Java Development
....
....
then save the file give executable permission to this file:-
# chmod +x /var/ftp/pub/ks.cfg

so that any client can execute this file when needed

How to configure kickstart client:-


boot the system by using 1cd
you will get boot prompt
boot:
here you can use any method nfs/ftp
boot: linux ks=nfs:192.168.1.10:/var/ftp/pub/ks.cfg
or
boot: linux ks=ftp://192.168.1.10/pub/ks.cfg

installation starts from server........


To perform network installation:-
configure nfs/ftp server with dump of all cds in /var/ftp/pub
on the client side boot with cd
boot: linux askmethod
it will ask for type of installation
nfs
ftp
cdrom
choose nfs and specify ip addr of nfs server and dir(/var/ftp/pub)
or
choose ftp and specify ip addr of ftp server and dir(/var/ftp/pub)
installation starts from server........

MAIL SERVER

MAIL server uses MTA( mail transfer agent) like sendmail, qmail, postfix squirrelmail, smail etc
MTA uses SMTP protocol to send and receive mail at port no. 25

on the client side mail client software like mutt(Mutt Mail User agenT), thunderbird, evolution, and webmail are
used to send and receive mail.

To configure Mail server (sendmail):-

pakages sendmail* m4*


portno. 25 SMTP
110 POP3
143 IMAP
config file /etc/mail/sendmail.mc
/etc/mail/sendmail.cf
service sendmail
daemon sendmail

Server side configuration:-


Install the pakages if not already installed
# yum remove sendmail*
# yum install sendmail*

open main configuration file:-


# vi /etc/mail/sendmail.mc

edit following line no.


116 add "# dnl" at the beginning of line
155 add "# dnl" at the beginning of line
(delete to new line)

Compile this file and send its contents to sendmail.cf file


# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

note: this command will not show any output on screen m4 is a macro compiler which is used to compile
sendmail.mc file

start service
# service sendmail restart

set hostname ......... mail.cms.com


set ip addr

On Client Side:-
set hostname............. sysX.cms.com
set ip addr
set ip addr of dns server in resolv.conf file
# vi /etc/resolv.conf
nameserver 192.168.1.X

DNS Server configuration:-


In dns server the only change is in forward lookup zone file:-
add following entry:-

IN MX 5 mail.cms.com.----(to define mail server)


192.168.1.X IN A mail.cms.com.----(to define its ip addr)

now start mailing from one user to other


root user is mailing to user1:-
# mail user1
Subjet: hi
skldjf;lasjkdf
lkjdslkafja;sldjkf
these are the contents of mail
type it and then press ctrl+d
Cc: (press enter)

mail is sent to user1

To check mail: Login as different user, user1


$ mutt (press enter)
or
$ mail (press enter)

To configure squirrel mail( graphical mode )


Install following pakages:
squirrelmail*, dovecot*, php*, perl*, httpd*, curl*, cyrus-imapd*,
and sendmail* if it is not already installed

Restart following services:


service httpd restart
service dovecot restart
service cyrus-imapd restart
service saslauthd restart
service sendmail restart

Then you can access mail in graphical mode using webmail( mail client )
open mozila firefox web browser
type following addr
http://<name of mail server>/webmail
like
http://mail.rhce.com/webmail
it will ask for username and password
then you can access your mail

WEB SERVER(APACHE SERVER)

There are many web servers like IIS(windows), apache, sunone, AOL, etc most popular web server is Apache, it
works on both windows and linux more than 68% of total web servers of world are configured on Apache

Note:- go to www.netcraft.com
Type url of any web server, and search, it will show you on what kind of server that web site is working, like
www.way2sms.com is working on Apache 2.0 installed on Fedora8 goto ip2location.com
type url of any web server, and search, it will show you the geographical location of that web server, like
www.google.com is in US, california, street...., contact person... www.whois.net...... you can find who is
maintaining that server, complete contact information is displayed with ph. no. too use nslookup command
to see ip addr of any dns server.

To configure web server:-


pakages httpd*(httpd,httpd-manaul,httpd-devel)
port no. 80
conf file /etc/httpd/conf/httpd.conf
service httpd
daemon httpd

Steps to configure web server:- install the packages if not already installed:-
# yum install httpd*

open main configuration file:-


# vi /etc/httpd/conf/httpd.conf

modify following lines:-


250 ServerAdmin [email protected]
264 ServerName www.cms.com.:80
280 DocumentRoot "/var/www/html"
134 Listen 80
390 DirectoryIndex index.html

line 250 is for providing contact user information if your web server is not working then client will
contact to this person
line 264 is for provding url for your web site, it may be different from your system name
like here system name is web.cms.com but website url is www.cms.com. and it works on port no.
80
line 280 is for defining DocumentRoot this is the location where your html files are kept
you can change this location
134 Listen 80 this is to define portno. that this web server listens
390 DirectoryIndex discribes the name of first page of your website
if first page name is different then change this option, by
default it is index.html file which is created inside
/var/www/html(DocumentRoot)

After editing configuration file you have to create website(index page)


# cd /var/www/html
# vi index.html
<html>
<title> This is cms.com web site </title>
<body> <h1> This is home page of cms computers ltd. </h1>
<h7> This page is created by YOURNAME </h7>
</body>
</html>

Now restart the service


# service httpd restart

Now specify your dns server:


# vi /etc/resolv.conf
nameserver 192.168.1.X

Check it
# dig -x 192.168.1.X

DNS server side configuration:-


on the dns server there is only one change
open FLZ file and add the entry of web server;

web.cms.com. IN A 192.168.1.Y----to define webserver


www.cms.com. IN CNAME web.cms.com.---to define its aliasname

# service named restart

Client side configuration:-


define your preffered dns:-
# vi /etc/resolv.conf
nameserver 192.168.1.X

now open web browser and open website www.cms.com or web.cms.com

NIS..... Network Information Services

It is a centralized directory service through which we can share resources like users, groups, mails over the
network It is similar to LDAP( Light Weight Directory Access Protocol )
Linux machine uses NIS, Solaris machine also uses NIS+

To configure NIS server


pakages ypserve*, ypbind*, yp-tools*
ypserve is for NIS server only, not client side
ypbind and yp-tools are required on client side
ypbind package is used to bind nis-client with server
portno. randomly assigned by portmap service
to see portno. use command--- (rpcinfo -p)
conf file /var/yp/Makefile
/etc/sysconfig/network
service yppasswdd, ypserv, portmap
daemon yppasswdd
Steps:-
1. install the package ( remove it if it is already installed )
# yum remove yp*
# yum install yp*

2. set nis domain name temporarily


# nisdomainname cms.com
check it
# nisdomainname (press enter)

3. set nis domain name permanently


# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=sysX.cms.com
NISDOMAIN=cms.com

4. edit main conf file


# vi /var/yp/Makefile
line no. 23
NOPUSH=TRUE
it means that there is no slave nis server
line no. 109
all: passwd group....... mail\
list of database which are centralized on network

5. create master nis server's database


# /usr/lib/yp/ypinit -m
it will ask hostname: (press ctrl + d)
then it will ask (y/n) (press y)

6. create some users:-


# useradd nisuser1
# passwd nisuser1

7. share your home dir using nfs server:


# vi /etc/exports
/home *(rw,sync)
# service nfs restart
# showmount -e

Configuring NIS-Client:
1. set nisdomain name
# nisdomainname cms.com
# vi /etc/sysconfig/network
NISDOMAIN=cms.com

2. mount home dir from server over client's home dir


# mount 192.168.1.X:/home /home

3. specify the type of authorization:


# authconfig-tui
* nis
ok
4. check your nis server conectivity
# ypwhich
it will show nis domain name in output

5. logout and login with nisuser1


now whatever data you create on client machine's home dir
will be stored on nis-server's home dir
it means /home dir is centralized

SHELL SCRIPTING
# grep 'root' /etc/passwd
# date --help | grep year
# cut -d: -f1 /etc/passwd
# grep bash /etc/passwd | sort
# cut -d: -f7 /etc/passwd | sort | uniq

First shell script:-


# vi first.sh
#/bin/bash
echo " this is my first shell script "
echo " Enter your First name:.......... "
read firstname
echo " Enter your Last name:........... "
read lastname
echo " Your Full Name Is :............. $firstname $lastname "

save this file and give execute permission now to run this shell script :
# ./first.sh
or
# bash first.sh

second shell script:-

# vi second.sh
#/bin/bash
echo "enter yes or no"
read ans
ans="$(echo $ans | tr 'A-Z' 'a-z')"
echo "$ans"

save the file and give execute permission now run shell script:
# ./second.sh

Note:- tr means translate character


used to translate characters
sed means Stream Editor used to edit output, without effecting original file

# vi pets
hi this is my pet animals file
i have a lot of pet animals
like
cat dog parrot and rabbit
but my fav. is cat
my cat is very soft
cat is white in color
dog is black in color
save the file and exit

# sed 's/cat/dog/' pets


this command will show edited output
all cat will be converted to dog in output
but the file will remain uneffected

# grep '^root:' /etc/passwd


To filter info of root user only
echo " this is date and time $(date)"
echo "pwd is : $(pwd)"
if [ -d $1 ]
then
echo " $1 is a dir"
else
if [ -f $1 ]
then
more $1
fi
fi

capital=dehli
echo "what is capital of india"
read cap
if [ $cap != $capital ]
then
echo "wrong"
exit 1
else
echo " correct "
fi

echo " enter ur weight"


read wt
if [ $wt -lt 500 ]
then
echo " u r eligible for next fight"
else
echo " u r not eligible for next fight"

read a
read b
c=`expr $a + $b`
echo $c

for x in 10 20 30
do
echo $x
done
cat > animal
cat
dog
fly
goat
lion

for i in `cat animal`


do
echo " $i"
done

*****************
/etc/fstab and /etc/mtab files

FSTAB---- File System Table file stores information about partition, file type, mount point, and mounting
options system reads this file at the time of booting, and mounts the partitions which are listed in this file

common contents of /etc/fstab are:

LABEL=/ / ext3 defaults 11


LABEL=/boot /boot ext3 defaults 12
LABEL=/home /home ext3 defaults 12
LABEL=/usr /usr ext3 defaults 12
LABEL=/var /var ext3 defaults 12
LABEL=SWAP-hda7 swap swap defaults 00
/dev/hda9 /mnt ext3 defaults 00
label of partition mnt pt filesystem options dump fsck

To see label of partition:-


# e2label /dev/hda2
/boot........ this is the label of /dev/hda2 partition

/etc/mtab..... MOUNT TABLE


This file provides system the information about mounted partitions " mount " command uses the contents of this
file

Note:- When we mount any partition by using 'mount' command, then /etc/mtab file is updated and new entry is
added but this type of mounting is temporary after rebooting the system it is automatically unmounted so to
mount a partition permanently we use /etc/fstab file we have to manually edit this file to mount a partition
permanently

ex.
a new partition is created /dev/hda9, it is formatted to mount it temporarily,
# mount /dev/hda9 /mnt

to mount it permanently,
# vi /etc/fstab

at the bottom of this file type following line


/dev/hda9 /mnt ext3 defaults 0 0
or you can change mounting options
/dev/hda9 /mnt ext3 defaults,usrquota 1 2

VIRTUALIZATION

Red Hat Virtualization can host multiple guest operating systems. Each guest operating system runs in its own
domain. Each guest operating systems handles its own applications.

Virtualization is of two types:


Full virtualization or paravirtualization.

Full virtualization provides total abstraction of the underlying physical system and creates a new virtual system
in which the guest operating systems can run. No modifications are needed in the guest OS or application (the
guest OS or application is not aware of the virtualized environment and runs normally).

Paravirualization requires user modification of the guest operating systems that run on the virtual machines(these
guest operating systems are aware that they are running on a virtual machine)

The first domain, known as domain0 (dom0), is automatically created when you boot the system. Domain0 will
host Guest OS(Domain1).

The hypervisor (Red Hat's Virtual Machine Monitor) is a virtualization platform that allows multiple operating
systems to run on a single host simultaneously within a full virtualization environment. A guest is an operating
system (OS) that runs on a virtual machine in addition to
the host or main OS.

Hardware Requirements for Virtualization:-


Intel VT-x or AMD-V Pacifica and Vanderpool technology for full and paravirtualization.
For full virtualization your system must support PAE (physical Address Extension), by using PAE technology we
can increase the amount of physical or virtual memory available to user applications.

Celeron “Pentium II " Pentium III " Pentium IV " Xeon " AMD Athlon " AMD Duron for para virtualization.

Installing virtualization:-
yum install <pakage name>

pakages are:
kernel-xen
xen
xen-libs
virt-managerz
gnome-applet-vm
libvirt

Booting a guest domain we can use virsh or xm commands


# xm create -c guestdomainname

You can make it permanent:


# chkconfig xendomains on

Connect to a domian:
# xm console domain-id
Create a domain:
# xm create -c newdomainname

Saving a domain:
# xm save domain-id

Destroy a domain:
# xm destroy domain-id

Shutdown a domain:
# xm shutdown domain-id

Restore a domain:
# xm restore domain-id

Suspend a domain:
# xm suspend domain-id

Resume a domain:
# xm resume domain-id

reboot a domain:
# xm reboot domain-id

pause a domain:
# xm pause domain-id

unpause a domain:
# xm unpause domain-id

Display domain states:


# xm list domain-id

Display uptime:
# xm uptime domain-id

Display domain information:


# xm domain info

Managing Virtual Machines in GUI mode: by using Virtual Machine Manager

The Virtual Machine Manager (VMM) gives you a graphical view of the virtual machines on your system. You
can use VMM to define both para-virtual and full virtual machines.

Open connection window:


go to applications ->system tools -> vitrual machince manager
Select local xen host
Click on connect

VMM window opens; here you can see domain0 is running


How to create a new virtual machine:

Requirements:
First create a new partition on Domain0 host (ex. /dev/hda9) then configure your nfs install server
192.168.1.10(share dir is /var/ftp/pub) Then create a kickstart server 192.168.1.10(save file in /var/ftp/pub)

Click on new in VMM window


->forward
->enter the name of virtual server(remember this name) and click forward
->specify the type of virtualization(paravirtualization) and click forward
->enter intall media url........ nfs:192.168.1.10:/var/ftp/pub
Enter kickstart url........... nfs:192.168.1.10:/var/ftp/pub/ks.cfg
Click on forward
->specify the partition name
partition..... /dev/hda9
click on forward
->set max. memory for virtual machine( dont modify anything )
click on forward
->start creating virtual machine.............

After virtual machine is created you can view graphical mode in virtual machine console window
To start your guest machine:-
# xm create -c guestname
Then right click on guest in virtual machine manager and chose open to open virtual console

Note:- you can also use "virt-install" command to create a virtual machine in text mode
PROXY SERVER

Proxy server is used to provide following three services:


Caching Server
Securing web access
Internet connection sharing

To configure Proxy server:-


pakage squid*
portno. 3128
conf file /etc/squid/squid.conf
service squid
daemon squid

Server side configuration:

Install the pakage:


# yum install squid*

Open main configuration file:


# vi /etc/squid/squid.conf

line no.
73 http_port 3128
remove the hash from line no. 993
cache_dir ufs /var/spool/squid 100 16 256

define acl before line no. 2394


like
acl neighbours src 192.168.10.0/24
acl denydomain dstdomain .yahoo.com
acl denykeyword url_regex http://www.google.co.in

After defining all acl define allow/deny policy for each of them below line no. 2500 like
http_access deny denydomain
http_access deny denykeyword
or
http_access deny denydomain denykeyword
http_access allow neighbours

save & exit

restart the service


# service squid restart

Client side configuration:


open mozilla fire fox
edit-> pref -> connections -> manual proxy ->
ip addr of proxy server and port no.(3128)
use same proxy server for all services
close
try to access different web sites.......

or for text mode


open elinks
press escape
go to setup menu
options manager
select protocols(press space to expand)
select http (press space to expand)
select proxy configuration(press space to expand)
select host and port-number option and edit
now specify ip addr of proxy server and portno.
save and exit

For windows clients:


open internet explorer
tools-> internet options-> connections -> lan connections ->
specify proxy server's ip addr and portno

TROUBLESHOOTING
To Break root password:-

1. restart system
# init 6
2. go to single user mode
at the grub boot screen select Redhat and press 'a'
then give space and type '1'
then press enter
3. at the shell prompt change the root password
sh# passwd root
******
******
4. restart the system
# init 6

What is GRUB?
GRand Unified Bootloader is the default boot loader program for RHEL5
configuration file for GRUB is /boot/grub/grub.conf

its contents are:-

default=0 ........default os is Redhat


timeout=5 ........time to change os
splashimage=(hd0,1)/grub/splash.xpm.gz ........grahical screen
hiddenmenu ........hides os options
title Red Hat Enterprise Linux Server (2.6.18-8.el5) ...... name of 1st os
root (hd0,1) ..... partition
kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/1 rhgb quiet ...kernel
initrd /initrd-2.6.18-8.el5.img ..... Initial RamDisk
title Other ....... name of 2nd os
rootnoverify (hd0,0) | boot info
chainloader +1 | of 2nd os(windows)
To set GRUB password:-
1. # grub-md5-crypt >> /boot/grub/grub.conf
now type password for two times
2. # vi /boot/grub/grub.conf
remove last 2 lines:-
password
retype password
cut last line where encrypted password is written.
paste it below ' hiddenmenu '
ex.:-
hiddenmenu
password --md5 $123abc.xyz45$6$pqr.
title Red Hat Enter.....
3. save and exit file, restart system and verify.

To remove GRUB password:-


1. boot from RHEL 1st cd
2. at the boot prompt type 'linux rescue' and press enter
boot: linux rescue
3. keyboard ...... ok
4. language ..... ok
5. network support .... no
6. rescue ......... continue
7. shell will appear type following command:-
sh# chroot /mnt/sysimage
8. open grub configuration file and remove password line:-
sh# vi /boot/grub/grub.conf
delete line below 'hiddenmenu'
save and exit
9. remove cd and restart
What is Autofs:
Autofs is a kernel option which allows you to automatically mount filesystems when you access them, and
automatically unmount them when you are done using them.

I like Autofs because it's:


• flexible--it can automatically mount any filesystem you can mount manually, including network
shares
• simple--configuration file syntax is similar to fstab
• configurable--timeouts and other facets of filesystem mounting are completely configurable
• scriptable--any filesystem configuration file can be replaced by a script
Installing Autofs:
1.Configure the kernel
2.Install Autofs software
3.Configure Autofs
4.Script Autofs (optional)

Configure autofs:
1.Create /etc/auto.master
1. Create /etc/auto.* files
2. Restart autofs
3. Access a configured directory

You might also like