104
The UNIX OS Peter J. Vasquez Sr. CSCI 6303.01

The UNIX OS

  • Upload
    indra

  • View
    78

  • Download
    0

Embed Size (px)

DESCRIPTION

Peter J. Vasquez Sr. CSCI 6303.01. The UNIX OS. The UNIX OS. What is UNIX? OpenBSD Installation Introduction to VI OpenBSD Configuration Introduction to ksh ksh Scripting. What is UNIX?. Design Architecture Filesystems Brief History. UNIX Design. Modular Programming - PowerPoint PPT Presentation

Citation preview

Page 1: The UNIX OS

The UNIX OS

Peter J. Vasquez Sr.CSCI 6303.01

Page 2: The UNIX OS

The UNIX OS

What is UNIX? OpenBSD Installation Introduction to VI OpenBSD Configuration Introduction to ksh ksh Scripting

Page 3: The UNIX OS

What is UNIX?

Design Architecture Filesystems Brief History

Page 4: The UNIX OS

UNIX Design

Modular Programming software design technique that increases the extent to

which software is composed from separate parts, called modules. http://en.wikipedia.org/wiki/Modularity_(programming)

Re-Usable Code the likelihood a segment of source code can be used

again to add new functionalities with slight or no modification. http://en.wikipedia.org/wiki/Reusability

Page 5: The UNIX OS

UNIX Architecture

Kernel – manages the computer's resources and controls their use by programs.

Consists of: CPU – responsible for running or executing

programs. The kernel decides which processes are allocated to the processor.

Memory – used to store instructions and data. The kernel decides what memory is available to a process, and whether nor not enough is available.

I/O – input and output devices (keyboards, mice, disk drives, etc). The kernel allocates requests to these devices from applications to perform I/O.

Page 6: The UNIX OS

UNIX Architecture (cont.)

Shell - user interface to the kernel, where commands are input (whether on the command line interface or in a GUI)

Shell Examples: Bourne Shell (and variants) C Shell (and variants) Blackbox, fluxbox, fvwm, GNOME, KDE, XFCE,

CDE

Page 7: The UNIX OS

UNIX Architecture (cont.)

System Processes (Daemons) – programs that assist the kernel with specific system tasks. Refers to background processes Handles tasks in the background that the user

cannot be bothered with Most daemons are child processes of another

running process (usually the init process, which is the initialization shell script responsible for starting up most processes after the kernel has loaded)

Page 8: The UNIX OS

UNIX Architecture (cont.)

Parent/Child Processes Relationship of running process to other running

processes. If one process initiates a new process, it is called the parent, while the new process is known as a child

New processes are spawned through a procedure called 'fork', which creates a copy of the parent along with the needed memory space and parameters to run with a task/set of instructions

Common example is the execution of shell commands, which remain interactive while child processes can be sent to the background to run

Page 9: The UNIX OS

UNIX Filesystems

UFS – UNIX File System (4.2/4.4BSD) a few block at the beginning reserved for boot

blocks a superblock containing a magic number identifying

as UFS filesystem a collection of cylinder groups, each containing the

following: backup copy of the superblock cylinder group header with statistics number of inodes number of data blocks

Page 10: The UNIX OS

UNIX Filesystems (cont)

<swap> - form of virtual memory used to extend available

main memory dedicated partition, which should be at least the

size of main memory not required, but highly recommended

Page 11: The UNIX OS

UNIX Brief History

Page 12: The UNIX OS

A Brief Overview of OpenBSD

UNICS -> UNIX TSS -> BSD -> NetBSD -> OpenBSD Designed with Security and Simplicity as primary goals

(only 2 remote holes in the default install in the past 10 years)

Major contributions to other UNIX/Linux Operating Systems include OpenSSH : free implementation of SSH (secure shell)

which provides for encrypted remote administration of UNIX/Linux systems (85% of installed systems world-wide)

pf : or packet filter (firewall) has been used in a wide range of embedded systems (for example, the syswall security appliance)

