Presentation on theme: "Cosc 4750 Booting and shutdown. Bootstrapping Starting up a computer, load kernel into memory and begin executing. a vulnerable time, since errors in."— Presentation transcript:
Cosc 4750 Booting and shutdown
Bootstrapping Starting up a computer, load kernel into memory and begin executing. a vulnerable time, since errors in configurations files, damaged file systems, failing hardware can prevent the computer from booting.
Booting manual –varies between venders –Linux boots to single user mode many system process are not running and only one user can log in (usually root) only part of the filesystem is mounted / /tmp, sometimes /usr and /var –Redhat 7.3+, all local partitions are mounted. –SGI boot to a command mode no system processes are running and the file system is not mounted. Only basic maintenance tasks can be done.
automatic –Unix boots to multi-user mode. (or mode pre- specified by administrator) –All system process (that are supposed too) are running. –Entire file system is mounted
Steps in booting 1.the boot code that is stored in ROM (BIOS or CMOS) is executed 2.the ROM turns over control to a boot loader (grub for Linux) 3.the boot loader loads and executes the kernel a.device detection and configuration 4.the kernel spawns the system init process, which is PID 1 a.manual boot mode: operator intervention (linux)
5. the init process executes a series of startup scripts in the from the rc.d directory which starts up system process and daemons. rc = run command 6. Multi-user operation
System Processes swapper – process 0 (not linux) init process 1 various memory and kernel handlers 1 getty process (console, not a gui environment)
Mutli-user operation More getty processes to handle logins xdm for X-term logins gdm or dtlogin (SUN) prefdm, X11 windows environment (linux) clogin (SGI)
Boot Loader (linux) Provides a way to boot linux, and other O/S like windows, etc. lilo: –configured with a text file, lilo.conf –specifies where the “kernel” is located can be /unix, but redhat 9 uses /boot/vmlinuz Grub –Configured through /etc/grub.conf, similar to lilo
Dual Boot Grub –List of available linux kernels to boot –And lists the window boot loader. Turns control over to the windows boot loader, which then boots windows Because of this, windows must always be installed first, then linux.
Run Levels level 0 is the level for system shutdown level 1 or S is single-user mode mode level 2-5 are varying multi-user levels –Linux: 3 is none-gui, 5 is gui –linux: 2 no gui and no networking. level 6: is a reboot level specified in /etc/inittab
Shutdown To shutdown a system, use the command: shutdown (normally found in /etc/ or /sbin Takes arguments to change between run- levels. like run level 0, which is shutdown Two versions (sys V and bsd) –shutdown –g0 –i0 –y –shutdown –h now (linux command)
Shutdown is a script that accesses the init process, – except shutdown –n which is a nasty way to shutdown a system. telinit S which simply go to run level 1 telinit 0 which shutdown the system, without telling anyone. Killing the init process will either reboot the system or just cause it to crash (more likely)
startup scripts The run level determines which startup scripts are used. –All of the scripts are located in the /etc/init.d/ directory There are also rcX.d directories –where X is the run level –These contain links to the files in the init.d directory So you only have to modify one file, instead 2 or 3.
Shell Scripting Shells are the command interface you use on a UNIX system, similar to DOS –Bourne (sh) Most init/startup scripts are written in bourne –c (csh), tcsh –korn (ksh), z (zsh) –Born Again Bourne Shell (bash)
Each is similar in characteristics, but each has it own scripting language. zsh and tcsh are upgrades of csh bash is a (much needed) update to Bourne shell –Startup scripts are done in bash or bourne. This is also the shell for root.
Shell Scripts (with bourne shell) file containing a series of commands One command per line (or separated by a ;) Output –Standard out and Standard Error output –command >file redirects std output –cmd >file 2>file2 directs std to file and stderr to file 2
variables a shell script uses the same environment variables as your shell uses, ie PATH, etc. using variables (in sh) –person=‘jim’ –echo “$person” –output: jim
read command echo –n “Pick a number ” read num echo “You picked: $num” OUPUT: –Pick a number –You picked:
You can define variables as commands dir=`pwd` (note the backquote) echo “You are in $dir” The output is: You are in
Argument variables $0 is the first argument, which is the name of the script $1 - $9 are command line values passed to the script myscript hi $0 contains myscript $1 contains hi
If command if ( T/F ) then fi if ( T/F ) then else fi if ( T/F ) then elif ( T/F ) else fi
other structures while ( T/F ) do done case in value) ;; value) *) ;; esac
Example 1 echo “Do you like UNIX?” read answer case $answer in Y|y ) whoami >>pass echo “good!” ;; N|n ) whoami >>fail echo “To bad.” ;; *) echo “please enter y or n” ;; esac
Example 2 filename=‘jim.txt’ if ( test –r $filename ) then echo “$filename is readable.” elif ( test –f $filename ) then echo “$filename does not exists.” else echo “$filename is not readable.” fi