|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
Softpanorama Search
|
| Recommended Links | grub | Xinetd | Suse RC Scripts | ||
| Solaris Run Levels |
Humor |
Etc |
The default runlevel for a system is specified in the /etc/inittab file, which will contain an entry such as id:3:initdefault: if the system starts in runlevel 3, or id:5:initdefault: if it starts in runlevel 5.
There are three method of determining the current runlevel
# who -r run-level 3 Aug 27 10:12 last=5
echo $RUNLEVEL
After the kernel starts a program called init, the init process reads the file "/etc/inittab" and uses this file to determine how to create processes. It does it in stages called runlevels.
The administrator can also dynamically change the current runlevel by using the init program. the default runlevel into which the system is booted can be changed by editing the "/etc/inittab" file.
Red Hat as well as its derivatives including Suse uses run levels in a following way:
Which services are started in which runlevels can be managed with the chkconfig tool, which keeps its configuration settings in a elaborate set of link to scripts contained in /etc/rc.d/.
/sbin/chkconfig --list lists all the services controlled by chkconfig and whether they are on/off for each runlevel. Setting a service A controlled by chkconfig, for levels X, Y and Z is achieved using /etc/chkconfig --level XYZ A
See Runlevel - Wikipedia, the free encyclopedia
| Default level is defined in /etc/inittab, for example id:5:initdefault |
The "/etc/inittab" file tells init which runlevel to start the system at and describes the processes to be run at each runlevel. An entry in the inittab file has the following format:
id:runlevels:action:process
# inittab This file describes how the INIT process should set up # the system in a certain run-level. # # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org> # Modified for RHS Linux by Marc Ewing and Donnie Barnes # # Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # 1) id:3:initdefault: # System initialization. 2) si::sysinit:/etc/rc.d/rc.sysinit 3) l0:0:wait:/etc/rc.d/rc 0 4) l1:1:wait:/etc/rc.d/rc 1 5) l2:2:wait:/etc/rc.d/rc 2 6) l3:3:wait:/etc/rc.d/rc 3 7) l4:4:wait:/etc/rc.d/rc 4 8) l5:5:wait:/etc/rc.d/rc 5 9) l6:6:wait:/etc/rc.d/rc 6 # Things to run in every runlevel. 10) ud::once:/sbin/update # Trap CTRL-ALT-DELETE 11) ca::ctrlaltdel:/sbin/shutdown -t3 -r now # When our UPS tells us power has failed, assume we have a few minutes # of power left. Schedule a shutdown for 2 minutes from now. # This does, of course, assume you have powerd installed and your # UPS connected and working correctly. 12) pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" # If power was restored before the shutdown kicked in, cancel it. 13) pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled" # Run gettys in standard runlevels 14) 1:2345:respawn:/sbin/mingetty tty1 15) 2:2345:respawn:/sbin/mingetty tty2 16) 3:2345:respawn:/sbin/mingetty tty3 17) 4:2345:respawn:/sbin/mingetty tty4 18) 5:2345:respawn:/sbin/mingetty tty5 19) 6:2345:respawn:/sbin/mingetty tty6 # Run xdm in runlevel 5 # xdm is now a separate service 20) x:5:respawn:/etc/X11/prefdm -nodaemonOn the left side of the file listing, above, are added numbers to help describe lines. Those lines without line numbers are either blank or begin with a "#" which means the line is a comment. Those line numbers are not part of the original file and are added here for reference purposes.
Note the order of programs to run as specified above are:
Therefore, the next thing that the system does is to run the rc.sysinit file, save buffers to the hard drive, then run system script files for the requested runlevel which will start up many system and network services as explained in the next section.
The default boot runlevel is set in the file /etc/inittab with the initdefault variable. When set to 3, the system boots up with the text interface on the VGA console; when set to 5, you get the GUI. Here is a snippet of the file (delete the initdefault line you don't need):
# Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:3:initdefault: # Console Text Mode id:5:initdefault: # Console GUI Mode
Note the following:
Posted: 3 May 2005Linux operating systems utilize runlevels to determine the services that should be running and to allow specific work to be done on the system. For example, runlevel one is designated single-user mode without networking and is used for critical system maintenance and troubleshooting. Runlevel three is multi-user text mode. Runlevel five is multi-user graphical mode.
Switching between runlevels is accomplished using the init command. Entering:
# init 5
will change to runlevel five. Changing to runlevel six will reboot the machine and runlevel zero will shut down the machine.
Entering runlevel at the command prompt will output the previous and current runlevels. For example:
#runlevel
N 5indicates that the machine is in runlevel five. The 'N' indicates that the machine was booted into level five, or no previous runlevel was entered.
As mentioned previously, the different runlevels are configured to run a specific set of services. Each runlevel is configured to start its specified services when starting and to shut down its services when switching to a different runlevel.
As a general rule, turn off all services that are not needed at a given runlevel. Managing the services started in each runlevel is simple and can be done graphically in YaST or at the command line with the chkconfig command.
Managing Runlevel Services With YaST
YaST offers a robust and easy to use runlevel service configuration tool. Access the tool at YaST > System > Runlevel Editor. Within the tool, turn services on or off by selecting the service and then selecting the Enable/Disable buttons.
Selecting expert mode allows the administrator to configure the state of a service in each runlevel.
For example, use the YaST runlevel editor to configure the OpenSLP daemon, slpd, to start in runlevels three and five only. Do the following:
- Select YaST > System > Runlevel Editor.
- Select the Expert Mode radio button.
- In the services list, select slpd.
- Use the check boxes to select runlevels three and five. Deselect all other runlevels.
- Save changes and exit.
Managing Runlevel Services With chkconfig
Most Linux distributions include the chkconfig command for managing runlevel services. The syntax for chkconfig is specified in the chkconfig man page.
For example, use chkconfig to configure the OpenSLP daemon, slpd, to start in runlevels three and five only. Do the following:
1.Check if slpd is on in the current runlevel
# chkconfig slpd
slpd on2.Check slpd's configuration for every runlevel.
# chkconfig -l slpd
slpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off3.Turn slpd on in runlevels three and five.
#chkconfig slpd 35
Unlike most non-UNIX operating systems which only have 2 modes of functionality (on and off), UNIX operating systems, including Linux, have different runlevels such as "maintenance" runlevel or "multi-user" runlevel, etc.
Runlevels are numbered from 0 to 6 and will vary from one Linux distribution to another. The description for each runlevel functionality is sometimes documented in
/etc/inittab.Table 2.1. Linux runlevels
Runlevel Purpose 0 Shuts down the machine safely. The operating system will also attempt to poweroff the system if possible 1 Single user mode. Only one terminal is available for the (single) user root. All other users are logged out2[a] Multi-user mode, but does not start NFS. Network services like email or web services are also stopped 3[a] Full multi-user mode. Selected network services are all on. 4[a] Not defined and generally unused 5[a] Like runlevel 3 but runs a Display Manager as well 6 restarts the machine safely [a] These runlevels may vary in functionality between Linux flavours. But these descriptions correspond to the current LSB specification.2.2.1. INIT Controls Runlevels
Both init and telinit are used to switch from one runlevel to another. Remember that init is the first program launched after the kernel has accessed the root device.
At boot time init is instructed which runlevel to reach in
/etc/inittabwith the line:id:5:initdefault:When the system is started it is possible to change runlevels by invoking init (or telinit which is a symbolic link pointing at init).
For example we switch to runlevel 4 with either of the next commands:
init 4 telinit 4The PID for init is always 1. It is possible to find out which runlevel the system is currently in with the command runlevel
runlevel N 5The first number is the previous runlevel (or N if not applicable) and the second number is the current runlevel.
Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Disclaimer:
Last modified: August 27, 2009