Thursday, 17 March 2016

Understanding init run levels within Linux

Run levels effectively allow you to provide certain degrees of functionality - there are several run-levels that I will describe below:

0 - halt : This will simply shutdown the machine.
1 - Single User Mode: Only the console is accessible, user is NOT authenticated and goes straight into root with logging in.
2 - Multi-user mode - does not support NFS though
3 - Full multiuser mode (This is the typical level for a server without a GUI)
4 - This level is not currently used.
5 - X11 : This run level is used when the server has a desktop environment / GUI.
6 - Reboot: Simply reboot's the machine ('shutdown -r' call this)

You can go to a run level by using the init command - for example:

init 1

Will get you into runlevel 1 (single user mode.)

There are several configuration files related to init that I will highlight below.

/etc/inittab: This is where you can define a default init level e.g.:

id:3:initdefault:

and also where you define what to monitor when changing an init level and what is to be performed once completed.

/etc/rc.d: This directory contains a folder for each run level e.g. 'rc0.d' that then contains a series of scripts within them - either beginning with 'S' (indicating that we are entering this runlevel) or 'K' (indicating that we leaving this run level.)

/etc/rc.local: This is where you can add your own startup scripts.

Sometimes it is necessary to drop into single user mode - although you might not be able to get into the OS to configure this in the first place - a typical example is if you manage to forget your root password - rather than having to run a live cd, mount the fs and update the root password we could boot into single user mode of the OS by adding a line to the entry in the grub boot loader.

To do this we need to have console access - we should then hover over the entry in the grub boot loader and hit the 'a' key - this allows you to then append data to the kernel line - we want to add 'single' right at the end of the kernel line.

0 comments:

Post a comment