Starting and Stopping Linux

Download Report

Transcript Starting and Stopping Linux

Starting and Stopping Linux
Boot Process
• BIOS initializes hardware
– Loads the boot sector
• MBR loads the bootloader
– Point to kernel
• Kernel initializes peripherals, loads drivers, mounts root
file system
– Calls /sbin/init
• Spawns user level processes
– Reads /etc/inittab
– Other scripts kicked off from inittab
• Distribution specific operations
– Red Hat
• /etc/rc.d/rc.sysint
• /etc/rc3.d or /etc/rc5.d (runlevel)
Run Levels
• Common scheme
–
–
–
–
0
1
2-5
6
Halt
single user
multi-user
reboot
• Red Hat
–
–
–
–
–
0
1
3
5
6
Halt
single-user text
multi-user text
multi-user graphical
reboot
Runlevel
• /sbin/runlevel
– Determines the run level
–N5
• “N” means you haven’t previously booted to a
different runlevel
– /sbin/init 3
• Change your runlevel. You must be root
– /sbin/init 1
• Single user, text, root shell
Why init?
• Init 1
– Troubleshoot and repair
• Stop/repair when normal methods fails
• Restart/switch services
• End an X session
Changing the default runlevel
• /etc/inittab
id:2:initdefault
– change “2” to the desired runlevel
• Comment line out
– Prompted for runlevel at startup
Stopping X
• startx is the command
– When you ‘log out’, X stops
Managing runlevels
• Red Hat
– chkconfig command
• Allows you to turn services on, off for one or more runlevels
• Allows you to add, delete services for one or more runlevels
– Chkconfig - - level 2345 ssh on
– Chkconfig - - add ssh
• xinetd services turned on/off with chkconfig (all
levels)
• chkconfig - - list
Try it…
• List all the services running on the system
• You can specify listing the status of a
single service as well
– Just list the service in the command
• chkconfig - - list syslog
• ln command
– Create a softlink to configure a service in a
runlevel
#ln –s /etc/rc.d/init.d/cups /etc/rc.d/rc3.d/S90cups
• Create the link for all runlevels
– Including the “kill” level!
#ln –s /etc/rc.d/init.d/cups /etc/rc.d/rc0.d/K01cups
Running and stopping services
• /init.d
– Contains scripts
• Read the script (for options)
# /etc/init.d/networking
– To stop networking:
# /etc/init.d/networking stop
Shutting down Linux
• Shutting down (must be root)
# shutdown –h now
# poweroff
# halt
# shutdown –h +6 “System coming down in 6 minutes”
• Cancel the shutdown
# shutdown –c
• Reboot
# shutdown –r now
# reboot
Ctrl-Alt-Delete
• Disable the 3-finger reboot
– Comment out the line in /etc/inittab
# ca:12345:ctrlaltdel:/sbin/shutdown –t1 –r now
– To allow for a set of users
• Add the –a switch
# ca:12345:ctrlaltdel:/sbin/shutdown –t1 –a –r now
– Then add list of allowed users to
/etc/shutdown.allow
Shutting down automatically
• Use the crontab
/etc/crontab
Add a line:
# m
00
h
23
dom
*
mon
*
dow
*
user
root
command
/sbin/shutdown – h now