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