Linux Post installation Activities

From Colwiki.org

Jump to: navigation, search

Outcomes

In this Module you will learn the activities that you can perform upon a basic Linux installation. More specifically, you will learn how:
  • To configure a Linux Boot Manager and the Linux Boot process (From Boot Loader to Bash) ; and
  • To configure peripheral devices including printers and networking



Terminologies

  • LILO Boot Loader:LILO (LInux LOader) is a generic boot loader for Linux.LILO was originally developed by Werner Almesberger. LILO does not depend on a specific file system, and can boot an operating system (e.g., Linux kernel images) from floppy disks and hard disks. One of up to sixteen different images can be selected at boot time. Various parameters, such as the root device, can be set independently for each kernel. LILO can be placed either in the master boot record (MBR) or the boot sector of a partition. In the latter case something else must be placed in the MBR to load LILO.
  • GRUB Boot loader: GNU GRUB is a very powerful boot loader, which can load a wide variety of free operating systems, as well as proprietary operating systems with chain-loading. GRUB is designed to address the complexity of booting a personal computer; both the program and this manual are tightly bound to that computer platform, although porting to other platforms may be addressed in the future.
  • Run Levels: The term runlevel refers to a mode of operation in one of the computer operating systems that implement Unix System V-style initialization. Conventionally, seven runlevels exist, numbered from zero to six; though up to ten, from zero to nine, may be used. S is sometimes used as a synonym for one of the levels.


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:

  1. 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----------------------------------
  1. Trap CTRL-ALT-DELETE

ca::ctrlaltdel:/sbin/shutdown -t3 -r now


snip----------------------------------
  1. 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

  1. 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:

  1. 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.
  2. 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 ...
  3. 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.
  4. 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:

  1. 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

  1. 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.


Summary

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.



Assignment

Take a look at the boot manpage, it covers most of what we did in this module.
  1. Change the system’s default run level to 3 and then 5. How do you know your current runlevel?
  2. Enable the Ctrl+Alt+Del in runlevel 3 only.
  3. Add a new login prompt on tty7. How can you force init to read its’ configuration file?
  4. Use dmesg to read the chipset of your ethernet card.
  5. Investigate differences between shutdown, halt and reboot. Which option to shutdown will force an fsck at the next boot?


Image:somerights20.png This work is licenced under a Creative Commons - By Attribution Licence - Share Alike License.

Personal tools
News & Events