Page 13: The UNIX OS

OpenBSD Installation

Obtain CD (can be purchased at openbsd.org, or ISO download from ftp.openbsd.org)

Boot up using correct version (i386 in this example)

Set up partition sizes, choose filesystem type Set up basic system and package configuration

Page 14: The UNIX OS

OpenBSD Installation (cont.)

Boot from CD

Page 15: The UNIX OS

OpenBSD Installation (cont.)

Press 'i' for install

Page 16: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>

Page 17: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>

Page 18: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>

Page 19: The UNIX OS

OpenBSD Installation (cont.)

Type 'yes' to proceed with install

Page 20: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>

Page 21: The UNIX OS

OpenBSD Installation (cont.)

Press <enter> for default disk, or specify disk

Page 22: The UNIX OS

OpenBSD Installation (cont.)

Type 'yes' to use the entire disk for OpenBSD

Page 23: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>

Page 24: The UNIX OS

OpenBSD Installation (cont.)

Now, type '?' for help, then press <enter>

Page 25: The UNIX OS

OpenBSD Installation (cont.)

Now type 'p' to see current partition map

Page 26: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>

Page 27: The UNIX OS

OpenBSD Installation (cont.)

Create (/) root, <swap>, /tmp and /var partitions

Page 28: The UNIX OS

OpenBSD Installation (cont.)

Create /usr and /home partitions

Page 29: The UNIX OS

OpenBSD Installation (cont.)

Type 'p' and press <enter> to see partitions

Page 30: The UNIX OS

OpenBSD Installation (cont.)

Type 'w', <enter>, 'q', <enter>, to write and exit

Page 31: The UNIX OS

OpenBSD Installation (cont.)

Now begin basic system, package configuration

Page 32: The UNIX OS

OpenBSD Installation (cont.)

Type hostname, networking info, press <enter>

Page 33: The UNIX OS

OpenBSD Installation (cont.)

Type in root password, press <enter> for CD

Page 34: The UNIX OS

OpenBSD Installation (cont.)

Type in 'all' to select all packages

Page 35: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>, type 'done', and press <enter>

Page 36: The UNIX OS

OpenBSD Installation (cont.)

Packages begin unpacking/installing to disk

Page 37: The UNIX OS

OpenBSD Installation (cont.)

Type timezone 'US/Central', type 'halt' to reboot

Page 38: The UNIX OS

OpenBSD Installation (cont.)

Press <enter>, the system will now reboot

Page 39: The UNIX OS

Introduction to VI

Two modes of operation Insert mode : type in a character to modify the

contents under the cursor directly Command mode : type in a “:” followed by the

command string for more advanced options We can create files, modify their contents, and

write the changes back to the disk We can search within files for common strings Useful in modification of the OS configuration

files

Page 40: The UNIX OS

Introduction to VI (cont.)

Login as new user, list contents of directory

Page 41: The UNIX OS

Introduction to VI (cont.)

Type 'vi sample' for a new file named 'sample'

Page 42: The UNIX OS

Introduction to VI (cont.)

Type 'I' for insert mode, type, press <esc> ': wq'

Page 43: The UNIX OS

Introduction to VI (cont.)

We can open the same file to make changes

Page 44: The UNIX OS

Introduction to VI (cont.)

Type 'yy' and then 'p' to copy and paste the line

Page 45: The UNIX OS

Introduction to VI (cont.)

You can type 'dd' to delete the current line

Page 46: The UNIX OS

Introduction to VI (cont.)

We can search/replace a word, ':%s/new/old/g'

Page 47: The UNIX OS

Introduction to VI (cont.)

Now our file reads the following:

Page 48: The UNIX OS

Introduction to VI (cont.)

We can undo the change by typing 'u'

Page 49: The UNIX OS

Introduction to VI (cont.)

A lot of changes are available, for a complete reference you can type in 'vi reference' into a search browser, which will provide many results

The most common uses of vi are for the modification of system configuration files, and in shell programming (scripting)

