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