Centos – SysV init run levels

centosinit-scriptrunlevelsysvinit

On a system that uses SysV init run levels such as Centos 5, when the OS is booting, does it go straight to the run level defined in /etc/inittab?

If I change my run level using the init command do the kill scripts for my current run level execute and then the start up scripts for the new run level execute?

For example if I was at run level 3 and entered init 1, would the kill scripts in /etc/rc.d/rc3.d be executed and then upon entering run level 1 would the startup scripts in /etc/rc.d/rc1.d be run?

Best Answer

Yes, SysVinit goes straight to the chosen run-level on boot without looking at scripts in other levels. You can view the runlevel history using the runlevel command. On first boot, it will show the "previous" runlevel as 'N'. After a runlevel change it will show the previous and current runlevel.

When switching runlevel, it first looks at the difference between them. Any services that are listed in the current level but not in the new one are first killed using the kill scripts, then any that are listed in the new level but not in the old one are run. Services that exist in both run levels are not touched.

For example switching from runlevel 3 to 5 will usually result in a few things (like a display manager) being started, but nothing killed. Switching from 5 to 1 will result in quite a few things being killed, then maybe 1 (like a single user interface console manager) being run.