Page 50: The UNIX OS

OpenBSD Configuration

Default configuration is listed in /etc/rc.conf

Page 51: The UNIX OS

OpenBSD Configuration (cont.)

/etc/rc.local for startup change (not /etc/rc.conf)

Page 52: The UNIX OS

OpenBSD Configuration (cont.)

For the GUI, configuration is in /etc/xorg.conf

Page 53: The UNIX OS

OpenBSD Configuration (cont.)

Login as root user Type 'man afterboot' on first boot to see list of

configurable options (new admin's guide) Run 'adduser' script to setup defaults Create User (best practice not to use root for

everything)

Page 54: The UNIX OS

OpenBSD Configuration (cont.)

Login as 'root' and type the password

Page 55: The UNIX OS

OpenBSD Configuration (cont.)

Press <enter> for default terminal type

Page 56: The UNIX OS

OpenBSD Configuration (cont.)

Type 'man afterboot' for admin guide (overview)

Page 57: The UNIX OS

OpenBSD Configuration (cont.)

Type 'adduser' and setup defaults for system

Page 58: The UNIX OS

OpenBSD Configuration (cont.)

Create User

Page 59: The UNIX OS

OpenBSD Configuration (cont.)

Now that we have a local user, we will exit the session as 'root' and re-login as the new user to continue configuration process

Configure networking parameters (done at installation, but can be changed after boot)

Configure GUI for X Windows

Page 60: The UNIX OS

OpenBSD Configuration (cont.)

Login, type 'su', root password, press <enter>

Page 61: The UNIX OS

OpenBSD Configuration (cont.)

Type 'ifconfig -a' , and vi '/etc/hostname.vic0'

Page 62: The UNIX OS

OpenBSD Configuration (cont.)

The network configuration is set to DHCP

Page 63: The UNIX OS

OpenBSD Configuration (cont.)

We can setup the GUI with 'X -configure'

Page 64: The UNIX OS

Introduction to ksh (K Shell)

A shell is primarily used to interpret commands into instructions for the operating system

When we first log in, the command line we are presented uses the korn shell (ksh)

Behavior of ksh is defined through shell variables

The following screens will show navigation through commands is ksh to create a directory, list it's contents, and either dump the sample file to the screen, or move it into our new directory

Page 65: The UNIX OS

Introduction to ksh (cont.)

Some sample shell variables

Page 66: The UNIX OS

Introduction to ksh (cont.)

We can also issue 'cat sample' to show our file

Page 67: The UNIX OS

Introduction to ksh (cont.)

We can list the contents of our directory, 'ls -al'

Page 68: The UNIX OS

Introduction to ksh (cont.)

And make a new directory, 'mkdir temp'

Page 69: The UNIX OS

Introduction to ksh (cont.)

Change directory with 'cd temp', list with 'ls -al'

Page 70: The UNIX OS

Introduction to ksh (cont.)

Now we can move our file, 'mv ../sample .'

Page 71: The UNIX OS

Introduction to ksh (cont.)

And show the directory contains our file, 'ls -al'

Page 72: The UNIX OS

Introduction to ksh (cont.)

We can see the contents again with 'cat sample'

Page 73: The UNIX OS

ksh Scripting

Combining the previous slides, we can begin to see how commands can be chained together

These chains of commands can be used to form shell scripts for common or routine tasks of the operating system

Page 74: The UNIX OS

ksh Scripting Defined

At the beginning of this file, we need to include !#/usr/bin/ksh

File starts on first line and ends at last line or when encountering the word 'exit'

There are four types of lines the shell defining line empty lines commentary (begin with a '#') commands

Page 75: The UNIX OS

ksh Scripting Defined (cont)

Script files should be change to permissions “chmod 700” (rwx – user, no permissions for group or world)

Commands start at the first word and end with the end of the line, or with a ';'

Examples: print -n “Name: “; read name; print “” grep filename | sort -u awk '{print $4}' | \

uniq -c >> /longpath/file

