]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- we _want_ utmpx and wtmpx, not utmp/wtmp
[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.67 2000/07/13 14:45:10 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 -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 | sed -e 's,/lib/modules/,,' -e 's, \
273                                         /.rhkmvtag,,' -e 's,[       ].*$,,'
274                         fi
275                         if [ -n "$mver" ]; then
276                                 ln -sf /lib/modules/$mver /lib/modules/default
277                         fi
278                 fi
279         fi
280         [ -n "$mver" -a -f "/boot/module-info-$mver" ] && \
281                 ln -sf /boot/module-info-$mver /boot/module-info
282         [ -n "$mver" -a -f "/boot/System.map-$mver" ] && \
283                 ln -sf /boot/System.map-$mver /boot/System.map
284
285         # Run depmod if:
286         # a) user requested or RUN_DEPMOD="";
287         # b) modules.dep is missing
288         # c) modules.dep is older than /etc/modules.conf or /lib/modules/$mver
289         if ! is_no "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ]; then
290                 if [ "$RUN_DEPMOD" = "ifmissing" -a ! -r /lib/modules/$mver/modules.dep ] ||\
291                 is_yes "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ] ||\
292                 [ /lib/modules/$mver/modules.dep -ot /etc/modules.conf ] ||\
293                 [ /lib/modules/$mver/modules.dep -ot /lib/modules/$mver ]
294                 then
295                         run_cmd "Finding module dependencies" depmod -a
296                 fi
297         fi
298 fi
299
300 # load sound modules
301 if [ -n "$USEMODULES" ] && is_yes "$LOAD_SOUND"; then
302         if grep -s -q "^alias sound-slot-0" /etc/modules.conf ; then
303                 run_cmd "Loading sound module" modprobe -s sound-slot-0
304         fi
305         if grep -s -q "^alias synth0" /etc/modules.conf ; then
306                 run_cmd "Loading synthesiser module" modprobe -s synth0
307         fi
308 fi
309
310 if [ -f /proc/sys/kernel/modprobe ]; then
311         # /proc/sys/kernel/modprobe indicates built-in kmod instead
312         echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
313 fi
314
315 # Load modules
316 if [ -f /etc/rc.d/rc.modules ]; then
317         /etc/rc.d/rc.modules
318 fi
319
320 # Add raid devices
321 if [ -f /proc/mdstat -a -f /etc/raidtab ]; then
322         show "Starting up RAID devices."; started
323
324         rc=0
325         
326         for i in `grep "raiddev" /etc/raidtab | awk '{print $2}'`
327         do
328                 RAIDDEV=`basename $i`
329                 RAIDSTAT=`grep "^$RAIDDEV : active" /proc/mdstat`
330                 if [ -z "$RAIDSTAT" ]; then
331                         # Try raidstart first...if that fails then
332                         # fall back to raid0run.
333                         RESULT=1
334                         if [ -x /sbin/raidstart ]; then
335                                 /sbin/raidstart $i
336                                 RESULT=$?
337                         fi
338                         if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
339                                 /sbin/raid0run $i
340                         fi
341                 fi
342         done
343
344         # A non-zero return means there were problems.
345         if [ $rc -gt 0 ]; then
346                 show "Starting up RAID devices."; fail
347                 echo "\n\n"
348                 nls "*** An error occurred during the RAID startup"
349                 nls "*** Dropping you to a shell; the system will reboot"
350                 nls "*** when you leave the shell."
351                 echo
352
353                 PS1="`nls "(RAID Repair)# "`"; export PS1
354                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
355                         sulogin
356                 else
357                         /bin/sh
358                 fi
359
360                 run_cmd "Unmounting file systems" umount -a
361                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
362                 run_cmd "Automatic reboot in progress" reboot
363         fi
364         show "Starting up RAID devices."; ok
365 fi
366
367 # Check filesystems
368 if [ ! -f /fastboot ]; then
369         show "Checking filesystems."; started
370         initlog -c "fsck -C -T -R -A -a $fsckoptions"
371
372         rc=$?
373
374         # A return of 2 or higher means there were serious problems.
375         if [ $rc -gt 1 ]; then
376                 echo "\n\n"
377                 nls "*** An error occurred during the file system check."
378                 nls "*** Dropping you to a shell; the system will reboot"
379                 nls "*** when you leave the shell."
380                 echo
381
382                 PS1="`nls "(Repair filesystem)# "`"; export PS1
383                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
384                         sulogin
385                 else
386                         /bin/sh
387                 fi
388
389                 run_cmd "Unmounting file systems" umount -a
390                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
391                 run_cmd "Automatic reboot in progress." reboot
392         elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
393                 run_cmd "Checking filesystem quotas" /sbin/quotacheck -v -R -a
394         fi
395 fi
396
397 # Mount all other filesystems (except for NFS and /proc, which is already
398 # mounted). Contrary to standard usage,
399 # filesystems are NOT unmounted in single user mode.
400 run_cmd "Mounting local filesystems." mount -a -t nonfs,smbfs,ncpfs,proc
401
402 # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
403 if is_yes "$TIME_SETUP_DELAYED"; then
404         if run_cmd "Setting clock$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
405                 show "Today's date: `LC_CTYPE=C date`"; ok
406         fi
407 fi
408
409 if [ -x /sbin/quotaon ]; then
410         run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -a
411 fi
412
413 # Initialize the serial ports.
414 if [ -f /etc/rc.d/rc.serial ]; then
415         . /etc/rc.d/rc.serial
416 fi
417
418 if [ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
419         show "`nls "Setting %s seconds for kernel reboot after panic." "$PANIC_REBOOT_TIME"`"; busy
420         if (echo $PANIC_REBOOT_TIME > /proc/sys/kernel/panic); then ok; else fail; fi
421 fi
422
423 # Clean out /etc & /var/{run/*,log/{b,w}tmpx}}.
424 rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck
425
426 {
427 # Clean up utmp/wtmp
428 if [ ! is_no "$NEED_XFILES" ]; then
429         :>/var/run/utmpx
430         touch /var/log/wtmpx
431         chown root.utmp /var/run/utmpx /var/log/wtmpx
432         chmod 0664 /var/run/utmpx /var/log/wtmpx
433 else
434         :>/var/run/utmp
435         touch /var/log/wtmp
436         chown root.utmp /var/run/utmp /var/log/wtmp
437         chmod 0664 /var/run/utmp /var/log/wtmp
438 fi
439
440 # Clean /tmp
441 if is_yes "$CLEAN_TMP"; then
442         rm -rf /tmp/*
443 fi
444
445 # Delete UUCP lock files.
446 rm -f /var/lock/LCK*
447
448 # Delete stale subsystem files.
449 rm -f /var/lock/subsys/*
450
451 # Delete stale pam_console locks.
452 rm -f /var/lock/console/*
453 rm -f /var/lock/console.lock
454
455 # Delete stale pid files
456 rm -f /var/run/*.pid
457 rm -f /var/spool/postoffice/.pid.*
458
459 # Delete X locks
460 rm -f /tmp/.X*-lock
461
462 # Delete Postgres sockets
463 rm -f /tmp/.s.PGSQL.*
464
465 # Right, now turn on swap in case we swap to files.
466 swapon -a >/dev/null 2>&1
467 run_cmd "Enabling swap space" /bin/true
468
469 # If a SCSI tape has been detected, load the st module unconditionally
470 # since many SCSI tapes don't deal well with st being loaded and unloaded
471 if [ -f /proc/scsi/scsi ] && cat /proc/scsi/scsi | grep -q 'Type:   Sequential-Access' 2>/dev/null ; then
472         if cat /proc/devices | grep -qv ' 9 st' ; then
473                 if [ -n "$USEMODULES" ] ; then
474                         # Try to load the module.  If it fails, ignore it...
475                         insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
476                 fi
477         fi
478 fi
479
480 # there could be a new kernel version.  remove old psdevtab database
481 rm -f /etc/psdevtab
482
483 # If needed increase number of available system files
484 # There are two versions of each setting, because file names
485 # changed between Linux 2.0 and 2.2
486 if [ -n "$VFS_FILE_MAX" ] ; then
487         if [ -f /proc/sys/kernel/file-max -a "$VFS_FILE_MAX" -gt 0 ]; then
488                 echo $VFS_FILE_MAX >/proc/sys/kernel/file-max
489         fi
490         if [ -f /proc/sys/fs/file-max -a "$VFS_FILE_MAX" -gt 0 ]; then
491                 echo $VFS_FILE_MAX >/proc/sys/fs/file-max
492         fi
493 fi
494 if [ -n "$VFS_INODE_MAX" ] ; then
495         if [ -f /proc/sys/kernel/inode-max -a "$VFS_INODE_MAX" -gt 0 ]; then
496                 echo $VFS_INODE_MAX >/proc/sys/kernel/inode-max
497         fi
498         if [ -f /proc/sys/fs/inode-max -a "$VFS_INODE_MAX" -gt 0 ]; then
499                 echo $VFS_INODE_MAX >/proc/sys/fs/inode-max
500         fi
501 fi
502
503
504 # Now that we have all of our basic modules loaded and the kernel going,
505 # let's dump the syslog ring somewhere so we can find it later
506 dmesg > /var/log/dmesg
507 chmod 640 /var/log/dmesg
508
509 # Now that we have all of our basic modules loaded and the kernel going,
510 # let's dump the syslog ring somewhere so we can find it later
511 kill -TERM `/sbin/pidof getkey` >/dev/null 2>&1
512 } &
513 if is_yes "$PROMPT"; then
514    /sbin/getkey i && touch /var/run/confirm
515 fi
516 wait
This page took 0.067458 seconds and 4 git commands to generate.