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