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