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