Linux Post installation Activities
From Colwiki.org
In this Module you will learn the activities that you can perform upon a basic Linux installation. More specifically, you will learn how:
|
|
We first focus on the role of the init program and its' associated configuration file /etc/inittab. The role of LILO and the GRUB Bootloader at boot time is investigated in greater depth. Finally we summarize the booting process. The document "From Power to Bash Prompt" written by Greg O'Keefe as well as the boot(7) manpage are both good references for this module.
Contents |
Understanding Runlevels
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.
Listing - Linux runlevels Runlevel 0 shuts down the machine safely, Runlevel 6 restarts the machine safely Runlevel 1 is single user mode Runlevel 2 is multi-user mode, but does not start NFS Runlevel 3 is full multi-user mode Runlevel 4 is not defined and generally unused Runlevel 5 is like runlevel 3 but runs a Display Manager as well 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 been initialized at boot time. The PID for init is always 1.
Listing - The PID for init is always 1
[root@nasaspc /proc]# ps uax |grep init
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.2 0.0 1368 52 ? S 20:17 0:04 init [3]
At each runlevel the system will stop or start a set of specific services. These programs are kept in /etc/rc.d/init.d. This directory contains all the services that the system may run. Once these programs are launched they will stay active until a new runlevel is called. The following services are also called daemons.
Listing - List of typicalservices (or daemons) in /etc/rc.d/init.d/
ls /etc/rc.d/init.d/ anacron cups identd kadmin krb5kdc mcserv nscd random smb xfs apmd dhcpd innd kdcrotate kudzu named ntpd rawdevices snmpd xinetd arpwatch functions ipchains keytable ldap netfs pcmcia rhnsd squid atd gpm iptables killall linuxconf network portmp rwhod sshd autofs halt irda kprop lpd nfs pgsql sendmail syslog crond httpd isdn krb524 marsrv nfslock pppoe single tux
Note: It is possible to stop or start manually a given daemon in /etc/rc.d/init.d by giving the appropriate argument. For example if you want to restart the apache server you would type:
/etc/rc.d/init.d/httpd restart
When working with runlevels you will instruct a specific predefined set of programs to run and another predefined set of programs to stop running. Say you want to be in runlevel 2, you would type
/sbin/init 2 This in turn forces init to read its configuration file /etc/inittab to find out what should happen at this runlevel. In particular (assuming we are switching to runlevel 2) the following line in inittab is executed:
l2:wait:/etc/rc.d/rc 2
If you look in /etc/inittab the “/etc/rc.d/rc N” command starts all services in the /etc/rc.d/rcN.d starting with an S and will stop of services starting with a K. These services are symbolic links pointing to the rc-scripts in /etc/rc.d/init.d. If you don't want a process to run in a given runlevel N you can delete the corresponding symlink in /etc/rc.d/rN.d beginning with a K.
The Joys of inittab
As promised let's take a look at /etc/inttab. The file has the following structure: id : runlevel : action : command the /etc/inittab file:
id:3:initdefault:
- System initialization.
si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6
snip----------------------------------
- Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
snip----------------------------------
- Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6
- Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm –nodaemon
The id field can be anything. If a runlevel is specified then the command and the required action will be performed only at that specific runlevel. If no number is specified then the line is executed at any run level.
Recognisable features in the /etc/inittab file:
- The default runlevel: this is set at the beginning of the file with the id id and the action initdefault. Notice that no command is given. This line simply tells init what the default runlevel is.
- First program called by init: /etc/rc.d/rc.sysinit. This script sets system defaults such as the PATH variable, determines if networking is allowed, the hostname, etc ...
- Default runlevel services: If the default runlevel is 3 then only the line "l3" will be executed. The action is "wait", no other program is launched until all services in run level 3 are running.
- The getty terminals: The lines with id's 1-to-6 launch the virtual terminals. This is where you can alter the number of virtual terminals.
Runlevel 5: The final line in inittab launches the Xwindow manager if runlevel 5 is reached.
Remarks:
- You can set a modem to listen for connections in inittab. If your modem is linked to /dev/ttyS1 then the following line will allow data connections (no fax) after 2 rings:
S1:12345:respawn:/sbin/mgetty -D -x 2 /dev/ttyS1
- When making changes to /etc/inittab you need to force init to reread this configuration file. This is most easily done using:
/sbin/init q
From Boot to Bash
We can now attempt to go through the steps a Linux system goes through while booting. If an initial ram disk is specified it is loaded here. Modules are inserted from the initial ram disk. The kernel is loaded from the medium, specified in LILO's configuration. As it loads it is decompressed. The kernel then mounts the root (/) filesystem in accordance with the configuration it receives from LILO (usually read-only). Hence essential programs in /bin and /sbin are made available. The kernel then loads init - the first 'userspace' process. Init reads /etc/inittab and follows its' instructions. In particular rc.sysinit is run. A filesystem integrity check (fsck) is done on the filesystems in accordance with entries in /etc/fstab. Next init goes into the default runlevel, the gettys start and the boot process is over. The prompt to login is now managed by the gettys on the ttys. After the user has typed in their username and pressed return;/bin/login is started. The user is prompted by /bin/login for the password. The user enters a password and presses return. The password the user is compared to the password in /etc/passwd or /etc/shadow.
| In order to effectively utilize Linux computing resources, most system administrators will prefer to establish “lean and mean” machines which run the necessary Linux services to be able to achieve what is required of them. This is possible through the use of runlevels. Services not required, which belong to different run levels, can be disabled or activated by changing the run levels.
In this module you have also learned how to control the boot process and customize it to your requirements. |
Take a look at the boot manpage, it covers most of what we did in this module.
|
This work is licenced under a Creative Commons - By Attribution Licence - Share Alike License.

