]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- run devfsd before all
[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.47 2000/02/18 09:13:26 wiget 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         if [ "$RUN_DEPMOD" = "yes" ] || [ "$RUN_DEPMOD" = "ifmissing" -a ! -r /lib/modules/$mver/modules.dep ]; then
206                 run_cmd "Finding module dependencies" depmod -a
207         fi
208 fi
209
210 # load sound modules
211 if [ -n "$USEMODULES" -a "$LOAD_SOUND" = "yes" ]; then
212         if grep -s -q "^alias sound" /etc/modules.conf ; then
213                 run_cmd "Loading sound module" modprobe -s sound
214         fi
215         if grep -s -q "^alias midi" /etc/modules.conf ; then
216                 run_cmd "Loading midi module" modprobe -s midi
217         fi
218 fi
219
220 if [ -f /proc/sys/kernel/modprobe ]; then
221         # /proc/sys/kernel/modprobe indicates built-in kmod instead
222         echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
223 fi
224
225 # Load modules
226 if [ -f /etc/rc.d/rc.modules ]; then
227         /etc/rc.d/rc.modules
228 fi
229
230 # Add raid devices
231 if [ -f /proc/mdstat -a -f /etc/raidtab ]; then
232         show "Starting up RAID devices."; started
233
234         rc=0
235         
236         for i in `grep "raiddev" /etc/raidtab | awk '{print $2}'`
237         do
238                 RAIDDEV=`basename $i`
239                 RAIDSTAT=`grep "^$RAIDDEV : active" /proc/mdstat`
240                 if [ -z "$RAIDSTAT" ]; then
241                         # Try raidstart first...if that fails then
242                         # fall back to raid0run.
243                         RESULT=1
244                         if [ -x /sbin/raidstart ]; then
245                                 /sbin/raidstart $i
246                                 RESULT=$?
247                         fi
248                         if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
249                                 /sbin/raid0run $i
250                         fi
251                 fi
252         done
253
254         # A non-zero return means there were problems.
255         if [ $rc -gt 0 ]; then
256                 show "Starting up RAID devices."; fail
257                 echo "\n\n"
258                 nls "*** An error occurred during the RAID startup"
259                 nls "*** Dropping you to a shell; the system will reboot"
260                 nls "*** when you leave the shell."
261                 echo
262
263                 PS1="`nls "(RAID Repair)# "`"; export PS1
264                 if [ "$RUN_SULOGIN_ON_ERR" = "yes" ]; then
265                         sulogin
266                 else
267                         /bin/sh
268                 fi
269
270                 run_cmd "Unmounting file systems" umount -a
271                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
272                 run_cmd "Automatic reboot in progress" reboot
273         fi
274         show "Starting up RAID devices."; ok
275 fi
276
277 # Check filesystems
278 if [ ! -f /fastboot ]; then
279         show "Checking filesystems."; started
280         initlog -c "fsck -C -T -R -A -a $fsckoptions"
281
282         rc=$?
283
284         # A return of 2 or higher means there were serious problems.
285         if [ $rc -gt 1 ]; then
286                 echo "\n\n"
287                 nls "*** An error occurred during the file system check."
288                 nls "*** Dropping you to a shell; the system will reboot"
289                 nls "*** when you leave the shell."
290                 echo
291
292                 PS1="`nls "(Repair filesystem)# "`"; export PS1
293                 if [ "$RUN_SULOGIN_ON_ERR" = "yes" ]; then
294                         sulogin
295                 else
296                         /bin/sh
297                 fi
298
299                 run_cmd "Unmounting file systems" umount -a
300                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
301                 run_cmd "Automatic reboot in progress." reboot
302         elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
303                 run_cmd "Checking filesystem quotas" /sbin/quotacheck -v -R -a
304         fi
305 fi
306
307 # Mount all other filesystems (except for NFS and /proc, which is already
308 # mounted). Contrary to standard usage,
309 # filesystems are NOT unmounted in single user mode.
310 run_cmd "Mounting local filesystems." mount -a -t nonfs,smbfs,ncpfs,proc
311
312 # set the console font
313 #if [ -x /sbin/setsysfont ]; then
314 #       show "Loading default system font"; busy
315 #       if (/sbin/setsysfont > /dev/null 2>&1); then deltext; ok; else deltext; fail; fi
316 #fi
317
318 if [ -x /sbin/quotaon ]; then
319         run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -a
320 fi
321
322 # Clean out /etc & /var/{run/*,log/{b,w}tmpx}}.
323 rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck
324 rm -f /var/run/utmp  
325 :>/var/run/utmpx
326 chown root.utmp /var/run/utmpx
327 chmod 0664 /var/run/utmpx
328
329 # Clean /tmp
330 if [ "$CLEAN_TMP" = "yes" ]; then
331         rm -rf /tmp/*
332 fi
333
334 # Delete UUCP lock files.
335 rm -f /var/lock/LCK*
336
337 # Delete stale subsystem files.
338 rm -f /var/lock/subsys/*
339
340 # Delete stale pam_console locks.
341 rm -f /var/lock/console/*
342 rm -f /var/lock/console.lock
343
344 # Delete stale pid files
345 rm -f /var/run/*.pid
346 rm -f /var/spool/postoffice/.pid.*
347
348 # Delete X locks
349 rm -f /tmp/.X*-lock
350
351 # Delete Postgres sockets
352 rm -f /tmp/.s.PGSQL.*
353
354 # Set the system clock.
355 show "Setting clock"; busy
356
357 ARC=0
358 UTC=0
359 if [ -f /etc/sysconfig/clock ]; then
360         . /etc/sysconfig/clock
361
362         # convert old style clock config to new values
363         if [ "${CLOCKMODE}" = "GMT" ]; then
364                 UTC=true
365         elif [ "${CLOCKMODE}" = "ARC" ]; then
366             ARC=true
367         fi
368 fi
369
370 if [ -x /sbin/hwclock ]; then
371         CLOCKFLAGS="--hctosys"
372         CLOCK=/sbin/hwclock
373 else
374         CLOCKFLAGS="-a"
375         CLOCK=/sbin/clock
376 fi
377
378 case "$UTC" in
379   yes|true)
380         CLOCKFLAGS="$CLOCKFLAGS -u";
381 #       echo -n " (utc)"
382         ;;
383 esac
384
385 case "$ARC" in
386   yes|true)
387         CLOCKFLAGS="$CLOCKFLAGS -A";
388 #       echo -n " (arc)"
389         ;;
390 esac
391
392 #echo -n ": "
393 if ($CLOCK $CLOCKFLAGS); then deltext; ok; else deltext; fail; fi
394
395 show "`nls "Date set to"` `date`"; ok
396
397 # Right, now turn on swap in case we swap to files.
398 swapon -a >/dev/null 2>&1
399 run_cmd "Enabling swap space" /bin/true
400 #show "Enabling swap space"; busy
401 #if [ "`LANG=C swapon -a 2>&1 | grep -v "busy"`" = "" ]; then
402 #       deltext; ok
403 #else
404 #       deltext; fail
405 #fi
406
407 # Initialize the serial ports.
408 if [ -f /etc/rc.d/rc.serial ]; then
409         . /etc/rc.d/rc.serial
410 fi
411
412 # If a SCSI tape has been detected, load the st module unconditionally
413 # since many SCSI tapes don't deal well with st being loaded and unloaded
414 if [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi | grep -q 'Type:   Sequential-Access' 2>/dev/null ; then
415         if cat /proc/devices | grep -qv ' 9 st' ; then
416                 if [ -n "$USEMODULES" ] ; then
417                         # Try to load the module.  If it fails, ignore it...
418                         insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
419                 fi
420         fi
421 fi
422
423 # there could be a new kernel version.  reinit /etc/psdevtab, to be sure.
424 rm -f /etc/psdevtab
425 #if [ -x /bin/ps ]; then
426 #show "Rebuilding /etc/psdevtab database"; busy
427 #if (ps > /dev/null 2>&1); then deltext; ok; else deltext; fail; fi
428 #fi
429
430 if ([ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ] 2>/dev/null); then
431 show "`nls "Sending val. %s to /proc/sys/kernel/panic" "$PANIC_REBOOT_TIME"`"; busy
432 if (echo $PANIC_REBOOT_TIME > /proc/sys/kernel/panic); then deltext; ok; else deltext; fail; fi
433 fi
434
435 # Now that we have all of our basic modules loaded and the kernel going,
436 # let's dump the syslog ring somewhere so we can find it later
437 dmesg > /var/log/dmesg
438 chmod 640 /var/log/dmesg
439
440 # Feed entropy into the entropy pool
441 /etc/rc.d/init.d/random start
This page took 0.060035 seconds and 4 git commands to generate.