Page 76: The UNIX OS

ksh Variables

Example ksh variables

Page 77: The UNIX OS

ksh Arrays

Example ksh arrays

Page 78: The UNIX OS

ksh Branching (Conditional Statements)

Example Branching

Page 79: The UNIX OS

ksh Branching (Conditional Statements) plus Case Statement

Example Branching/Case Statements

Page 80: The UNIX OS

ksh Looping

Example Loop Statements

Page 81: The UNIX OS

ksh Looping plus continue,break

Example Loop Statements (cont)

Page 82: The UNIX OS

ksh Command Line Arguments (Positional Parameters)

Example Command Line Arguments

Page 83: The UNIX OS

ksh Comparisons

Example Use of Comparisons

Page 84: The UNIX OS

ksh Variable Manipulation

Example variable manipulation

Page 85: The UNIX OS

ksh Regular Expressions

Use * for matching any string (for example, to get all files end in .c, use *.c)

?(pattern) matches zero or one times *(pattern) matches any time the pattern +(pattern) matches one or more times @(pattern) matches one time the pattern !(pattern) matches string without the pattern

Page 86: The UNIX OS

ksh Functions

Making a Function function foo { #commands } foo() { #commands }

Calling the Function foo arg1 arg2 ... (arguments $1...$n or $*)

Return exits the function immediately with value specified

after return as exit status (for example, 'return 0')

Page 87: The UNIX OS

ksh Data Redirection

Done with “>” “>>” “<” “<<” Command Output to File

To write to a new file: 'command > file' To Append to an existing file: 'command >> file'

Standard Error Redirection To redirect the error output: 'command 2> file' Discard the error: 'command 2>/dev/null'

File into Command replaces standard input with file: 'command < file'

Page 88: The UNIX OS

ksh Data Redirection (cont)

Combine Input and Output Redirection 'command < infile > outfile' 'command < infile > outfile 2>/dev/null'

Commands into Program 'command <<EOF

input1 input2 input3 EOF'

Page 89: The UNIX OS

ksh Pipes and Co-processes

To send output of one command to another ' command1 | command2 | command3 ' for example “last | awk '{print $1}' | sort -u”

Background Processes command |& for example, ksh in background 'ksh |&'

Page 90: The UNIX OS

ksh Input from User and Files

Read in a Variable print -n “Enter your favorite color: “;read var; print””

Read into a File Line for Line get each line of a file into a variable

{ while read myline; do # process $myline done } < filename

catch output last | sort | {

while read myline;do #commands done }

Page 91: The UNIX OS

ksh Special Variables

$# - Number of arguments on command line $? - Exit status of last command $$ - Process id of current program $! - Process id of last background job $0 – Program name including path $1..$n – Command line arguments, one by one $* - All command line arguments in one string

Page 92: The UNIX OS

ksh Sample Script

Create new file with vi, add shell to top

Page 93: The UNIX OS

ksh Sample Script (cont)

Keep looping until our condition is met

Page 94: The UNIX OS

ksh Sample Script (cont)

Now we can ask the user for some information

Page 95: The UNIX OS

ksh Sample Script (cont)

If we have the right person, verify password

Page 96: The UNIX OS

ksh Sample Script (cont)

Add condition to limit number of guesses

Page 97: The UNIX OS

ksh Sample Script (cont)

If the user login is successful, run command

Page 98: The UNIX OS

ksh Sample Script (cont)

Now we make sure script is executable

Page 99: The UNIX OS

ksh Sample Script (cont)

We can run the script now with './sample'

Page 100: The UNIX OS

ksh Sample Script (cont)

If the name doesn't match, ask again

Page 101: The UNIX OS

ksh Sample Script (cont)

Now the name matches, so ask the password

Page 102: The UNIX OS

ksh Sample Script (cont)

Password doesn't match, so ask again

Page 103: The UNIX OS

ksh Sample Script (cont)

Password matches, run authorized command

Page 104: The UNIX OS

Any Questions?