close

Вход

Забыли?

вход по аккаунту

код для вставкиСкачать
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 prespecified 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 runlevels. 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.
Example of /etc/rc.d/rc5.d/
•
•
•
•
•
•
•
•
•
•
•
K05innd
K30mcserv K80nscd
S20random S80sendmail
K10pulse
K34yppasswdd K84apmd S25netfs
S85gpm
K15pvmd
K35dhcpd K84ypserv S30syslog S85httpd
K20bootparamd K45named
K92ipchains S35krb5server S90xfs
K20isdn
K50snmpd
K96pcmcia S40atd
S91smb
K20rstatd
K54pxe
S05kudzu S40crond
S99linuxconf
K20rusersd K55routed S06reconfig S50inet
S99local
K20rwalld
K60mars-nwe S10network S55xntpd
K20rwhod
K61ldap
S11portmap S60lpd
K25squid
K65identd S14nfslock S60nfs
K28amd
K75gated S18autofs S75keytable
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 <cursor waits here for input>
– You picked: <what you entered>
• You can define variables as commands
• dir=`pwd` (note the backquote)
• echo “You are in $dir”
• The output is:
You are in <your current working directory>
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
<commands>
fi
if ( T/F )
then
<commands>
else
<commands>
fi
if ( T/F )
then
<commands>
elif ( T/F )
<commands>
else
<commands>
fi
other structures
while ( T/F )
do
<commands>
done
case <variable> in
value)
<commands>
;;
value)
<commands>
*)
<commands>
;;
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
Typical linux init.d script
#!/bin/sh
# chkconfig: - 91 35
# description: Starts and stops the Samba smbd
and nmbd daemons used to provide SMB
network services.
…
start() {
KIND="SMB"
echo -n $"Starting $KIND services: "
daemon smbd $SMBDOPTIONS
RETVAL=$?
echo
KIND="NMB"
echo -n $"Starting $KIND services: "
daemon nmbd $NMBDOPTIONS
RETVAL2=$?
echo
[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] &&
touch /var/lock/subsys/smb || \
RETVAL=1
return $RETVAL
}
stop() {
KIND="SMB"
echo -n $"Shutting down $KIND services: "
killproc smbd
RETVAL=$?
echo
KIND="NMB"
echo -n $"Shutting down $KIND services: "
killproc nmbd
RETVAL2=$?
[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] &&
rm -f /var/lock/subsys/smb
echo ""
return $RETVAL
}
command line output:
#/etc/init.d/smb start
Starting SMB services:
Starting NMB services:
[OK]
[OK]
shorter init.d script
if test $1 = "start" then
/usr/local/bin/sshd
elif test $1 = "stop" then
killall -9 sshd
fi
Q&A
1/--страниц
Пожаловаться на содержимое документа