Sie sind auf Seite 1von 27

Session 1 Intro Unix

Introduction to unix
User Interface
Pros & Cons
Unix File System
Directory Hierarchy Layout
Getting Started



History
In order to understand the popularity of Unix, one needs to know about its history.
Unix was originally developed as a multitasking system for minicomputers and
mainframes. Development started at Bell Labs in 1969 througout the 1970s, with
the following goals in mind:
the system had to be simple and elegant
it had to be written in a high-level language rather than in assembly code
it should allow code recycling (re-use of code)
Typical vendor systems at that time were extremely large and all written in system
specific code, whereas Unix uses only a small amount of system specific code (it's
called the kernel). The Unix development group worked primarily in this higher level
programming language to develop the operating system on top of the kernel, thus
allowing easy portability to a wide range of hardware platforms: the only piece of
code that really needed to be adapted in order for the system to run on a different
platform, was the kernel.
These portability and system programming issues have caused many hardware
and software vendors to choose Unix in one flavour or another as an alternative to
their own proprietary systems. Unix makes their applications more portable and
provides vendor-independent networking, allowing users to easily interact with
systems from different vendors.
The user interface

Unix is a good operating system for experienced users and programmers,
because it was designed by such people.
Everything a good programmer needs is present, but not much of anything
else. A great example are the Unix "manpages" or manual pages. They are
included with every system and completely cross-referenced, but you'll find
extremely few tutorials or "getting started" guides. Experienced users find
them very convenient, but the manpages can be overwhelming for a
beginning Unix user.

During the last decennium, the user interface has improved tremenduously: a
windowing system was added and grapghical user interfaces (GUIs) were
being developed to easily administer a wide range of programs.

Especially in the freely available Linux distibutions that emerged during the
early 1990s as a response to the wide range of proprietary Unix systems,
extreme effort has been put in developping a more userfriendly system.

Pros & Cons
Advantages:
already exists for over 30 years
available for almost any hardware platform
made to keep on running
secure and versatile
scalable
Disadvantages:
many different dialects
on proprietary systems: bundling and system specific
implementation of commands/packages
not user-friendly, confusing for beginners
proprietary hardware is expensive

Introduction to the Unix File
System

Functions of an operating system
There are two things everybody knows about an operating system:
it provides an interface between the user and the system resources
it's a set of programs controlling all computer tasks

In Unix, the operating system consists of files, arranged in a tree
structure. Everything is a file: programs, directories, images, texts,
services etc. are all files. Sometimes a file with a special attribute, but a
file nevertheless.
There are 3 major types of files
Kernel
Shell
File system


The Kernel
Acts as an intermediary between applications running on a
computer and the hardware inside the computer. It controls
physical and virtual memory, schedules processes, and starts
and stops daemons. All commands interact with the kernel.
Kernel is a major part of operating system.
Kernels are classified on the basis of their architecture as
Monolithic and Micro kernel .
Monolithic : Uses a single big kernel. All changes done requires
a relinking of kernel followed with a reboot of system. Eg:- SCO
unix and HP-UX
Micro kernel : Consists of a core kernel with a set of loadable
kernel modules.The kernel modules are loaded on demand and
the kernel is relinked dynamically without a reboot.It is possible
to load/unload the kernel modules dynamically without affecting
system performance. This imparts Plug-n-play feature in
the OS. Eg : Solaris and Linux
Shell
The shell is a wrapper to prevent painstaking user interaction with the underlying
hardware. It translates user input to a form the kernel can understand by calling on to
the suitable executable (program) for the user's command and passing this to the
kernel. Supposing Unix were a car, then the shell would be the steering wheel. In the
same picture, the kernel would be the engine.
The shell allows the user to interactively use the system, it provides means of
customizing your environment and programming (cfr. batch-files in DOS).
There are a couple of different types of shells, the most important are:
sh or Bourne shell: the standard shell, the most compact but also the simpelest
ksh or Korn Shell: superset of the common shell, lets you edit the command line,
usually using the vi editor, which makes it rather confusing for new users.
csh or C-shell: scripting and executing commands is done using C programming
language syntax.
tcsh or turbo C shell: a superset of csh allowing easier scripting
bash or Bourne again shell: the GNU shell, allowing flexible and intuitive user
interaction. As of this writing, bash is the most advanced shell and is the most
recommendable shell for beginning users.

