The UNIX OS Peter J. Vasquez Sr. CSCI 6303.01. The UNIX OS What is UNIX? OpenBSD Installation...
-
Upload
mervyn-mathews -
Category
Documents
-
view
240 -
download
1
Transcript of The UNIX OS Peter J. Vasquez Sr. CSCI 6303.01. The UNIX OS What is UNIX? OpenBSD Installation...
The UNIX OS
What is UNIX? OpenBSD Installation Introduction to VI OpenBSD Configuration Introduction to ksh ksh Scripting
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
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.
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
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)
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
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
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
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)
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
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
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)
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)
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
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
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
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
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
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
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')
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'
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'
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 |&'
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 }
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