Presentation on theme: "Introduction to Linux Linux startup process Unix Shells and scripts."— Presentation transcript:
Introduction to Linux Linux startup process Unix Shells and scripts
Startup of Linux When you start linux, you normally see lines of messages with a SUCCESS or FAIL tag on the right. (Press F2 to see these messages on SuSE Linux.) These messages basically tells you devices it detects. After that, Linux will be launched in 1 of 7 runlevels.
Runlevels of Linux Changing the default runlevel is sort of like switch Windows into safe mode. The 7 runlevels of Linux are as follows: Runlevel 0Halt (shutdown machine) Runlevel 1Single-user mode* Runlevel 2User-defined mode Runlevel 3Multi-user mode (no GUI) Runlevel 4Another user-defined mode Runlevel 5Multi-user mode (GUI) Runlevel 6Reboot * In single-user mode, networking is disabled, usually only root partition is mounted with read- only.
Purpose of runlevels? Runlevels restricts the kernel. On a workstation, you probably want to run linux with a runlevel of 5 to allow multiple people to use that machine. On a server, you would run linux with a runlevel of 3 because you wouldn't need X-server to be on. On runlevel 3, X-server in not started by default. When you restore a backup to a linux machine, you would run with runlevel 1.
Switching runlevels The default runlevel is defined in the file /etc/inittab. To switch runlevel on the fly, use the command init and pass in the desired runlevel. (init 3)
Daemon processes... A program that should be run in the background without user intervention is called a daemon process. A daemon, in the real world, is a type of being immediate between God and humans that is neither evil nor good and is the help of both as defined by Greek methology. Usually, when a daemon is started, it'll detach from a terminal, fork a child process and exits. When a parent process exits and the child is still running, the init process becomes the parent for the child.
/etc/rc.d Any startup scripts are normally placed in this directory. Inside this directory, there are normally subdirectories rc0.d to rc6.d that corresponces to the different runlevels. Normally, you would place symbolic links inside the rc subdirectories and have them point to the actual rc script. This way, the script is more managable.
Sample startup script #!/bin/sh case "$1" in start) if [ -x /usr/local/apache/bin/apachectl ]; then /usr/local/apache/bin/apachectl startssl > /dev/null 2>&1 && echo -n ' Apache HTTP Server' fi ;; stop) if [ -x /usr/local/apache/bin/apachectl ]; then /usr/local/apache/bin/apachectl stop > /dev/null && echo ' Apache stopped' fi ;; *) echo "$0 start | stop" ;; esac
Shells Common shells: shbourne shell cshc shell kshkorn shell bashbourne again shell tcshtc shell zshz shell Perferred shell for linux users is bash. Perferred shell for BSD users is tcsh. To change your default shell, use the chsh command.
Shell scripts Normally, shells scripts are run with the bourne shell as this shell exists in all unixes. The first line of a shell script is which shell the script is going to be run by. #!/bin/sh After that, they are basically shell commands. A shell script must have the executable permission.
BSD Startup BSD do not use runlevels. Instead, BSD uses what's called kernel secure level. A higher securelevel means more restriction. When BSD boots up, it runs in a securelevel of 0. After that, the secure level may not be lowered, but may be raised.
The default securelevel is -1. At securelevel 1, X-Server may not be run. Imutable flags may not be changed. At securelevel 2, all of level 1 and time might may not be changed to more than about 1 sec. And firewall rules may not be changed.
Because there are no runlevels, BSDs do not have the /etc/rc0.d directories. Instead, scripts in /etc/rc.d and /usr/local/etc/rc.d are executed.