Previous Page | Next Page

  1. Introduction
  2. Boot Process
  3. Init and System Initialization
  4. rc.sysinit script
  5. rc script
  6. functions script
  7. Services
  8. apm daemon
  9. network startup
  10. The network script file
  11. The network-functions file
  12. Portmap startup
  13. Random initialization
  14. Syslog initialization
  15. Gated
  16. Atd
  17. cron initialization
  18. pcmcia
  19. inetd daemon
  20. named daemon
  21. lpd daemon
  22. mars-nwe
  23. netfs startup
  24. dhcpd daemon
  25. autofs daemon
  26. keytable daemon
  27. sendmail daemon
  28. gpm daemon
  29. httpd daemon
  30. xfs startup
  31. smb startup
  32. innd startup
  33. linuxconf startup
  34. rc.local script
  35. Init, Getty, Login
  36. The shell
  37. Shutting down
  38. X
  39. Conclusions
  40. App A. rc.sysinit listing
  41. App B. functions listing
  42. App C. rc listing
  43. Credits

Appendix A

Linux /etc/rc.d/rc.sysinit script program listing

1	#!/bin/sh
2	#
3	# /etc/rc.d/rc.sysinit - run once at boot time
4	#
5	# Taken in part from Miquel van Smoorenburg's bcheckrc.
6	#
7
8	# Rerun ourselves through initlog
9	if [ -z "$IN_INITLOG" ]; then
10	 [ -f /sbin/initlog ] && exec /sbin/initlog -r /etc/rc.d/rc.sysinit
11	fi
12
13	# Set the path
14	PATH=/bin:/sbin:/usr/bin:/usr/sbin
15	export PATH
16
17	# Read in config data.
18	if [ -f /etc/sysconfig/network ]; then
19	    . /etc/sysconfig/network
20	else
21	    NETWORKING=no
22	    HOSTNAME=localhost
23	fi
24
25	# Source functions
26	. /etc/rc.d/init.d/functions
27
28	# Fix console loglevel
29	/sbin/loglevel $LOGLEVEL
30
31	# Load keymap
32	KEYMAP=
33	if [ -f /etc/sysconfig/console/default.kmap ]; then
34	  KEYMAP=/etc/sysconfig/console/default.kmap
35	else
36	  . /etc/sysconfig/keyboard
37	  if [ -n "$KEYTABLE" -a -d "/usr/lib/kbd/keymaps" ]; then
38	     KEYMAP=$KEYTABLE
39	  fi
40	fi
41	if [ -n "$KEYMAP" ]; then 
42	  # Since this takes in/output from stdin/out, we can't use initlog
43	  echo -n "Loading default keymap"
44	  loadkeys $KEYMAP < /dev/tty0 > /dev/tty0 2&#^@/dev/null && \
45	     success "Loading default keymap" || failure "Loading default keymap"
46	  echo
47	fi   
48
49	# Load system font
50	if [ -x /sbin/setsysfont ]; then
51	    action "Setting default font" /sbin/setsysfont
52	fi
53
54	# Start up swapping.
55	action "Activating swap partitions" swapon -a
56
57	# Set the hostname.
58	action "Setting hostname ${HOSTNAME}" hostname ${HOSTNAME}
59
60	# Set the NIS domain name
61	if [ -n "$NISDOMAIN" ]; then
62	    action "Setting NIS domain name $NISDOMAIN" domainname $NISDOMAIN
63	else
64	    domainname ""
65	fi
66
67	if [ -f /fsckoptions ]; then
68		fsckoptions=`cat /fsckoptions`
69	    else
70		fsckoptions=
71	fi
72
73	if [ -f /forcefsck ]; then
74		fsckoptions="-f $fsckoptions"
75	fi
76
77	_RUN_QUOTACHECK=0
78	if [ ! -f /fastboot ]; then
79	        STRING="Checking root filesystem"
80		echo $STRING
81		initlog -c "fsck  -T -a $fsckoptions /"
82		rc=$?
83		
84		if [ "$rc" = "0" ]; then
85			success "$STRING"
86			echo
87		elif [ "$rc" = "1" ]; then
88		        passed "$STRING"
89			echo
90	        fi
91	
92	        # A return of 2 or higher means there were serious problems.
93		if [ $rc -gt 1 ]; then
94			failure "$STRING"
95			echo
96			echo
97			echo "*** An error occurred during the file system check."
98			echo "*** Dropping you to a shell; the system will reboot"
99			echo "*** when you leave the shell."
100
101			PS1="(Repair filesystem) \#"; export PS1
102			sulogin
103
104			echo "Unmounting file systems"
105			umount -a
106			mount -n -o remount,ro /
107			echo "Automatic reboot in progress."
108			reboot
109		elif [ "$rc" = "1" ]; then
110			_RUN_QUOTACHECK=1
111		fi
112	fi
113
114	# check for arguments 
115
116	mount -t proc /proc /proc
117
118	if grep -i nopnp /proc/cmdline >/dev/null ; then
119	    PNP=
120	else
121	    PNP=yes
122	fi
123
124	# set up pnp 
125	if [ -x /sbin/isapnp -a -f /etc/isapnp.conf ]; then
126	    if [ -n "$PNP" ]; then
127		action "Setting up ISA PNP devices" /sbin/isapnp /etc/isapnp.conf
128	    else
129		action "Skipping ISA PNP configuration at users request" /bin/true
130	    fi
131	fi
132
133	# Remount the root filesystem read-write.
134	action "Remounting root filesystem in read-write mode" mount -n -o remount,rw /
135
136	# Update quotas if fsck was run on /.
137	if [ X"$_RUN_QUOTACHECK" = X1 -a -x /sbin/quotacheck ]; then
138		action "Checking root filesystem quotas"  /sbin/quotacheck -v /
139	fi
140	# XXX Disabled to avoid complaints on root later with quotaon -a
141	#if [ -x /sbin/quotaon ]; then
142	#    action "Turning on user and group quotas for root filesystem"  /sbin/quotaon /
143	#fi
144
145	if [ -n "$IN_INITLOG" ]; then
146	    IN_INITLOG=
147	fi
148
149	if [ ! -f /etc/HOSTNAME ]; then
150	    echo ${HOSTNAME} > /etc/HOSTNAME
151	fi
152
153	# Clear mtab
154	>/etc/mtab
155
156	# Enter root and /proc into mtab.
157	mount -f /
158	mount -f /proc
159
160	if ! grep -i nomodules /proc/cmdline >/dev/null && [ -f /proc/ksyms ]; then
161	    USEMODULES=y
162	else
163	    USEMODULES=
164	fi
165
166	# Our modutils don't support it anymore, so we might as well remove
167	# the link.
168	rm -f /lib/modules/preferred
169	rm -f /lib/modules/default
170	if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then
171	    # Get ready for kmod if module support in the kernel
172	    if [ -z `uname -r | grep "-"` ]; then
173	       # we're using a new kernel, no preferred needed
174	       mver=`uname -r`
175	    else
176	       ktag="`cat /proc/version`"
177	       mtag=grep -l "$ktag" /lib/modules/*/.rhkmvtag 2> /dev/null
178	       if [ -n "$mtag" ]; then
179	          mver=echo $mtag | sed -e 's,/lib/modules/,,' -e 's,/.rhkmvtag,,' -e 's,[       ].*$,,'
180	       fi
181	       if [ -n "$mver" ]; then
182	         ln -sf /lib/modules/$mver /lib/modules/default
183	       fi
184	    fi
185	    [ -n "$mver" -a -f "/boot/module-info-$mver" ] && ln -sf /boot/module-info-$mver /boot/module-info
186	    [ -n "$mver" -a -f "/boot/System.map-$mver" ] && ln -sf /boot/System.map-$mver /boot/System.map
187	    action "Finding module dependencies" depmod -a
188	fi
189
190	# load sound modules
191	if [ -n "$USEMODULES" ]; then
192	   if grep -s -q "^alias sound" /etc/conf.modules ; then
193	      action "Loading sound module" modprobe sound
194	   fi
195	   if grep -s -q "^alias midi" /etc/conf.modules ; then
196	      action "Loading midi module" modprobe midi
197	   fi
198	fi
199
200	if [ -f /proc/sys/kernel/modprobe ]; then
201	   if [ -n "$USEMODULES" ]; then
202	       echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
203	   else
204	       echo "" > /proc/sys/kernel/modprobe
205	   fi
206	fi
207
208	# Add raid devices
209	if [ -f /proc/mdstat -a -f /etc/raidtab -a -x /sbin/raidadd ]; then
210		action "Starting up RAID devices" raidadd -a
211
212		rc=$?
213
214		if [ $rc = 0 ]; then
215			raidrun -a
216			rc=$?
217		fi
218
219		# A non-zero return means there were problems.
220		if [ $rc -gt 0 ]; then
221			echo
222			echo
223			echo "*** An error occurred during the RAID startup"
224			echo "*** Dropping you to a shell; the system will reboot"
225			echo "*** when you leave the shell."
226
227			PS1="(RAID Repair) \#"; export PS1
228			sulogin
229
230			echo "Unmounting file systems"
231			umount -a
232			mount -n -o remount,ro /
233			echo "Automatic reboot in progress."
234			reboot
235		fi
236	fi
237
238	# Check filesystems
239	if [ ! -f /fastboot ]; then
240	        STRING="Checking filesystems"
241		echo $STRING
242		initlog -c "fsck  -T -R -A -a $fsckoptions"
243		rc=$?
244		        if [ "$rc" = "0" ]; then
245				success "$STRING"
246				echo
247			elif [ "$rc" = "1" ]; then
248			        passed "$STRING"
249				echo
250			fi
251
252			# A return of 2 or higher means there were serious problems.
253			if [ $rc -gt 1 ]; then
254		        failure "$STRING"
255			echo
256			echo
257			echo "*** An error occurred during the file system check."
258			echo "*** Dropping you to a shell; the system will reboot"
259			echo "*** when you leave the shell."
260	
261			PS1="(Repair filesystem) \#"; export PS1
262			sulogin
263
264			echo "Unmounting file systems"
265			umount -a
266			mount -n -o remount,ro /
267			echo "Automatic reboot in progress."
268			reboot
269		elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
270			action "Checking filesystem quotas" /sbin/quotacheck -v -R -a
271		fi
272	fi
273
274	# Mount all other filesystems (except for NFS and /proc, which is already
275	# mounted). Contrary to standard usage,
276	# filesystems are NOT unmounted in single user mode.
277	action "Mounting local filesystems" mount -a -t nonfs,smbfs,ncpfs,proc
278
279	if [ -x /sbin/quotaon ]; then
280	    action "Turning on user and group quotas for local filesystems" /sbin/quotaon -a
281	fi
282
283	# Clean out /etc.
284	rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck
285	>/var/run/utmp
286	touch /var/log/wtmp
287	chgrp utmp /var/run/utmp /var/log/wtmp
288	chmod 0664 /var/run/utmp /var/log/wtmp
289
290	# Delete pam_console lock and refcount files
291	rm -f /var/lock/console.lock
292	rm -f /var/lock/console/*
293
294	# Delete UUCP lock files.
295	rm -f /var/lock/LCK*
296
297	# Delete stale subsystem files.
298	rm -f /var/lock/subsys/*
299
300	# Delete stale pid files
301	rm -f /var/run/*.pid
302
303	# Delete X locks
304	rm -f /tmp/.X*-lock
305
306	# Delete Postgres sockets
307	rm -f /tmp/.s.PGSQL.*
308
309	# Set the system clock.
310	ARC=0
311	UTC=0
312	if [ -f /etc/sysconfig/clock ]; then
313	    . /etc/sysconfig/clock
314
315	    # convert old style clock config to new values
316	    if [ "${CLOCKMODE}" = "GMT" ]; then
317		    UTC=true
318	    elif [ "${CLOCKMODE}" = "ARC" ]; then
319		    ARC=true
320	    fi
321	fi
322
323	CLOCKDEF=""
324	if [ -x /sbin/hwclock ]; then
325	    CLOCKFLAGS="--hctosys"
326	    CLOCK=/sbin/hwclock
327	    $CLOCK --adjust
328	else
329	    CLOCKFLAGS="-a"
330	    CLOCK=/sbin/clock
331	fi
332
333	case "$UTC" in
334	  yes|true)
335	    CLOCKFLAGS="$CLOCKFLAGS -u";
336	    CLOCKDEF="$CLOCKDEF (utc)";
337	  ;;
338	esac
339
340	if [ "$CLOCK" = "/sbin/clock" ]; then
341	 case "$ARC" in
342	   yes|true)
343	     CLOCKFLAGS="$CLOCKFLAGS -A";
344	     CLOCKDEF="$CLOCKDEF (arc)";
345	   ;;
346	 esac
347	fi
348
349	$CLOCK $CLOCKFLAGS
350	action "Setting clock $CLOCKDEF: `date`" date
351
352	# Right, now turn on swap in case we swap to files.
353	swapon -a >/dev/null 2>&1
354	action "Enabling swap space" /bin/true
355
356	# Initialize the serial ports.
357	if [ -f /etc/rc.d/rc.serial ]; then
358		. /etc/rc.d/rc.serial
359	fi
360
361	# Load modules (for backward compatibility with VARs)
362	if [ -f /etc/rc.d/rc.modules ]; then
363		/etc/rc.d/rc.modules
364	fi
365
366	# If a SCSI tape has been detected, load the st module unconditionally
367	# since many SCSI tapes don't deal well with st being loaded and unloaded
368	if [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi | grep -q 'Type:   Sequential-Access' 2>/dev/null ; then
369		if cat /proc/devices | grep -qv ' 9 st' ; then
370			if [ -n "$USEMODULES" ] ; then
371				# Try to load the module.  If it fails, ignore it...
372				modprobe st 2>/dev/null
373			fi
374		fi
375	fi
376	
377	# Set preferred X display manager link
378	preferred=
379	if [ -f /etc/sysconfig/desktop ]; then
380		if [ -n "`grep GNOME /etc/sysconfig/desktop`" ]; then
381			preferred=gdm
382		elif [ -n "`grep KDE /etc/sysconfig/desktop`" ]; then
383			preferred=kdm
384		elif [ -n "`grep AnotherLevel /etc/sysconfig/desktop`" ]; then
385			preferred=xdm
386		fi
387	fi
388	if [ -n "$preferred" ] && which $preferred >/dev/null 2>&1; then
389		ln -snf ../..`which $preferred` /etc/X11/prefdm 
390	else
391	        if [ ! -L /etc/X11/prefdm ]; then
392			if which gdm >/dev/null 2>&1; then
393				ln -snf ../..`which gdm` /etc/X11/prefdm
394			elif which kdm >/dev/null 2>&1; then
395				ln -snf ../..`which kdm` /etc/X11/prefdm
396			elif which xdm >/dev/null 2>&1; then
397				ln -snf ../..`which xdm` /etc/X11/prefdm
398			fi
399		fi
400	fi
401	
402	# Now that we have all of our basic modules loaded and the kernel going,
403	# let's dump the syslog ring somewhere so we can find it later
404	dmesg > /var/log/dmesg