4 Booting Linux “Repeated reboots of the system failed to solve the problem ”
5.1 init and telinit
init runs all the processes that run on your Linux system. The collection of processes started by init is the runlevel, and each runlevel corresponds to the scripts /etc/rc.d/rc?.d/S* (with the
? replaced by a number from 0 to 6).
When you change the runlevel, init runs a script which stops all the extra processes in the current runlevel, and starts the required processes from the new runlevel. To see the current and previous runlevel, the command is runlevel.
linux:~ # runlevel
N 5
linux:~ # init 3
linux:~ # tail -1 /var/log/messages
Jun 2 09:55:08 linux init: Switching to runlevel: 3 linux:~ # runlevel
5 3
linux:~ # ps -C kdm
PID TTY TIME CMD
The effect of changing to runlevel 3, was to stop kdm (which was running). When we change back to runlevel 5, kdm is started.
linux:~ # init 5
linux:~ # ps -C kdm
PID TTY TIME CMD 2991 ? 00:00:00 kdm 2995 ? 00:00:00 kdm
5.2 shutdown
shutdown is for shutting down your system.
linux:~ # shutdown
Usage: shutdown [-akrhfnc] [-t secs] time [warning message] -a: use /etc/shutdown.allow
-k: don't really shutdown, only warn. -r: reboot after shutdown.
-h: halt after shutdown.
-z: shutdown using software suspend. -f: do a 'fast' reboot (skip fsck). -F: Force fsck on reboot.
-n: do not go through "init" but go down real fast.
-c: cancel a running shutdown.
-t secs: delay between warning and kill signal. ** the "time" argument is mandatory! (try "now") **
The reason to use shutdown, rather than init 6 to reboot or init 0 is so that the shutdown can happen at a time determined by the administrator.
linux:~ # date
Mon Jun 2 10:12:49 SAST 2003
linux:~ # shutdown -r -t 10 10:14 # reboot at 10:14 AM
Broadcast message from root (pts/0) (Mon Jun 2 10:13:02 2003): The system is going DOWN for reboot in 1 minute!
<Press Ctrl+C to kill shutdown
Shutdown cancelled.
linux:~ # shutdown -r -t 10 10:14
Broadcast message from root (pts/0) (Mon Jun 2 10:13:11 2003): The system is going DOWN for reboot in 1 minute!
A little bit later...
Broadcast message from root (pts/0) (Mon Jun 2 10:14:11 2003): The system is going down for reboot NOW!
At this point, shutdown exits, but the current runlevel has changed to 6, as if telinit t 10 6 had been run (which is more or less what happened). At this point, the system is busy shutting down. (Hey, you can reboot a system when logged in remotely!)
linux:~ # runlevel
5 6
linux:~ # Read from remote host 192.168.1.191: Connection reset by peer
Connection to 192.168.1.191 closed.
5.3 inittab
When /sbin/init is started by the kernel, it reads /etc/inittab to determine the startup sequence. These are the lines that determine the startup behaviour of your system.
The initdefault specification specifies the default runlevel at startup (unless overridden by kernel parameters). Remember that the meaning of runlevels is not uniform between distributions.
5 Change runlevels LPI 102 Course Notes 41
# 1 - Single user mode (for maintenance, e.g. reiserfsck) # 2 - Multiuser, without NFS
# 3 - Full multiuser mode # 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this) id:5:initdefault:
Before thinking about runlevels, init runs the sysinit script.
# System initialization. si::sysinit:/etc/rc.d/rc.sysinit For the actual runlevel which is chosen, a script is run – in this case /etc/rc.d/rc 5. 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
And when you are in runlevel 2 ,3 , 4 and 5, init makes sure that the following programs are always running (mingetty handles terminal login, and mgetty handles modem dialin access.)
1:2345:respawn:/sbin/mingetty --noclear 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 s0:2345:respawn:/sbin/mgetty -x 3 ttyS0
5.4 Review
Quiz questions 1. How do you schedule a reboot in one hour from now? 2. Which parameter in which file changes the default runlevel of your system? 3. What is the purpose of single user mode? 4. What mechanism is used to alert users of an impending shutdown? 5. How does init terminate processes (i.e. which signals)?Assignments 1. Switch to single user mode and modify your root password. Check which processes are running in single user mode. After this switch to multiuser mode again. 2. Schedule a shutdown which will occur in 1 minute. Once the shutdown has started, cancel it. Observe the effect that this has on a) a user who is logged in at a console b)a user who is logged in using X
c) a user who is logged in using ssh or telnet
3. Configure your system with a different default runlevel (e.g. boot multiuser without X). Document the steps you took to do this.
Answers to quiz questions
1. Using shutdown (or at if you care to). 2. initdefault in /etc/inittab
3. System maintenance without interference by other users and programs 4. Console broadcast
6 Print queues LPI 102 Course Notes 43
6 Print queues
Line printer paper is strongest at the perforations.LPIC topic 1.107.2 — Manage printers and print queues [1]
Weight: 1 Objective The candidate should be able to manage print queues and user print jobs. This objective includes monitoring print server and user print queues and troubleshooting general printing problems. Key files, terms, and utilities include lpc line printer control lpq show the line printer queue lprm remove jobs from the line printer queue lpr line printer submit a job /etc/printcap lpd configuration file6.1 lpd, lpr, lpq and lprm
Originally, most printing on Unix systems was done with line printers. The “lp” of “line printer”' has survived into the new millennium, even though it is now rather difficult to get access to a genuine line printer. The unix printing system consists of a few components: lpd – lpd is the queue manager. It sits patiently in the background waiting for someone to want something printed. Print jobs that are submitted to lpd are queued, and printed in more or less the order in which they were requested. lpd is configured by the file /etc/printcap, which names the printers connected to the machine, and describes the filters and parameters for each printer.lpr – lpr is used to add jobs to the printer queue. The standard method of printing a postscript file is the command lpr. If you have a second printer named lp1, you can print to it with lpr P lp1.
lpr filename.ps
lpr -P lp1 filename.ps
lpq, lprm – these commands are used to control the print queue. lpq displays a list of jobs for the default printer, and lpq P lp1 will display the list for a printer named jerry. lprm will remove a print job from the queue. It is possible to remove a job based on its job id, or alternatively, to remove all jobs for a user. foo:~ $ lpq -P lp1 lp1 is ready no entries foo:~ $ lpr -P lp1 < /etc/passwd foo:~ $ lpq -P lp1
lp1 is ready and printing
Rank Owner Job File(s) Total Size active donaldd 1214 (stdin) 2048 bytes foo:~ $ lpr -P lp1 < /etc/passwd
foo:~ $ lpr -P lp1 < /etc/passwd
foo:~ $ lpq -P lp1
lp1 is ready and printing
Rank Owner Job File(s) Total Size active donaldd 1214 (stdin) 2048 bytes 1st donaldd 1215 (stdin) 2048 bytes 2nd donaldd 1216 (stdin) 2048 bytes foo:~ $ lprm -P lp1 1216 1215
foo:~ $ lpq -P lp1
lp1 is ready and printing
Rank Owner Job File(s) Total Size active donaldd 1214 (stdin) 2048 bytes foo:~ $ lprm -P lp1 1214
foo:~ $ lpq -P lp1
lp1 is ready no entries
lpc – the lpc command provides a mechanism to talk the lpd process while it is running. In some implementations, lpc can be used to adjust the priority of messages, and to restart the print system. The most common use of lpc is to show the status of all printers.
# lpc help # your lpc may have
more
Commands may be abbreviated. Commands are: exit help quit status ?
# lpc status
lp0:
printer is on device 'parallel' speed -1 queuing is enabled
printing is enabled no entries
daemon present lp1:
printer is on device 'lpd' speed -1 queuing is enabled
printing is enabled no entries
daemon present
# lpc restart # hit lpd with a big hammer # lpc topq # make a job jump the queue