]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- support exit code defined in LSB spec (http://www.linuxbase.org/)
[projects/rc-scripts.git] / rc.d / rc.sysinit
1 #!/bin/sh
2 #
3 # /etc/rc.d/rc.sysinit - run once at boot time
4 # $Id: rc.sysinit,v 1.48 2000/02/28 12:50:45 misiek Exp $
5 #
6 # Taken in part from Miquel van Smoorenburg's bcheckrc.
7 # Changes:      Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
8 #
9
10 # Set the path
11 PATH=/bin:/sbin:/usr/bin:/usr/sbin
12 export PATH
13
14 # NLS
15 if [ -f /etc/sysconfig/i18n ]; then
16         . /etc/sysconfig/i18n
17         [ -n "$LANG" ] && export LANG || unset LANG
18         [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
19         [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
20         [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
21         [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
22         [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
23         [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
24         [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
25         [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
26         [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
27 fi
28
29 # Read functions
30 . /etc/rc.d/init.d/functions
31
32 # Read network config data.
33 if [ -f /etc/sysconfig/network ]; then
34         . /etc/sysconfig/network
35 else
36         NETWORKING=no
37         HOSTNAME=localhost
38 fi
39
40 # Read system config data.
41 if [ -f /etc/sysconfig/system ]; then
42         . /etc/sysconfig/system
43 else
44         RUN_SULOGIN_ON_ERR=yes
45         RUN_ISAPNP=yes
46         PANIC_REBOOT_TIME=0
47         DELAY_LOGIN=yes
48         CLEAN_TMP=no
49         CONSOLE_LOGLEVEL=1
50         LOAD_SOUND=yes
51         SET_SLINKS=yes
52         RUN_LDCONFIG=yes
53 fi
54
55 # Print welcome message
56 echo -e "\t\t\t`termput setaf 6` Powered by `termput setaf 2`PLD/Linux`termput setaf 7`"
57
58 # set up devfsd
59 if [ -x /sbin/devfsd -a -f /etc/devfsd.conf ]; then
60         if [ "$RUN_DEVFSD" = "yes" ]; then
61                 run_cmd "Starting Device Filesystem Daemon" /sbin/devfsd /dev
62         fi
63 fi
64
65 # Set console loglevel
66 /bin/dmesg -n $CONSOLE_LOGLEVEL
67
68 # we need /proc mounted before starting fsck
69 mount -n -t proc /proc /proc
70
71 # Start up swapping.
72 run_cmd "`nls "Activating swap partitions"`" swapon -a
73
74 # Set the hostname.
75 run_cmd "`nls "Host:"` ${HOSTNAME}" hostname ${HOSTNAME}
76
77 # Set the NIS domain name
78 if [ -n "$NISDOMAIN" ]; then
79         run_cmd "`nls "NIS Domain:"` ${NISDOMAIN}" domainname $NISDOMAIN
80 else
81         domainname ""
82 fi
83
84 if [ -f /fsckoptions ]; then
85         fsckoptions=`cat /fsckoptions`
86 else
87         fsckoptions=''
88 fi
89
90 if [ -f /forcefsck ]; then
91         fsckoptions="-f $fsckoptions"
92 fi
93
94 # Test for NFS Root
95 NFSROOT=`cat /proc/mounts | awk '{ if ($2 ~ /^\/$/ && $3 ~ /^nfs$/) print $3 }'`
96
97 _RUN_QUOTACHECK=0
98 if [ ! -f /fastboot -a ! -n "$NFSROOT" ]; then
99         show "Checking root filesystems."; started
100         initlog -c "fsck -C -T -a $fsckoptions /"
101
102         rc=$?
103
104         # A return of 2 or higher means there were serious problems.
105         if [ $rc -gt 1 ]; then
106                 # don't use '\n' in nls macro !
107                 echo "\n\n"
108                 nls "*** An error occurred during the file system check."
109                 nls "*** Dropping you to a shell; the system will reboot"
110                 nls "*** when you leave the shell."
111                 echo
112
113                 PS1="`nls "(Repair filesystem)# "`"; export PS1
114                 if [ "$RUN_SULOGIN_ON_ERR" = "yes" ]; then
115                         sulogin
116                 else
117                         /bin/sh
118                 fi
119
120                 run_cmd "Unmounting file systems" umount -a
121                 mount -n -o remount,ro /
122                 run_cmd "Automatic reboot in progress." reboot
123         elif [ "$rc" = "1" ]; then
124                 _RUN_QUOTACHECK=1
125         fi
126 fi
127
128 # check for arguments 
129 if grep -i nopnp /proc/cmdline >/dev/null ; then
130         PNP=
131 else
132         PNP=yes
133 fi
134
135 # set up pnp 
136 if [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
137         if [ -n "$PNP" -a "$RUN_ISAPNP" = "yes" ]; then
138                 run_cmd "Setting up ISA PNP devices" /sbin/isapnp /etc/isapnp/isapnp.conf
139         fi
140 fi
141
142
143 # Remount the root filesystem read-write.
144 run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
145
146 # Update quotas if fsck was run on /.
147 if [ X"$_RUN_QUOTACHECK" = "X1" -a -x /sbin/quotacheck -a ! -n "$NFSROOT" ]; then
148         run_cmd "Checking root filesystem quotas" /sbin/quotacheck -v /
149 fi
150
151 # /etc/nologin when starting system
152 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
153
154 if [ "$DELAY_LOGIN" = "yes" -a ! -f /etc/nologin ]; then
155         show "Enabling Delay Login"; busy
156         echo > /etc/nologin
157         nls "System bootup in progress  - please wait" >> /etc/nologin
158         echo >> /etc/nologin
159         chmod 644 /etc/nologin
160         cp -fp /etc/nologin /etc/nologin.boot
161         deltext; ok
162 fi
163
164 echo ${HOSTNAME} > /etc/HOSTNAME
165
166 # Clear mtab
167 >/etc/mtab
168
169 # Enter root and /proc into mtab.
170 mount -f /
171 mount -f /proc
172
173 if ! grep -i nomodules /proc/cmdline >/dev/null && [ -f /proc/ksyms ]; then
174         USEMODULES=y
175 else
176         USEMODULES=
177 fi
178
179 # Kernel dependent links
180 rm -f /lib/modules/preferred
181 rm -f /lib/modules/default
182 if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then
183         if [ "$SET_SLINKS" != "no" ]; then
184         # Get ready for kmod if module support in the kernel
185                 if [ -z `uname -r | grep "-"` ]; then
186                 # we're using a new kernel, no preferred needed
187                         mver=`uname -r`
188                 else
189                         ktag="`cat /proc/version`"
190                         mtag=grep -l "$ktag" /lib/modules/*/.rhkmvtag 2> /dev/null
191                         if [ -n "$mtag" ]; then
192                                 mver=echo $mtag | sed -e 's,/lib/modules/,,' -e 's, \
193                                         /.rhkmvtag,,' -e 's,[       ].*$,,'
194                         fi
195                         if [ -n "$mver" ]; then
196                                 ln -sf /lib/modules/$mver /lib/modules/default
197                         fi
198                 fi
199         fi
200         [ -n "$mver" -a -f "/boot/module-info-$mver" ] && \
201                 ln -sf /boot/module-info-$mver /boot/module-info
202         [ -n "$mver" -a -f "/boot/System.map-$mver" ] && \
203                 ln -sf /boot/System.map-$mver /boot/System.map
204
205         # Run depmod if: a) user requested; b) modules.dep is missing
206         # c) modules.dep is older than /etc/modules.conf
207         if [ "$RUN_DEPMOD" != "no" ]; then
208                 if [ "$RUN_DEPMOD" = "ifmissing" -a ! -r /lib/modules/$mver/modules.dep ] || (find /lib/modules/$mver/ -name modules.dep ! -newer /etc/modules.conf -print 2>&1 | grep -q "modules.dep"); then
209                         run_cmd "Finding module dependencies" depmod -a
210                 fi
211         fi
212 fi
213
214 # load sound modules
215 if [ -n "$USEMODULES" -a "$LOAD_SOUND" = "yes" ]; then
216         if grep -s -q "^alias sound" /etc/modules.conf ; then
217                 run_cmd "Loading sound module" modprobe -s sound
218         fi
219         if grep -s -q "^alias midi" /etc/modules.conf ; then
220                 run_cmd "Loading midi module" modprobe -s midi
221         fi
222 fi
223
224 if [ -f /proc/sys/kernel/modprobe ]; then
225         # /proc/sys/kernel/modprobe indicates built-in kmod instead
226         echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
227 fi
228
229 # Load modules
230 if [ -f /etc/rc.d/rc.modules ]; then
231         /etc/rc.d/rc.modules
232 fi
233
234 # Add raid devices
235 if [ -f /proc/mdstat -a -f /etc/raidtab ]; then
236         show "Starting up RAID devices."; started
237
238         rc=0
239         
240         for i in `grep "raiddev" /etc/raidtab | awk '{print $2}'`
241         do
242                 RAIDDEV=`basename $i`
243                 RAIDSTAT=`grep "^$RAIDDEV : active" /proc/mdstat`
244                 if [ -z "$RAIDSTAT" ]; then
245                         # Try raidstart first...if that fails then
246                         # fall back to raid0run.
247                         RESULT=1
248                         if [ -x /sbin/raidstart ]; then
249                                 /sbin/raidstart $i
250                                 RESULT=$?
251                         fi
252                         if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
253                                 /sbin/raid0run $i
254                         fi
255                 fi
256         done
257
258         # A non-zero return means there were problems.
259         if [ $rc -gt 0 ]; then
260                 show "Starting up RAID devices."; fail
261                 echo "\n\n"
262                 nls "*** An error occurred during the RAID startup"
263                 nls "*** Dropping you to a shell; the system will reboot"
264                 nls "*** when you leave the shell."
265                 echo
266
267                 PS1="`nls "(RAID Repair)# "`"; export PS1
268                 if [ "$RUN_SULOGIN_ON_ERR" = "yes" ]; then
269                         sulogin
270                 else
271                         /bin/sh
272                 fi
273
274                 run_cmd "Unmounting file systems" umount -a
275                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
276                 run_cmd "Automatic reboot in progress" reboot
277         fi
278         show "Starting up RAID devices."; ok
279 fi
280
281 # Check filesystems
282 if [ ! -f /fastboot ]; then
283         show "Checking filesystems."; started
284         initlog -c "fsck -C -T -R -A -a $fsckoptions"
285
286         rc=$?
287
288         # A return of 2 or higher means there were serious problems.
289         if [ $rc -gt 1 ]; then
290                 echo "\n\n"
291                 nls "*** An error occurred during the file system check."
292                 nls "*** Dropping you to a shell; the system will reboot"
293                 nls "*** when you leave the shell."
294                 echo
295
296                 PS1="`nls "(Repair filesystem)# "`"; export PS1
297                 if [ "$RUN_SULOGIN_ON_ERR" = "yes" ]; then
298                         sulogin
299                 else
300                         /bin/sh
301                 fi
302
303                 run_cmd "Unmounting file systems" umount -a
304                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
305                 run_cmd "Automatic reboot in progress." reboot
306         elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
307                 run_cmd "Checking filesystem quotas" /sbin/quotacheck -v -R -a
308         fi
309 fi
310
311 # Mount all other filesystems (except for NFS and /proc, which is already
312 # mounted). Contrary to standard usage,
313 # filesystems are NOT unmounted in single user mode.
314 run_cmd "Mounting local filesystems." mount -a -t nonfs,smbfs,ncpfs,proc
315
316 # set the console font
317 #if [ -x /sbin/setsysfont ]; then
318 #       show "Loading default system font"; busy
319 #       if (/sbin/setsysfont > /dev/null 2>&1); then deltext; ok; else deltext; fail; fi
320 #fi
321
322 if [ -x /sbin/quotaon ]; then
323         run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -a
324 fi
325
326 # Clean out /etc & /var/{run/*,log/{b,w}tmpx}}.
327 rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck
328 rm -f /var/run/utmp  
329 :>/var/run/utmpx
330 chown root.utmp /var/run/utmpx
331 chmod 0664 /var/run/utmpx
332
333 # Clean /tmp
334 if [ "$CLEAN_TMP" = "yes" ]; then
335         rm -rf /tmp/*
336 fi
337
338 # Delete UUCP lock files.
339 rm -f /var/lock/LCK*
340
341 # Delete stale subsystem files.
342 rm -f /var/lock/subsys/*
343
344 # Delete stale pam_console locks.
345 rm -f /var/lock/console/*
346 rm -f /var/lock/console.lock
347
348 # Delete stale pid files
349 rm -f /var/run/*.pid
350 rm -f /var/spool/postoffice/.pid.*
351
352 # Delete X locks
353 rm -f /tmp/.X*-lock
354
355 # Delete Postgres sockets
356 rm -f /tmp/.s.PGSQL.*
357
358 # Set the system clock.
359 show "Setting clock"; busy
360
361 ARC=0
362 UTC=0
363 if [ -f /etc/sysconfig/clock ]; then
364         . /etc/sysconfig/clock
365
366         # convert old style clock config to new values
367         if [ "${CLOCKMODE}" = "GMT" ]; then
368                 UTC=true
369         elif [ "${CLOCKMODE}" = "ARC" ]; then
370             ARC=true
371         fi
372 fi
373
374 if [ -x /sbin/hwclock ]; then
375         CLOCKFLAGS="--hctosys"
376         CLOCK=/sbin/hwclock
377 else
378         CLOCKFLAGS="-a"
379         CLOCK=/sbin/clock
380 fi
381
382 case "$UTC" in
383   yes|true)
384         CLOCKFLAGS="$CLOCKFLAGS -u";
385 #       echo -n " (utc)"
386         ;;
387 esac
388
389 case "$ARC" in
390   yes|true)
391         CLOCKFLAGS="$CLOCKFLAGS -A";
392 #       echo -n " (arc)"
393         ;;
394 esac
395
396 #echo -n ": "
397 if ($CLOCK $CLOCKFLAGS); then deltext; ok; else deltext; fail; fi
398
399 show "`nls "Date set to"` `date`"; ok
400
401 # Right, now turn on swap in case we swap to files.
402 swapon -a >/dev/null 2>&1
403 run_cmd "Enabling swap space" /bin/true
404 #show "Enabling swap space"; busy
405 #if [ "`LANG=C swapon -a 2>&1 | grep -v "busy"`" = "" ]; then
406 #       deltext; ok
407 #else
408 #       deltext; fail
409 #fi
410
411 # Initialize the serial ports.
412 if [ -f /etc/rc.d/rc.serial ]; then
413         . /etc/rc.d/rc.serial
414 fi
415
416 # If a SCSI tape has been detected, load the st module unconditionally
417 # since many SCSI tapes don't deal well with st being loaded and unloaded
418 if [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi | grep -q 'Type:   Sequential-Access' 2>/dev/null ; then
419         if cat /proc/devices | grep -qv ' 9 st' ; then
420                 if [ -n "$USEMODULES" ] ; then
421                         # Try to load the module.  If it fails, ignore it...
422                         insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
423                 fi
424         fi
425 fi
426
427 # there could be a new kernel version.  reinit /etc/psdevtab, to be sure.
428 rm -f /etc/psdevtab
429 #if [ -x /bin/ps ]; then
430 #show "Rebuilding /etc/psdevtab database"; busy
431 #if (ps > /dev/null 2>&1); then deltext; ok; else deltext; fail; fi
432 #fi
433
434 if ([ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ] 2>/dev/null); then
435 show "`nls "Sending val. %s to /proc/sys/kernel/panic" "$PANIC_REBOOT_TIME"`"; busy
436 if (echo $PANIC_REBOOT_TIME > /proc/sys/kernel/panic); then deltext; ok; else deltext; fail; fi
437 fi
438
439 # Now that we have all of our basic modules loaded and the kernel going,
440 # let's dump the syslog ring somewhere so we can find it later
441 dmesg > /var/log/dmesg
442 chmod 640 /var/log/dmesg
443
444 # Feed entropy into the entropy pool
445 /etc/rc.d/init.d/random start
This page took 0.083815 seconds and 3 git commands to generate.