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