The type of shell a user gets is determined in /etc/passwd, the database containing
user login information. Some users (e.g. POP3 users, database users) get no shell or
a shell that doesn't exist in order to prevent them from connecting directly to a system.
File system
A File system is defined as a Heirarchy of Files and Directories
. Data on a Solaris system is stored in a hierarchical fashion
on the file system. Organizing data in this way makes it easy to
locate and group related operating system control files and user
information.
Mounting a file system : The process of making ( or attaching )
a file system as part of a unix device tree. After mounting you
can access a file system relative to a mount point.
File systems are classified as Disk based, Distributed or
Pseudo file systems .
Disk based : Exists in hard disk. Eg: ufs , vxfs
Distributed : Network based .Available on the network eg: NFS
Psuedo : RAM based . Exists in physical RAM.eg: tmpfs ,
procfs, fdfs

Home directory vs. working
directory
When you log on to the system, it places you in your home
directory as a start, which is defined in the /etc/passwd file. It
is your unique place in the filesystem and contains files you
use all the time when logging in. You can make your own files
here, edit or delete them, create and remove directories, this
is your room and you're the boss in here.
Your working directory, on the other hand, can be anything. At
the start of every session the working directory and the home
directory are the same. As soon as you change to another
directory, that directory becomes your working directory, and
unless you tell the system otherwise, all commands that you
enter will apply to the working directory.

Working directory is called current or present working
directory on some systems.

Intro of Unix Directory Hierarchy
The directories on a Unix system are conveniently ordered into a tree structure.
The parent directory of the tree is called the "root" directory and is written as a
forward slash (/).

The root contains the entire filesystem. Some of the most important directories are listed below:
/ or /root on some systems: root's homedirectory. Keep in mind that the root of a filesystem is /,
not /root.
/bin: binary files (program files)
/boot or /kernel: information for booting the system, directory for storing (the) kernel(s).
/dev: entries for all devices. Some systems use /devices and /dev, where /dev contains links to
entries in /devices.
/etc: system configuration files, startup and shutdown procedures.
/home: (or /export/home or /users on some systems): user homedirectories
/lib: library files
/net: entries for other (networked) systems
/opt: third party software (used to be /usr/local), unbundled software
/proc: a pseudo-filesystem storing information about processes and devices
/sbin: system binaries
/tmp: temporary space, required on every Unix system
/usr: user binaries and libraries, manuals and docs
/var: variable files
Swap: virtual memory on a hard disk allowing the system to use more memory than the amount
fysically available

Getting started
In order to be able to log on to a Unix system, you need to get a login, a and a password, your
loginname and related userid need to be assigned to one or more groups, you need a
homedirectory and, in order to do anything directly on the system, a shell.
On most sites, there will be more than one Unix server to connect to, so you may also want to know
the hostname of your system.
Connecting to a system
Logging on to a Unix server can be done in a number of ways:
locally on the console, in text mode (some systems offer virtual consoles)
locally in graphical mode, using X
using remote display of X
from another Unix host, using telnet or ssh (Secure SHell)
from an MS Windows, Mac or other PC system using a terminal emulation program such as the
MS Windows telnet program, CRT, F-secure, MacTelnet (former NCSA Telnet), putty, ...
Whatever method you use, you always have to authenticate to the system. Some form of a login
prompt will be displayed, enter your username here (you got it from your system administrator, it may
be called loginname, userID, username or login). After that, the system will ask your password.
When you log in using some form of textmode, the system will display a "message of the day" or
motd, most of the time some information on the system you're connecting to, such as the operating
system version, kernel information, vendor etc. Sometimes it will display a fortune cookie to get you in
the mood. After that you will be given a shell prompt, see next chapter on shells.
When using graphical mode, the system will start an X session for you. In order to manipulate a
system or environment in graphical mode, you will then likely want to open an X terminal window or
xterm which starts your default shell in a window. There may be shortcuts for opening an xterm, or you
may have to use the mouse buttons. Since you are already authenticated to the system, you don't
need to log in again.

Getting started Contd..
Changing your password
User account, including passwords, are the first line of defense. Creating and maintaining user
accounts is one of the tasks of a system administrator. On a system that is monitored on a daily basis,
some programs should be installed to usher users to change their passwords regularly and to make
them acceptably difficult. In this case you will have to use the passwd command every now and then.
Should the system not point you in that direction, take a look at the chapter about scheduling
commands to install your own reminders.
Changing your password should be the first thing you do when accessing a new account for the first
time. Just type passwd on the command line and follow the instructions. You will be asked to enter
your current password, and after acceptation the system asks you to enter the new password twice.
You'll get a message saying that your entry in the /etc/passwd file and some other related files are
updated.

