]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- bring it up to date with the stuff ;>
[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.83 2001/07/05 15:47:39 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 [ -r /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 [ -r /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 [ -r /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 nls "\t\t\t%sPowered by %sPLD GNU/Linux%s" "$(termput setaf 6)" "$(termput setaf 2)" "$(termput setaf 7)"
57 if is_yes "$PROMPT"; then
58         nls -n "\t\t    Press %sI%s to enter interactive startup." "$(termput setaf 1)" "$(termput setaf 7)"
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 # Configure Linux kernel
82 run_cmd "Configuring kernel parameters" /sbin/sysctl -p /etc/sysctl.conf
83
84 # Set the system clock.
85 ARC=0
86 SRM=0
87 UTC=0
88
89 if [ -f /etc/sysconfig/clock ]; then
90         . /etc/sysconfig/clock
91
92         # convert old style clock config to new values
93         if [ "${CLOCKMODE}" = "GMT" ]; then
94                 UTC=true
95         elif [ "${CLOCKMODE}" = "ARC" ]; then
96                 ARC=true
97         fi
98 fi
99
100 if grep "system serial" /proc/cpuinfo | grep -q MILO ; then
101         ARC=true
102 fi
103
104 CLOCKDEF=""
105 CLOCKFLAGS="--hctosys"
106
107 case "$UTC" in
108         yes|true)
109                 CLOCKFLAGS="$CLOCKFLAGS --utc";
110                 CLOCKDEF="$CLOCKDEF (utc)";
111         ;;
112         *)
113         CLOCKFLAGS="$CLOCKFLAGS --localtime";
114         CLOCKDEF="$CLOCKDEF (local)";
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 # Check if timezone definition is available
132 if [ -e /etc/localtime ] ; then
133         if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
134                 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
135         fi
136 else
137         TIME_SETUP_DELAYED=yes
138 fi
139
140 # Start up swapping
141 run_cmd "Activating swap partitions" swapon -a
142
143 # Set the hostname
144 run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
145
146 # Set the NIS domain name
147 if [ -n "$NISDOMAIN" ]; then
148         run_cmd "$(nls 'NIS Domain:') ${NISDOMAIN}" domainname $NISDOMAIN
149 else
150         domainname ""
151 fi
152
153 # Setup hdparm thing (if exists and is needed)
154 if ! grep -iq nohdparm /proc/cmdline; then
155         [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
156 fi
157
158 if [ -f /fsckoptions ]; then
159         fsckoptions=$(cat /fsckoptions)
160 else
161         fsckoptions=''
162 fi
163
164 if [ -f /forcefsck ]; then
165         fsckoptions="-f $fsckoptions"
166 fi
167
168 _RUN_QUOTACHECK=0
169 if awk '{ if ($2 ~ /^\/$/ && ( $3 ~ /^(nfs|romfs)$/ || $6 ~ /^0$/ ) ) exit 1 ; else exit 0}' /etc/fstab; then
170
171     if [ ! -f /fastboot  ]; then
172             show "Checking root filesystem"; started
173             initlog -c "fsck -C -T -a $fsckoptions /"
174
175             rc=$?
176
177             # A return of 2 or higher means there were serious problems.
178             if [ $rc -gt 1 ]; then
179                     # don't use '\n' in nls macro !
180                     echo
181                     echo
182                     nls "*** An error occurred during the file system check."
183                     nls "*** Dropping you to a shell; the system will reboot"
184                     nls "*** when you leave the shell."
185                     echo
186
187                     PS1="$(nls '(Repair filesystem)# ')"; export PS1
188                     if is_yes "$RUN_SULOGIN_ON_ERR"; then
189                             sulogin
190                     else
191                             /bin/sh
192                     fi
193
194                     run_cmd "Unmounting file systems" umount -a
195                     mount -n -o remount,ro /
196                     run_cmd "Automatic reboot in progress" reboot
197             elif [ "$rc" = "1" ]; then
198                     _RUN_QUOTACHECK=1
199             fi
200     fi
201
202 fi
203
204 # Check for arguments 
205 if grep -iq nopnp /proc/cmdline; then
206         PNP=
207 else
208         PNP=yes
209 fi
210
211 # Set up pnp 
212 if [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
213         if [ -n "$PNP" ] && is_yes "$RUN_ISAPNP"; then
214                 run_cmd "Setting up ISA PNP devices" /sbin/isapnp /etc/isapnp/isapnp.conf
215         fi
216 fi
217
218
219 # Remount the root filesystem read-write
220 run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
221
222 # Update quotas if fsck was run on /
223 if [ X"$_RUN_QUOTACHECK" = "X1" -a -x /sbin/quotacheck ]; then
224         run_cmd "Checking root filesystem quotas" /sbin/quotacheck -vug /
225 fi
226
227 # Remove /etc/nologin when starting system
228 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
229
230 if is_yes "$DELAY_LOGIN" && [ ! -f /etc/nologin ]; then
231         show "Enabling Delay Login"; busy
232         echo > /etc/nologin
233         nls "System bootup in progress - please wait" >> /etc/nologin
234         echo >> /etc/nologin
235         chmod 644 /etc/nologin
236         cp -fp /etc/nologin /etc/nologin.boot
237         ok
238 fi
239
240 # The root filesystem is now read-write, so we can now log via
241 # syslog() directly...
242 if [ -n "$IN_INITLOG" ]; then
243         IN_INITLOG=""
244 fi
245
246 # Clear mtab
247 >/etc/mtab
248
249 # Write root and /proc to mtab
250 mount -f /
251 mount -f /proc
252 [ -f /proc/bus/usb/devices ] && mount -f -t usbdevfs usbdevfs /proc/bus/usb
253
254 if [ ! -f /proc/modules ]; then
255         USEMODULES=
256 elif ! grep -iq nomodules /proc/cmdline; then
257         USEMODULES=y
258 else
259         USEMODULES=
260 fi
261
262 # Kernel dependent links
263 rm -f /lib/modules/preferred
264 rm -f /lib/modules/default
265 if [ -x /sbin/depmod -a -n "$USEMODULES" ]; then
266         if is_yes "$SET_SLINKS"; then
267                 # Get ready for kmod if module support in the kernel
268                 if [ -z $(uname -r | grep "-") ]; then
269                         # We're using a new kernel, no preferred needed
270                         mver=$(uname -r)
271                 else
272                         ktag="$(cat /proc/version)"
273                         mtag=grep -l "$ktag" /lib/modules/*/.rhkmvtag 2> /dev/null
274                         if [ -n "$mtag" ]; then
275                                 mver=$(echo $mtag | awk ' { gsub(/\/lib\/modules\//,NIL); gsub(/.rhkmvtag/,NIL); gsub(/[     ].*$/,NIL); print $0 } ')
276                         fi
277                         if [ -n "$mver" ]; then
278                                 ln -sf /lib/modules/$mver /lib/modules/default
279                         fi
280                 fi
281
282                 [ -n "$mver" -a -f "/boot/module-info-$mver" ] && \
283                         ln -sf /boot/module-info-$mver /boot/module-info
284                 [ -n "$mver" -a -f "/boot/System.map-$mver" ] && \
285                         ln -sf /boot/System.map-$mver /boot/System.map
286         fi
287 fi
288
289 # Run depmod if RUN_DEPMOD != "no" and:
290 # a) user requested or RUN_DEPMOD="";
291 # b) modules.dep is missing
292 # c) modules.dep is older than /etc/modules.conf or /lib/modules/$mver
293 if ! is_no "$RUN_DEPMOD" && [ -n "$USEMODULES" ]; then
294         if is_yes "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ] || \
295                 [ "$RUN_DEPMOD" = "ifmissing" -a ! -r /lib/modules/$mver/modules.dep ] ||\
296                 [ /lib/modules/$mver/modules.dep -ot /etc/modules.conf ] ||\
297                 [ /lib/modules/$mver/modules.dep -ot /lib/modules/$mver ]; then
298                 run_cmd "Finding module dependencies" depmod -a
299         fi
300 fi
301
302 if [ -f /proc/sys/kernel/modprobe ]; then
303         if [ -n "$USEMODULES" ]; then
304                 sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1
305         else
306                 # We used to set this to NULL, but that causes
307                 # 'failed to exec' messages"
308                 sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1
309         fi
310 fi
311
312 # Load modules
313 if [ -x /etc/rc.d/rc.modules ]; then
314         /etc/rc.d/rc.modules
315 fi
316         
317 # Load sound modules
318 if [ -n "$USEMODULES" ] && is_yes "$LOAD_SOUND"; then
319         if grep -s -q "^alias sound-slot-0" /etc/modules.conf ; then
320                 run_cmd "Loading sound module" modprobe -s sound-slot-0
321         fi
322         if grep -s -q "^alias synth0" /etc/modules.conf ; then
323                 run_cmd "Loading synthesiser module" modprobe -s synth0
324         fi
325 fi
326
327 # Add raid devices
328 if [ -f /proc/mdstat -a -f /etc/raidtab ]; then
329
330         rc=0
331         
332         for i in $(grep -v "^#" /etc/raidtab | grep "raiddev" | awk '{print $2}')
333         do
334                 RAIDDEV=$(basename $i)
335                 RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat)
336                 show "Starting up RAID device %s" $RAIDDEV
337                 busy
338                 if [ -z "$RAIDSTAT" ]; then
339                         # Try raidstart first...if that fails then
340                         # fall back to raid0run and if that fails too
341                         # fall back to raidadd, raidrun.
342                         RESULT=1
343                         if [ -x /sbin/raidstart ]; then
344                                 /sbin/raidstart $i
345                                 RESULT=$?
346                         fi
347                         if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
348                                 /sbin/raid0run $i
349                                 RESULT=$?
350                         fi
351                         if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
352                                 /sbin/raidadd $i
353                                 /sbin/raidrun $i
354                                 RESULT=$?
355                         fi
356                         if [ $RESULT -gt 0 ]; then
357                                 rc=1
358                                 fail
359                         else
360                                 ok
361                         fi
362                 else
363                         ok
364                 fi
365         done
366
367         # A non-zero return means there were problems
368         if [ $rc -gt 0 ]; then
369                 show "Starting up RAID devices."; fail
370                 echo
371                 echo
372                 nls "*** An error occurred during the RAID startup"
373                 nls "*** Dropping you to a shell; the system will reboot"
374                 nls "*** when you leave the shell."
375                 echo
376
377                 PS1="$(nls '(RAID Repair)# ')"; export PS1
378                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
379                         sulogin
380                 else
381                         /bin/sh
382                 fi
383
384                 run_cmd "Unmounting file systems" umount -a
385                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
386                 run_cmd "Automatic reboot in progress" reboot
387         fi
388         show "Starting up RAID devices."; ok
389 fi
390
391 # Find and activate volume groups
392 if [ -e /proc/lvm -a -x /sbin/vgscan -a -x /sbin/vgchange ]; then
393         run_cmd "Scanning for LVM volume groups" /sbin/vgscan && \
394         run_cmd "Activating LVM volume groups" /sbin/vgchange -a y
395 fi
396
397 # Check filesystems
398 if ! grep -q nofsck /proc/cmdline && [ ! -f /fastboot ]; then
399         show "Checking filesystems"; started
400         initlog -c "fsck -C -T -R -A -a $fsckoptions"
401
402         rc=$?
403
404         # A return of 2 or higher means there were serious problems
405         if [ $rc -gt 1 ]; then
406                 echo
407                 echo
408                 nls "*** An error occurred during the file system check."
409                 nls "*** Dropping you to a shell; the system will reboot"
410                 nls "*** when you leave the shell."
411                 echo
412
413                 PS1="$(nls '(Repair filesystem)# ')"; export PS1
414                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
415                         sulogin
416                 else
417                         /bin/sh
418                 fi
419
420                 run_cmd "Unmounting file systems" umount -a
421                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
422                 run_cmd "Automatic reboot in progress" reboot
423         elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
424                 if [ -x /sbin/convertquota ]; then
425                         if [ -f /quota.user ]; then
426                             /sbin/convertquota -u / && rm -f /quota.user
427                         fi
428                         if [ -f /quota.group ]; then
429                             /sbin/convertquota -g / && rm -f /quota.group
430                         fi
431                 fi
432                 run_cmd "Checking filesystem quotas" /sbin/quotacheck -v -u -g -R -a
433         fi
434 fi
435
436 # Mount all other filesystems (except for NFS and /proc, which is already
437 # mounted). Contrary to standard usage,
438 # filesystems are NOT unmounted in single user mode.
439
440 # Don'n mount devpts if devfs is already mounted
441 if is_yes "$MOUNT_DEVFS"; then
442         run_cmd "Mounting local filesystems" mount -a -t nonfs,smbfs,ncpfs,proc,devpts
443 else
444         run_cmd "Mounting local filesystems" mount -a -t nonfs,smbfs,ncpfs,proc
445 fi
446
447 # Now do some workaround - encrypted filesystems couldn't have been fsck-ed
448 # before mount - that's where the password is entered.
449 # mount is buggy - when remounting loopback filesystem, loop=XXX
450 # option is removed from /etc/mtab
451 if grep -q "encryption=" /etc/fstab; then
452         show "Checking encrypted filesystems"; started
453         LOOPLIST="$(
454         grep "encryption=" /etc/fstab | grep -v 'noauto' | grep -w 'ro' |\
455         while read FILE DIR TYPE OPTS TMP1; do
456                 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
457                 echo "$LOOP"
458         done
459         grep "encryption=" /etc/fstab | grep -vw 'ro\|noauto' |\
460         while read FILE DIR TYPE OPTS TMP1; do
461                 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
462                 LOOPLIST="$LOOPLIST $LOOP"
463                 NEWOPTS="remount,`echo "$OPTS" | sed 's#loop\(=[^,]*\)\?#loop='"$LOOP"'#'`,ro"
464                 echo "$LOOP"
465                 mount "$DIR" -o "$NEWOPTS"
466         done
467         )"
468         
469         initlog -c "fsck -T -C -a $fsckoptions $LOOPLIST"
470         rc=$?
471
472         # A return of 2 or higher means there were serious problems.
473         if [ $rc -gt 1 ]; then
474                 echo "\n\n"
475                 nls "*** An error occurred during the file system check."
476                 nls "*** Dropping you to a shell; the system will reboot"
477                 nls "*** when you leave the shell."
478                 echo
479
480                 PS1="`nls '(Repair filesystem)# '`"; export PS1
481                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
482                         sulogin
483                 else
484                         /bin/sh
485                 fi
486
487                 run_cmd "Unmounting file systems" umount -a
488                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
489                 run_cmd "Automatic reboot in progress." reboot
490         fi
491         
492         show "Remounting encrypted filesystems back in rw mode"; busy
493         grep "encryption=" /etc/fstab | grep -vw 'ro\|noauto' |\
494         while read FILE DIR TYPE OPTS TMP1; do
495                 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
496                 NEWOPTS="remount,`echo "$OPTS" | sed 's#loop\(=[^,]*\)\?#loop='"$LOOP"'#'`,rw"
497                 mount "$DIR" -o "$NEWOPTS"
498         done
499         ok
500 fi
501
502 # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
503 if is_yes "$TIME_SETUP_DELAYED"; then
504         if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
505                 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
506         fi
507 fi
508
509 if [ -x /sbin/quotaon ]; then
510         run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -a
511 fi
512
513 # Initialize the serial ports
514 if [ -f /etc/rc.d/rc.serial ]; then
515         . /etc/rc.d/rc.serial
516 fi
517
518 if [ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
519         show 'Setting %s seconds for kernel reboot after panic.' "$PANIC_REBOOT_TIME"; busy
520         if (sysctl -w kernel.panic=$PANIC_REBOOT_TIME 2> /dev/null); then ok; else fail; fi
521 fi
522
523 # Clean out /etc & /var/{run/*,log/{b,w}tmpx}}
524 rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck
525
526 {
527 # Clean up utmp/wtmp
528 rm -f /var/run/utmp?
529 if ! is_no "$NEED_XFILES" ; then
530         :>/var/run/utmpx
531         touch /var/log/wtmpx
532         chown root.utmp /var/run/utmpx /var/log/wtmpx
533         chmod 0664 /var/run/utmpx /var/log/wtmpx
534 else
535         :>/var/run/utmp
536         touch /var/log/wtmp
537         chown root.utmp /var/run/utmp /var/log/wtmp
538         chmod 0664 /var/run/utmp /var/log/wtmp
539 fi
540
541 # Clean /tmp
542 if is_yes "$CLEAN_TMP"; then
543         rm -rf /tmp/*
544 fi
545
546 # Delete UUCP lock files
547 rm -f /var/lock/LCK*
548
549 # Delete stale subsystem files
550 rm -f /var/lock/subsys/*
551
552 # Delete stale pam_console locks
553 rm -f /var/lock/console/*
554 rm -f /var/lock/console.lock
555
556 # Delete stale pid files
557 rm -f /var/run/*.pid
558 rm -f /var/spool/postoffice/.pid.*
559
560 # Delete X locks
561 rm -f /tmp/.X*-lock
562
563 # Delete Postgres sockets
564 rm -f /tmp/.s.PGSQL.*
565
566 # Right, now turn on swap in case we swap to files
567 swapon -a >/dev/null 2>&1
568 run_cmd "Enabling swap space" /bin/true
569
570 # If a SCSI tape has been detected, load the st module unconditionally
571 # since many SCSI tapes don't deal well with st being loaded and unloaded
572 if [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi | grep -q 'Type:   Sequential-Access' 2>/dev/null ; then
573         if cat /proc/devices | grep -qv ' 9 st' ; then
574                 if [ -n "$USEMODULES" ] ; then
575                         # Try to load the module. If it fails, ignore it...
576                         insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
577                 fi
578         fi
579 fi
580
581 # There could be a new kernel version. Remove old psdevtab database
582 rm -f /etc/psdevtab
583
584 # Now that we have all of our basic modules loaded and the kernel going,
585 # let's dump the syslog ring somewhere so we can find it later
586 dmesg > /var/log/dmesg
587 chmod 640 /var/log/dmesg
588
589 kill -TERM $(/sbin/pidof getkey) >/dev/null 2>&1
590 } &
591 if is_yes "$PROMPT"; then
592         /sbin/getkey i && touch /var/run/confirm
593 fi
594 wait
595 echo
596
597 # This must be last line !
598 # vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.175631 seconds and 4 git commands to generate.