]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- use /etc/rc.d/rc.acct for accouting; updated accouting related parts of translation...
[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$
5 #
6 # Taken in part from Miquel van Smoorenburg's bcheckrc.
7 # Changes:      Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
8 #
9
10 # Set the path
11 PATH=/bin:/sbin:/usr/bin:/usr/sbin
12 export PATH
13
14 # Read functions
15 . /etc/rc.d/init.d/functions
16
17 # we need /proc mounted before everything
18 mount -n -o gid=17 -t proc /proc /proc
19
20 # sysfs is also needed before any other things (under kernel > 2.5)
21 if grep -q sysfs /proc/filesystems ; then
22     run_cmd "Mounting sysfs filesystem" mount -n -o gid=17 -t sysfs sysfs /sys
23 fi
24
25 # Choose Hardware profile
26 rm -f /var/run/hwprofile 2> /dev/null
27 if [ -f /etc/sysconfig/hwprof ]; then
28     . /etc/sysconfig/hwprof
29     if is_yes "${HWPROFILES}" && [ -x /sbin/hwprofile -a -d /etc/sysconfig/hwprofiles/data ]; then
30        mount -n / -o rw,remount
31        /sbin/hwprofile -qf
32        mount -n / -o ro,remount
33     fi
34 fi
35
36 # NLS
37 if [ -r /etc/sysconfig/i18n ]; then
38         . /etc/sysconfig/i18n
39         [ -n "$LANG" ] && export LANG || unset LANG
40         [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
41         [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
42         [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
43         [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
44         [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
45         [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
46         [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
47         [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
48         [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
49 fi
50
51 # Read network config data
52 if [ -r /etc/sysconfig/network ]; then
53         . /etc/sysconfig/network
54 else
55         NETWORKING=no
56         HOSTNAME=localhost
57 fi
58
59 # Read system config data
60 if [ -r /etc/sysconfig/system ]; then
61         . /etc/sysconfig/system
62 else
63         RUN_SULOGIN_ON_ERR=yes
64         RUN_USERPNP=yes
65         RUN_KERNELPNP=yes
66         PANIC_REBOOT_TIME=0
67         DELAY_LOGIN=yes
68         CLEAN_TMP=no
69         CONSOLE_LOGLEVEL=1
70         SET_SLINKS=yes
71         RUN_LDCONFIG=yes
72 fi
73
74 # Print welcome message
75 nls "\t\t\t%sPowered by %sPLD Linux Distribution%s" "$(termput setaf 6)" "$(termput setaf 2)" "$(termput setaf 7)"
76 if is_yes "$PROMPT"; then
77         nls -n "\t\t  Press %sI%s to enter interactive startup" "$(termput setaf 1)" "$(termput setaf 7)"
78         echo
79         sleep 1
80 fi
81
82 # Set console loglevel
83 if [ -n "$CONSOLE_LOGLEVEL" ]; then
84         /bin/dmesg -n $CONSOLE_LOGLEVEL
85 fi
86
87 # /dev must be also mounted before everything but only if we want use them ;-)
88 if is_yes "$MOUNT_DEVFS"; then
89         run_cmd "Mounting Device Filesystem" mount -n -t devfs /dev /dev
90 fi
91
92 # set up devfsd
93 if [ -e /dev/.devfsd -a -x /sbin/devfsd ]; then
94         run_cmd "Starting Device Filesystem Daemon" /sbin/devfsd /dev
95 fi
96
97 # Configure Linux kernel (initial configuration, some required modules still
98 # may be missing).
99 /sbin/sysctl -p /etc/sysctl.conf > /dev/null 2>&1
100
101 # Set the system clock.
102 ARC=0
103 SRM=0
104 UTC=0
105
106 if [ -f /etc/sysconfig/clock ]; then
107         . /etc/sysconfig/clock
108
109         # convert old style clock config to new values
110         if [ "${CLOCKMODE}" = "GMT" ]; then
111                 UTC=true
112         elif [ "${CLOCKMODE}" = "ARC" ]; then
113                 ARC=true
114         fi
115 fi
116
117 if grep "system serial" /proc/cpuinfo | grep -q MILO ; then
118         ARC=true
119 fi
120
121 CLOCKDEF=""
122 CLOCKFLAGS="--hctosys"
123
124 if is_yes "$UTC" ; then
125         CLOCKFLAGS="$CLOCKFLAGS --utc"
126         CLOCKDEF="$CLOCKDEF (utc)"
127 else
128         CLOCKFLAGS="$CLOCKFLAGS --localtime"
129         CLOCKDEF="$CLOCKDEF (local)"
130 fi
131
132 if is_yes "$ARC" ; then
133         CLOCKFLAGS="$CLOCKFLAGS -A"
134         CLOCKDEF="$CLOCKDEF (arc)"
135 fi
136
137 if is_yes "$SRM" ; then
138         CLOCKFLAGS="$CLOCKFLAGS -S"
139         CLOCKDEF="$CLOCKDEF (srm)"
140 fi
141
142 # Check if timezone definition is available
143 if [ -e /etc/localtime ] ; then
144         if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
145                 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
146         fi
147 else
148         TIME_SETUP_DELAYED=yes
149 fi
150
151 # Start up swapping
152 run_cmd "Activating swap partitions" swapon -a
153
154 # Set the hostname
155 run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
156
157 # Set the NIS domain name
158 if [ -n "$NISDOMAIN" ]; then
159         run_cmd "$(nls 'NIS Domain:') ${NISDOMAIN}" domainname $NISDOMAIN
160 else
161         domainname ""
162 fi
163
164 # Setup hdparm thing (if exists and is needed)
165 if ! grep -iq nohdparm /proc/cmdline; then
166         [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
167 fi
168
169 if [ -f /fastboot ] || grep -iq "fastboot" /proc/cmdline 2> /dev/null ; then
170         fastboot=yes
171 else
172         fastboot=
173 fi
174
175 if [ -f /fsckoptions ]; then
176         fsckoptions=$(cat /fsckoptions)
177 else
178         fsckoptions=''
179 fi
180
181 if [ -f /forcefsck ]; then
182         fsckoptions="-f $fsckoptions"
183 fi
184
185 _RUN_QUOTACHECK=0
186 _ROOTFS_TYPE=$(grep " / " /proc/mounts | awk '{ print $3 }')
187
188 if [ -z "$fastboot" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" ]; then 
189         show "Checking root filesystem"; started
190         initlog -c "fsck -C -T -a $fsckoptions /"
191
192         rc=$?
193
194         # A return of 4 or higher means there were serious problems.
195         if [ $rc -gt 3 ]; then
196                 # don't use '\n' in nls macro !
197                 echo
198                 echo
199                 nls "*** An error occurred during the file system check."
200                 nls "*** Dropping you to a shell; the system will reboot"
201                 nls "*** when you leave the shell."
202                 echo
203
204                 PS1="$(nls '(Repair filesystem)# ')"; export PS1
205                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
206                         sulogin
207                 else
208                         /bin/sh
209                 fi
210
211                 run_cmd "Unmounting file systems" umount -a
212                 mount -n -o remount,ro /
213                 run_cmd "Automatic reboot in progress" reboot
214         # A return of 2 or 3 means that filesystem was repaired but we need
215         # to reboot.
216         elif [ "$rc" = "2" -o "$rc" = "3" ]; then
217                 echo
218                 nls "*** Filesystem was repaired but system needs to be"
219                 nls "*** rebooted before mounting it."
220                 nls "*** REBOOTING ***"
221                 echo
222
223                 run_cmd "Unmounting file systems" umount -a
224                 mount -n -o remount,ro /
225                 run_cmd "Automatic reboot in progress" reboot
226         elif [ "$rc" = "1" ]; then
227                 _RUN_QUOTACHECK=1
228         fi
229 fi
230
231 # Check for arguments 
232 if grep -iq nopnp /proc/cmdline; then
233         PNP=
234 else
235         PNP=yes
236 fi
237
238 # set up pnp and kernel pnp
239 if [ -n "$PNP" ]; then
240     if is_yes "$RUN_USERPNP" && [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
241         run_cmd "Setting up ISA PNP devices (userspace pnp)" /sbin/isapnp /etc/isapnp/isapnp.conf
242     fi
243     if is_yes "$RUN_KERNELPNP"; then
244         /sbin/modprobe -k isa-pnp 2> /dev/null
245         if [ -e /proc/isapnp -a -f /etc/isapnp/isapnp-kernel.conf ]; then
246             show "Setting up ISA PNP devices (kernelspace pnp)"; busy
247             grep -v "^#" /etc/isapnp/isapnp-kernel.conf > /proc/isapnp && (deltext; ok) || (deltext; fail)
248         fi
249     fi
250 fi
251
252 # Remount the root filesystem read-write
253 run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
254
255 # Update quotas if fsck was run on /
256 if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
257         run_cmd "Checking root filesystem quotas" /sbin/quotacheck -vug /
258 fi
259
260 # Clear mtab
261 >/etc/mtab
262
263 # Remove stale backups
264 rm -f /etc/mtab~ /etc/mtab~~
265
266 # Enter root, /proc, /sys and devfs into mtab.
267 mount -f /
268 mount -f /proc
269 if grep -q sysfs /proc/filesystems ; then
270         mount -f -t sysfs sysfs /sys
271 fi
272 if is_yes "$MOUNT_DEVFS"; then
273         mount -f -t devfs devfs /dev
274 fi
275
276 # Remove /etc/nologin when starting system
277 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
278
279 if is_yes "$DELAY_LOGIN" && [ ! -f /etc/nologin ]; then
280         show "Enabling Delay Login"; busy
281         echo > /etc/nologin
282         nls "System bootup in progress - please wait" >> /etc/nologin
283         echo >> /etc/nologin
284         chmod 644 /etc/nologin
285         cp -fp /etc/nologin /etc/nologin.boot
286         ok
287 fi
288
289 # The root filesystem is now read-write, so we can now log via
290 # syslog() directly...
291 if [ -n "$IN_INITLOG" ]; then
292         IN_INITLOG=""
293 fi
294
295 if [ ! -f /proc/modules ]; then
296         USEMODULES=
297 elif ! grep -iq nomodules /proc/cmdline; then
298         USEMODULES=y
299 else
300         USEMODULES=
301 fi
302
303 # Adjust symlinks as necessary in /boot to keep system services from
304 # spewing messages about mismatched System maps and so on.
305 if is_yes "$SET_SLINKS"; then
306         if [ -L /boot/System.map -a -r /boot/System.map-`uname -r` ] ; then
307                 ln -s -f System.map-`uname -r` /boot/System.map
308         fi
309         if [ ! -e /boot/System.map -a -r /boot/System.map-`uname -r` ] ; then
310                 ln -s -f System.map-`uname -r` /boot/System.map
311         fi
312 fi
313
314 # Run depmod if RUN_DEPMOD != "no" and:
315 # a) user requested or RUN_DEPMOD="";
316 # b) modules.dep is missing
317 # c) modules.dep is older than /etc/modules.conf or /lib/modules/`uname -r`
318 if ! is_no "$RUN_DEPMOD" && [ -n "$USEMODULES" ]; then
319         if is_yes "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ]; then
320                 run_cmd "Finding module dependencies" depmod -a
321         elif [ "$RUN_DEPMOD" = "ifmissing" ]; then
322                 run_cmd "Finding module dependencies" depmod -A
323         fi
324 fi
325
326 if [ -f /proc/sys/kernel/modprobe ]; then
327         if [ -n "$USEMODULES" ]; then
328                 sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1
329                 sysctl -w kernel.hotplug="/sbin/hotplug" >/dev/null 2>&1
330         else
331                 # We used to set this to NULL, but that causes
332                 # 'failed to exec' messages"
333                 sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1
334                 sysctl -w kernel.hotplug="/bin/true" >/dev/null 2>&1
335         fi
336 fi
337
338 # Initialize USB controller and HID devices
339 usb=0
340 if ! grep -iq "nousb" /proc/cmdline 2>/dev/null && ! grep -q "usb" /proc/devices 2>/dev/null ; then
341         aliases=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+usb-controller" | awk '{ print $3 }')
342         if [ -n "$aliases" -a "$aliases" != "off" ] ; then
343                 /sbin/modprobe -k usbcore
344                 if ! grep -qE "(usbdevfs|usbfs)" /etc/mtab && [ ! -f /proc/bus/usb/devices ]; then
345                         run_cmd "Mounting USB filesystem" mount /proc/bus/usb
346                 fi
347                 for alias in $aliases ; do 
348                         run_cmd "$(nls 'Initializing USB controller') ($alias)" /sbin/modprobe $alias
349                 done
350                 [ $? -eq 0 -a -n "$aliases" ] && usb=1
351         fi
352 fi
353
354 if ! grep -iq "nousb" /proc/cmdline 2>/dev/null && grep -q "usb" /proc/devices 2>/dev/null ; then
355         usb=1
356 fi
357
358 needusbstorage=
359 if [ $usb = "1" ]; then
360         mouseoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=02")
361         kbdoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=01")
362         needusbstorage=$(cat /proc/bus/usb/devices 2>/dev/null|grep -e "^I.*Cls=08")
363         if [ -n "$kbdoutput" ] || [ -n "$mouseoutput" ]; then
364                 run_cmd "Initializing USB HID interface" modprobe hid 2> /dev/null
365         fi
366         if [ -n "$kbdoutput" ]; then
367                 run_cmd "Initializing USB keyboard" modprobe keybdev
368         fi
369         if [ -n "$mouseoutput" ]; then
370                 run_cmd "Initializing USB mouse" modprobe mousedev
371         fi
372 fi
373
374 # Load usb storage here, to match most other things
375 if [ -n "$needusbstorage" ]; then
376         modprobe usb-storage >/dev/null 2>&1
377 fi
378
379 # Load sound modules if they need persistent DMA buffers
380 if grep -q "options sound dmabuf=1" /etc/modules.conf 2>/dev/null ; then
381         RETURN=0
382         alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound[[:space:]]+" | awk '{ print $3 }')
383         if [ -n "$alias" -a "$alias" != "off" ] ; then
384                 run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
385                 RETURN=$?
386         fi
387         alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound-slot-0[[:space:]]+" | awk '{ print $3 }')
388         if [ -n "$alias" -a "$alias" != "off" ] ; then
389                 run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
390                 RETURN=$?
391         fi
392 fi
393
394 # Load modules
395 if [ -x /etc/rc.d/rc.modules ]; then
396         /etc/rc.d/rc.modules
397 fi
398
399 # Find and activate volume groups:
400 # EVMS
401 if [ -x /sbin/evms_activate ]; then
402         # Linux 2.5 core module
403         modprobe -s -k evmscore > /dev/null 2>&1
404         # Linux 2.4 core modules
405         modprobe -s -k evms > /dev/null 2>&1
406         modprobe -s -k evms_passthru > /dev/null 2>&1
407         modprobe -s -k ldev_mgr > /dev/null 2>&1
408         modprobe -s -k dos_part > /dev/null 2>&1
409         is_yes "$EVMS_GUID_PTABLE" && modprobe -s -k gpt_part >/dev/null 2>&1
410         is_yes "$EVMS_LVM" && modprobe -s -k lvm_vge >/dev/null 2>&1
411         is_yes "$EVMS_AIX" && modprobe -s -k AIXlvm_vge >/dev/null 2>&1
412         is_yes "$EVMS_OS2" && modprobe -s -k os2lvm_vge >/dev/null 2>&1
413         run_cmd "Discovering EVMS volumes" /sbin/evms_activate
414         if is_yes "$EVMS_LVM" && is_yes "$EVMS_LVM_COMPAT_NODES" ; then
415                 # Link nodes for compatibility with LVM
416                 if [ "echo /dev/evms/lvm/*" != '/dev/evms/lvm/*' ] ; then
417                         ln -s /dev/evms/lvm/* /dev/
418                 fi
419         fi
420 fi
421 # LVM
422 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
423         modprobe -s -k lvm-mod >/dev/null 2>&1
424         # device mapper (2.5+ and patched 2.4)
425         modprobe -s -k dm-mod >/dev/null 2>&1
426         run_cmd "Scanning for LVM volume groups" /sbin/vgscan && \
427         run_cmd "Activating LVM volume groups" /sbin/vgchange -a y
428 fi
429
430 # Add raid devices
431 if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ] || [ -f /etc/raidtab ]; then
432
433         modprobe -s md >/dev/null 2>&1
434         if [ -f /proc/mdstat ]; then
435             goraidtab=1
436             rc=0
437             
438             if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
439                 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf); then
440                     run_cmd "Starting up RAID devices" /sbin/mdadm --assemble --scan
441                     rc=$?
442                     [ "$rc" -eq 0 ] && goraidtab=0
443                 fi
444             fi
445             
446             if [ -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
447                 
448                 for i in $(grep -v "^#" /etc/raidtab | grep "raiddev" | awk '{print $2}') ; do
449                     RAIDDEV=$(basename $i)
450                     RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat)
451                     show "Starting up RAID device %s" $RAIDDEV
452                     busy
453                     if [ -z "$RAIDSTAT" ]; then
454                         # Try raidstart first...if that fails then
455                         # fall back to raid0run and if that fails too
456                         # fall back to raidadd, raidrun.
457                         RESULT=1
458                         if [ -x /sbin/raidstart ]; then
459                                 /sbin/raidstart $i
460                                 RESULT=$?
461                         fi
462                         if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
463                                 /sbin/raid0run $i
464                                 RESULT=$?
465                         fi
466                         if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
467                                 /sbin/raidadd $i
468                                 /sbin/raidrun $i
469                                 RESULT=$?
470                         fi
471                         if [ $RESULT -gt 0 ]; then
472                                 rc=1
473                                 fail
474                         else
475                                 ok
476                         fi
477                     else
478                         ok
479                     fi
480                 done
481             fi
482
483             # A non-zero return means there were problems
484             if [ $rc -gt 0 ]; then
485                 show "Starting up RAID devices"; fail
486                 echo
487                 echo
488                 nls "*** An error occurred during the RAID startup."
489                 nls "*** Dropping you to a shell; the system will reboot"
490                 nls "*** when you leave the shell."
491                 echo
492
493                 PS1="$(nls '(RAID Repair)# ')"; export PS1
494                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
495                         sulogin
496                 else
497                         /bin/sh
498                 fi
499
500                 run_cmd "Unmounting file systems" umount -a
501                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
502                 run_cmd "Automatic reboot in progress" reboot
503             fi
504             show "Starting up RAID devices"; ok
505         fi
506 fi
507
508 _RUN_QUOTACHECK=0
509 # Check filesystems
510 if [ -z "$fastboot" ] && ! grep -q nofsck /proc/cmdline; then
511         show "Checking filesystems"; started
512         initlog -c "fsck -C -T -R -A -a $fsckoptions"
513
514         rc=$?
515
516         # A return of 2 or higher means there were serious problems
517         if [ $rc -gt 1 ]; then
518                 echo
519                 echo
520                 nls "*** An error occurred during the file system check."
521                 nls "*** Dropping you to a shell; the system will reboot"
522                 nls "*** when you leave the shell."
523                 echo
524
525                 PS1="$(nls '(Repair filesystem)# ')"; export PS1
526                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
527                         sulogin
528                 else
529                         /bin/sh
530                 fi
531
532                 run_cmd "Unmounting file systems" umount -a
533                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
534                 run_cmd "Automatic reboot in progress" reboot
535         elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
536                 _RUN_QUOTACHECK=1
537         fi
538 fi
539
540 # Mount all other filesystems (except for NFS and /proc, which is already
541 # mounted). Contrary to standard usage,
542 # filesystems are NOT unmounted in single user mode.
543
544 run_cmd "Mounting local filesystems" mount -a -t nonfs,smbfs,ncpfs,proc
545
546 # Now do some workaround - encrypted filesystems couldn't have been fsck-ed
547 # before mount - that's where the password is entered.
548 # mount is buggy - when remounting loopback filesystem, loop=XXX
549 # option is removed from /etc/mtab
550 if grep "^[^#].*encryption=" /etc/fstab | grep -v -q "noauto"; then
551         show "Checking encrypted filesystems"; started
552         LOOPLIST="$(
553         grep "encryption=" /etc/fstab | grep -v 'noauto' | grep -w 'ro' |\
554         while read FILE DIR TYPE OPTS TMP1; do
555                 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
556                 echo "$LOOP"
557         done
558         grep "encryption=" /etc/fstab | grep -vw 'ro\|noauto' |\
559         while read FILE DIR TYPE OPTS TMP1; do
560                 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
561                 LOOPLIST="$LOOPLIST $LOOP"
562                 NEWOPTS="remount,`echo "$OPTS" | sed 's#loop\(=[^,]*\)\?#loop='"$LOOP"'#'`,ro"
563                 echo "$LOOP"
564                 mount "$DIR" -o "$NEWOPTS"
565         done
566         )"
567         
568         initlog -c "fsck -T -C -a $fsckoptions $LOOPLIST"
569         rc=$?
570
571         # A return of 2 or higher means there were serious problems.
572         if [ $rc -gt 1 ]; then
573                 echo "\n\n"
574                 nls "*** An error occurred during the file system check."
575                 nls "*** Dropping you to a shell; the system will reboot"
576                 nls "*** when you leave the shell."
577                 echo
578
579                 PS1="`nls '(Repair filesystem)# '`"; export PS1
580                 if is_yes "$RUN_SULOGIN_ON_ERR"; then
581                         sulogin
582                 else
583                         /bin/sh
584                 fi
585
586                 run_cmd "Unmounting file systems" umount -a
587                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
588                 run_cmd "Automatic reboot in progress" reboot
589         elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
590                 _RUN_QUOTACHECK=1
591         fi
592         
593         show "Remounting encrypted filesystems back in rw mode"; busy
594         grep "encryption=" /etc/fstab | grep -vw 'ro\|noauto' |\
595         while read FILE DIR TYPE OPTS TMP1; do
596                 LOOP="`cat /proc/mounts | awk '$2 == "'"$DIR"'" { print $1 }'`"
597                 NEWOPTS="remount,`echo "$OPTS" | sed 's#loop\(=[^,]*\)\?#loop='"$LOOP"'#'`,rw"
598                 mount "$DIR" -o "$NEWOPTS"
599         done
600         ok
601 fi
602
603 if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
604         run_cmd "Checking filesystem quotas"  /sbin/quotacheck -v -u -g -R -a
605 fi
606
607 # Turn on quota
608 if [ -x /sbin/quotaon ]; then
609         run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -a
610 fi
611
612 # Turn on process accounting
613 if [ -x /etc/rc.d/rc.acct ]; then
614         /etc.rc.d/rc.acct start
615 fi
616
617 # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
618 if is_yes "$TIME_SETUP_DELAYED"; then
619         if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
620                 show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
621         fi
622 fi
623
624 # Initialize the serial ports
625 if [ -f /etc/rc.d/rc.serial ]; then
626         . /etc/rc.d/rc.serial
627 fi
628
629 if [ -f /proc/sys/kernel/panic -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
630         show 'Setting %s seconds for kernel reboot after panic' "$PANIC_REBOOT_TIME"; busy
631         if (sysctl -w kernel.panic=$PANIC_REBOOT_TIME >/dev/null 2>&1); then ok; else fail; fi
632 fi
633
634 # ... and here finish configuring parameters
635 run_cmd "Configuring kernel parameters" /sbin/sysctl -p /etc/sysctl.conf
636
637 # Clean up /etc.
638 rm -f /fastboot /fsckoptions /forcefsck /halt /poweroff
639
640 # Clean up /var
641 # I'd use find, but /usr may not be mounted.
642 for afile in /var/lock/* /var/run/*; do
643         if [ -d "$afile" ]; then
644                 bafile=$(basename $afile)
645                 [ "$bafile" != "news" -a "$bafile" != "sudo" -a "$bafile" != "mon" ] && rm -rf $afile/*
646         else
647                 rm -f $afile 2> /dev/null
648         fi
649 done
650
651 # Delete stale pid files
652 rm -f /var/spool/postoffice/.pid.*
653
654 {
655 # Clean up utmp/wtmp
656 if ! is_no "$NEED_XFILES" ; then
657         :>/var/run/utmpx
658         touch /var/log/wtmpx
659         chown root.utmp /var/run/utmpx /var/log/wtmpx
660         chmod 0664 /var/run/utmpx /var/log/wtmpx
661 else
662         :>/var/run/utmp
663         touch /var/log/wtmp
664         chown root.utmp /var/run/utmp /var/log/wtmp
665         chmod 0664 /var/run/utmp /var/log/wtmp
666 fi
667
668 # Clean /tmp
669 if is_yes "$CLEAN_TMP"; then
670         rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
671 fi
672
673 # Right, now turn on swap in case we swap to files
674 swapon -a >/dev/null 2>&1
675 run_cmd "Enabling swap space" /bin/true
676
677 # If a SCSI tape has been detected, load the st module unconditionally
678 # since many SCSI tapes don't deal well with st being loaded and unloaded
679 if [ -f /proc/scsi/scsi ] && grep -q 'Type:   Sequential-Access' /proc/scsi/scsi 2>/dev/null ; then
680         if cat /proc/devices | grep -qv ' 9 st' ; then
681                 if [ -n "$USEMODULES" ] ; then
682                         # Try to load the module. If it fails, ignore it...
683                         insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
684                 fi
685         fi
686 fi
687
688 # There could be a new kernel version. Remove old psdevtab database
689 rm -f /etc/psdevtab
690
691 # Now that we have all of our basic modules loaded and the kernel going,
692 # let's dump the syslog ring somewhere so we can find it later
693 mv -f /var/log/dmesg /var/log/dmesg.old
694 dmesg > /var/log/dmesg
695 chmod 640 /var/log/dmesg /var/log/dmesg.old
696
697 kill -TERM $(/sbin/pidof getkey) >/dev/null 2>&1
698 } &
699 if is_yes "$PROMPT"; then
700         /sbin/getkey i && touch /var/run/confirm
701 fi
702 wait
703 echo
704
705 # This must be last line !
706 # vi:syntax=sh:tw=78:ts=8:sw=4
This page took 0.337262 seconds and 3 git commands to generate.