Disconnecting from a system
Text mode
When you're done working on the system, you should always log out. Don't just switch out the
screen, but enter the exit or logout command. In most shells entering CTRL-D does the same.
Do this in all open shells (or xterms), including those on other virtual consoles if you have them.
The system will then display a new login prompt, or destroy the terminal window if that's what you
were using.
When connecting from a PC, the terminal emulation program will show a blank window and a
disconnect message in most cases.

Graphical mode
After closing all terminal windows and applications, find the logout button. Most desktop systems
have one, if you use just a window manager try the mouse buttons to display menus.



Session 2 Working with File
system

Introducing File Components








All files in Unix make use of a file name & a record called inode
File is associated with inode & inode provide access to data
blocks
Inodes used to record information about a file
Inode contain two parts ,First inode contain information about the
file, including its owner ,its permissions & its size .Second ,inode
contain pointer to data block associated with file
Inodes are numbered & each filesystem have its own list of inode
which are created while creation of filesystem
Data blocks are unit of disk space used to store data



File Types
There are mainly four file types in Unix
1. Regular or Ordinary Files
2. Directories
3. Symbolic Links
4. Device Files
Device files don`t store data . They provide
access to devices
The Character in the first column of the ls l
command indicate the file type as follows :-
- : Regular File
d : Directory
l : Symbolic Link
b : Block Special Device name
c : Character Special Device name


Files & Directory
$ pwd
/home/abuzneid/UNIX
$
To Display Present Working Directory
ls l command to list the files in a directory (-l = long listing)
$ ls -l
total 8
drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:40 Documents
drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:43 mail
drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:53 memos
drwxr-xr-x 2 abuzneid 534 512 Oct 8 13:53 personal
Process

Startup & Shutdown
Press the power button on your system, and after few moments you see the Linux login
prompt
Linux Boot Process. Solaris Boot Process.

Linux Detail Boot Process
1. BIOS
BIOS stands for Basic Input/Output System
Performs some system integrity checks
Searches, loads, and executes the boot loader program..
Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
So, in simple terms BIOS loads and executes the MBR boot loader.
2. MBR
MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components
1) primary boot loader info in 1st 446 bytes
2) partition table info in next 64 bytes
3) mbr validation check in last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.
3. GRUB
GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which one to be executed.
GRUB displays a splash screen, waits for few seconds, if you dont enter anything, it loads the default kernel image
as specified in the grub configuration file.
GRUB has the knowledge of the filesystem (the older Linux loader LILO didnt understand filesystem).

Linux Detail Boot Process Contd..
Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of
CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img
As you notice from the above info, it contains kernel and initrd image.
So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel
Mounts the root file system as specified in the root= in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ps -ef | grep
init and check the pid.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It
also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other
hardware.

Linux Detail Boot Process Contd..
5. Init
Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels
0 halt
1 Single user mode
2 Multiuser, without NFS
3 Full multiuser mode
4 unused
5 X11
6 reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
Execute grep initdefault /etc/inittab on your system to identify the default run level
If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
Typically you would set the default run level to either 3 or 5.

6. Runlevel programs
When the Linux system is booting up, you might see various services getting started. For example, it might say starting sendmail . OK. Those are the
runlevel programs, executed from the run level directory as defined by your run level.
Depending on your default init level setting, the system will execute the programs from one of the following directories.
Run level 0 /etc/rc.d/rc0.d/
Run level 1 /etc/rc.d/rc1.d/
Run level 2 /etc/rc.d/rc2.d/
Run level 3 /etc/rc.d/rc3.d/
Run level 4 /etc/rc.d/rc4.d/
Run level 5 /etc/rc.d/rc5.d/
Run level 6 /etc/rc.d/rc6.d/
Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
Programs starts with S are used during startup. S for startup.
Programs starts with K are used during shutdown. K for kill.
There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the
sequence number of 80. So, syslog program will be started before sendmail.

Solaris Boot Process
1. Boot prom phase
2. Boot program phase
3. Kernel initialization phase
4. Init initialization phase
Power on > POST >Boot Device (1-15) >ufs boot loader >Kernel >/file system >/sbin/init >
/svc/lib/svc.startd
1. Boot prom phase
When we power on the server it displays banner. Banner includes host id, mac address, promt chip release
& version, physical memory size.
After displays the banner it starts post (Power On Self Test) and starts boot program phase
2. Boot program phase
Here it starts reading the boot program which is available in 1-15 sector of the HDD.
This 1-15 sector of HDD contains ufs which is responsible for loading secondary boot program called ufs
boot loader.
3. Kernel initialization phase
Ufs boot loader loads the kernel in to the memory. After the loading the kernel it starts unmapping the ufs
boot loader for loading operating system (O/S) modules and start mounting the root file system.
4. Init initialization phase
Here it starts /sbin/init process which is invoke /svc/lib/svc.startd which is responsible for following process
a. configuring all network devices
b. mounting all file system
c. starts all network services
d. runs rc-scripts which brings the machine to multi user mode
NOTE:-
In solaros_10 svc.startd act as a separate boot phase
The common process which starts at boot time in all flavor of Unix is init. But where as in Solaris there is
another process which starts before init is swapper and its process id is 0 but it is in solaris 9. from solaris
10 its renamed as scheduled process at the same process id.


Solaris Boot Process Contd..
Daemon
Its continuous processes which runs in a background and provide service as
per client request. The daemon which is responsible for starting the service
and stopping the service is init.d But from solaris_10 its replaced with
svc.startd
Stand Alone Services
This services which as starts as start time and which as ends down time its
called as Stand Alone Services . these are stored under /etc/init.d directory
PORT NO
For every service we are having an address called port number these are the
port no are stored under /etc/services file. /etc/services file and /etc/init/service
are having symbolically link

Booting a Unix System
Virtually all modern computers can be configured to boot automatically when power comes on or after a
crash. When autobooting is not enabled, booting is initiated by entering a simple command in response to a
prompt: sometimes just a carriage return, sometimes a b, sometimes the word boot.

Boot a system:
Solaris : ok boot
Linux ; boot: linux
When a command is required, you often can tell the system to boot to single-user mode by adding a -s or
similar option to the boot command, as in these examples from a Solaris and a Linux system:
ok boot -s Solaris
boot: linux single Linux


Boot Initialization - Linux
Linux
Initialize "init"
"init" is the main process, it will always have a PID value: 1.
"init" reads its configuration from the /etc/inittab file. that
contains the settings for the system at every level of execution.

Runlevels
"init"defines the X level of performance standards for Linux:
Level 0: Stop (not to be attributed to the initdefault)
Level 1, S: single user mode (only the root user can log).
Typically used for maintenance.
Level 2: Multi-user mode without NFS network
Level 3: full mode for multiple users including network
Level 4: User Configurable duplicate but the level 3 by default.
Level 5: X11 (including network)
Level 6: Restart

Boot Initialization - Solaris
Run Level Description User Status Run Control Script Directory
0 Hardware maintenance mode Console access /etc/rc0.d
1 Administrative state; only root file
system is available
Single user /etc/rc1.d
2 First multiuser state; NFS
resources unavailable
Multiuser /etc/rc2.d
3 NFS resources available Multiuser /etc/rc3.d
4 User-defined state Not specified N/A
5 Power down state Console access /etc/rc5.d
6 Operating system halted and
reboot
Multiuser /etc/rc6.d
S Administrative tasks and repair of
corrupted file systems
Console access /etc/rcS.d
Each run level is associated with a run level script, as shown in Table 5-2. The run level
script is responsible for the orderly execution of all run level scripts within a specific run
level directory. The script name matches the run level and directory name.
Control Script & Directory

Every Solaris init state (such as init state 6) has its own run level script directory (for example,
/etc/rc6.d). This contains a set of symbolic links (like shortcuts in Microsoft Windows) that are
associated with the service startup files in the /etc/init.d directory. Each linked script starts with a
letter S (start) or the letter K (kill), and is used to start or kill processes, respectively. When a
system is booted, processes are started. When a system is shut down, processes are killed. The
start and kill links are typically made to the same script file, which interprets two parameters: start
and stop. The scripts are executed in numerical order, so a script like /etc/rc3.d/ S20dhcp is
executed before /etc/rc3.d/ S21sshd. If youre curious about what kind of scripts are started or killed
in Solaris during startup and shutdown, Table 5-3 shows the startup scripts in /etc/rc2.d, while Table
5-4 shows the kill scripts found in /etc/rc0.d. Its important to realize that these will change from
system to system.
Example start & kill script

S05RMTMPFILES Removes temporary files in the /tmp directory.
S20sysetup Establishes system setup requirements, and checks
/var/crash to determine whether the system is recovering
from a crash.
K22acct Terminates process accounting using
/usr/lib/acct/shutacct.
K42audit Kills the auditing daemon (/usr/sbin/audit).

Das könnte Ihnen auch gefallen