]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- don't get tempted to kill blogd
[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 #
8
9 # reasonable start values for bootsplash progress.
10 export progress=0
11 export sscripts=45
12 export kscripts=45
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 network config data
30 if [ -r /etc/sysconfig/network ]; then
31         . /etc/sysconfig/network
32 else
33         NETWORKING=no
34         HOSTNAME=localhost
35 fi
36
37 CONSOLE_LOGLEVEL=1
38
39 # Read functions
40 . /etc/rc.d/init.d/functions
41
42 disable_selinux() {
43         typeset _d selinuxfs _t _r
44
45         while read _d selinuxfs _t _r; do
46                 [ "$_t" = "selinuxfs" ] && break
47         done </proc/mounts
48         echo "*** Warning -- SELinux is active"
49         echo "*** Disabling security enforcement for system recovery."
50         echo "*** Run 'setenforce 1' to reenable."
51         echo "0" > $selinuxfs/enforce
52 }
53
54 relabel_selinux() {
55         typeset _d selinuxfs _t _r
56
57         while read _d selinuxfs _t _r; do
58                 [ "$_t" = "selinuxfs" ] && break
59         done </proc/mounts
60         echo "
61          *** Warning -- SELinux relabel is required. ***
62          *** Disabling security enforcement.         ***
63          *** Relabeling could take a very long time, ***
64          *** depending on file system size.          ***
65          "
66         echo "0" > $selinuxfs/enforce
67         /sbin/fixfiles -F relabel > /dev/null 2>&1
68         rm -f /.autorelabel
69         echo "*** Enabling security enforcement.         ***"
70         echo $SELINUX > $selinuxfs/enforce
71 }
72
73 # Remove duplicate entries from mtab (for vserver guest use only)
74 clean_vserver_mtab() {
75         :>/etc/mtab.clean
76         while read device mountpoint line; do
77                 grep -qs "$mountpoint" /etc/mtab.clean || \
78                         echo "$device $mountpoint $line" >> /etc/mtab.clean
79         done < /etc/mtab
80         cat /etc/mtab.clean > /etc/mtab
81         rm -f /etc/mtab.clean
82 }
83
84
85 # boot logging to /var/log/boot.msg. install showconsole package to get it.
86 if [ -x /sbin/blogd ] && ! is_no "$RC_BOOTLOG"; then
87         RC_BOOTLOG=1
88 else
89         RC_BOOTLOG=
90 fi
91
92 if ! is_yes "$VSERVER" ; then
93         # we need /proc mounted before everything
94         mount -n -o gid=17 -t proc /proc /proc
95
96         # Only read this once.
97         cmdline=$(cat /proc/cmdline)
98
99         # sysfs is also needed before any other things (under kernel > 2.5)
100         if grep -q sysfs /proc/filesystems 2>/dev/null ; then
101                 mount -n -o gid=17 -t sysfs sysfs /sys
102                 if [ "$(kernelver)" -ge "002006014" ] && \
103                         grep -q securityfs /proc/filesystems 2>/dev/null ; then
104                                 mount -n -o gid=17 -t securityfs securityfs /sys/kernel/security
105                 fi
106                                                                                                                 
107         fi
108
109         # selinux
110         if grep -q selinuxfs /proc/filesystems 2>/dev/null && ! grep -q selinuxfs /proc/mounts 2>/dev/null; then
111                 mount -n -o gid=17 -t selinuxfs selinuxfs /selinux
112         fi
113
114         # PLD Linux LiveCD support
115         if [ -x /etc/rc.d/rc.live ]; then
116                 /etc/rc.d/rc.live
117         fi
118
119         # Choose Hardware profile
120         if [ -f /etc/sysconfig/hwprof ]; then
121                 . /etc/sysconfig/hwprof
122                 if is_yes "${HWPROFILES}" && [ -x /sbin/hwprofile -a -d /etc/sysconfig/hwprofiles/data ]; then
123                         mount -n / -o rw,remount
124                         /sbin/hwprofile -qf
125                         mount -n / -o ro,remount
126                 fi
127         fi
128
129         # Disable splash when requested
130         [ -e /proc/splash ] && is_no "$BOOT_SPLASH" && echo "0" > /proc/splash
131
132         # Check SELinux status
133         selinuxfs=$(awk '/ selinuxfs / { print $2 }' /proc/mounts 2> /dev/null)
134         SELINUX=
135         if [ -n "$selinuxfs" ] && [ "$(cat /proc/self/attr/current)" != "kernel" ]; then
136                 if [ -r $selinuxfs/enforce ] ; then
137                         SELINUX=$(cat $selinuxfs/enforce)
138                 else
139                         # assume enforcing if you can't read it
140                         SELINUX=1
141                 fi
142         fi
143
144         if [ -x /sbin/restorecon ] && LC_ALL=C fgrep -q " /dev " /proc/mounts 2>/dev/null ; then
145                 /sbin/restorecon -R /dev 2>/dev/null
146         fi
147
148
149         [ -z "${CONSOLETYPE}" ] && CONSOLETYPE="$(/sbin/consoletype)"
150
151         if [ "$CONSOLETYPE" = "vt" -a -x /sbin/setsysfont ]; then
152                 /sbin/setsysfont
153         fi
154 fi
155
156
157 # Print welcome message
158 nls "\t\t\t%sPowered by %sPLD Linux Distribution%s" "$(termput setaf $CPOWEREDBY)" "$(termput setaf $CPLD)" "$(termput op)"
159 if ! is_no "$RC_PROMPT"; then
160         nls -n "\t\t  Press %sI%s to enter interactive startup" "$(termput setaf $CI)" "$(termput op)"
161         echo
162 fi
163
164 # Set the hostname
165 if [ -z "${HOSTNAME}" ]; then
166         show "$(nls 'Host:') $(hostname)" ; ok
167 else
168         run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
169 fi
170
171 # Set the NIS domain name
172 if [ -n "$NISDOMAIN" ]; then
173         run_cmd "$(nls 'NIS Domain:') ${NISDOMAIN}" domainname $NISDOMAIN
174 else
175         domainname ""
176 fi
177
178 if ! is_yes "$VSERVER"; then
179         # Set console loglevel
180         if [ -n "$CONSOLE_LOGLEVEL" ]; then
181                 /bin/dmesg -n $CONSOLE_LOGLEVEL
182         fi
183
184         [ -x /sbin/start_udev ] && /sbin/start_udev
185
186         # Unmount the initrd, if necessary
187         if grep -q /initrd /proc/mounts 2>/dev/null && ! grep -q /initrd/loopfs /proc/mounts 2>/dev/null; then
188                 if [ -e /initrd/dev/.devfsd ]; then
189                         umount /initrd/dev
190                 fi
191                 umount /initrd/dev 2>/dev/null
192                 umount /initrd
193                 /sbin/blockdev --flushbufs /dev/ram0 >/dev/null 2>&1
194         fi
195
196         # /dev must be also mounted before everything but only if we want use them ;-)
197         if is_yes "$MOUNT_DEVFS"; then
198                 run_cmd "Mounting Device Filesystem" mount -n -t devfs /dev /dev
199
200                 # set up devfsd
201                 if [ -e /dev/.devfsd -a -x /sbin/devfsd ]; then
202                         run_cmd "Starting Device Filesystem Daemon" /sbin/devfsd /dev
203                 fi
204         fi
205
206         # Start logging console output since we have all /dev stuff setup
207         if [ "$RC_BOOTLOG" ]; then
208                 /sbin/blogd -q
209         fi
210
211         # cpuset support (mounted unconditionally, shouldn't be a problem)
212         if grep -q cpuset /proc/filesystems 2>/dev/null ; then
213                 # mkdir for udev (FIXME fix the udev instead)
214                 mkdir -p /dev/cpuset 2>/dev/null
215                 mount -n -t cpuset none /dev/cpuset
216         fi
217
218         # Configure Linux kernel (initial configuration, some required modules still
219         # may be missing).
220         /sbin/sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
221
222         # Set the system clock.
223         ARC=0
224         SRM=0
225         UTC=0
226
227         if [ -f /etc/sysconfig/clock ]; then
228                 . /etc/sysconfig/clock
229
230                 # convert old style clock config to new values
231                 if [ "${CLOCKMODE}" = "GMT" ]; then
232                         UTC=true
233                 elif [ "${CLOCKMODE}" = "ARC" ]; then
234                         ARC=true
235                 fi
236         fi
237
238         if grep "system serial" /proc/cpuinfo 2>/dev/null | grep -q MILO 2>/dev/null ; then
239                 ARC=true
240         fi
241
242         CLOCKDEF=""
243         CLOCKFLAGS="--hctosys"
244
245         if is_yes "$UTC" ; then
246                 CLOCKFLAGS="$CLOCKFLAGS --utc"
247                 CLOCKDEF="$CLOCKDEF (utc)"
248         else
249                 CLOCKFLAGS="$CLOCKFLAGS --localtime"
250                 CLOCKDEF="$CLOCKDEF (local)"
251         fi
252
253         if is_yes "$ARC" ; then
254                 CLOCKFLAGS="$CLOCKFLAGS -A"
255                 CLOCKDEF="$CLOCKDEF (arc)"
256         fi
257
258         if is_yes "$SRM" ; then
259                 CLOCKFLAGS="$CLOCKFLAGS -S"
260                 CLOCKDEF="$CLOCKDEF (srm)"
261         fi
262
263         # Check if timezone definition is available
264         if [ -e /etc/localtime -a -e /dev/rtc ] ; then
265                 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
266                         show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
267                 fi
268         else
269                 TIME_SETUP_DELAYED=yes
270         fi
271
272         # Start up swapping
273         run_cmd "Activating swap partitions" swapon -a -e
274
275         # Initialize USB controllers
276         usb=0
277         if ! strstr "$cmdline" "nousb" && ! grep -q "/proc/bus/usb" /proc/mounts 2>/dev/null ; then
278                 aliases=$(/sbin/modprobe -c | awk '/^alias[\t ]+usb-controller/ { print $3 }')
279                 if [ -n "$aliases" -a "$aliases" != "off" ] ; then
280                         /sbin/modprobe -s -k usbcore
281                         for alias in $aliases ; do
282                                 [ "$alias" = "off" ] && continue
283                                 run_cmd "$(nls 'Initializing USB controller') ($alias)" /sbin/modprobe -s $alias
284                         done
285                         [ $? -eq 0 -a -n "$aliases" ] && usb=1
286                 fi
287                 if grep -iq "usb" /proc/devices 2>/dev/null ; then
288                         usb=1
289                 fi
290         fi
291
292         if [ "$usb" = "1" -a ! -f /proc/bus/usb/devices ]; then
293                 run_cmd "Mounting USB filesystem" mount -n -t usbfs usbfs /proc/bus/usb
294         fi
295
296         needusbstorage=
297         if [ "$usb" = "1" ]; then
298                 needusbstorage=$(LC_ALL=C cat /proc/bus/usb/devices 2>/dev/null|grep -e "^I.*Cls=08" 2>/dev/null)
299                 if [ "$(kernelverser)" -lt "002006" ]; then
300                         LC_ALL=C grep -q 'hid' /proc/bus/usb/drivers 2>/dev/null || run_cmd "Initializing USB HID interface" modprobe hid 2> /dev/null
301                         mouseoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=02" 2>/dev/null)
302                         kbdoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=01" 2>/dev/null)
303                         if [ -n "$kbdoutput" ]; then
304                                 run_cmd "Initializing USB keyboard" modprobe keybdev
305                         fi
306                         if [ -n "$mouseoutput" ]; then
307                                 run_cmd "Initializing USB mouse" modprobe mousedev
308                         fi
309                 fi
310         fi
311
312         # Setup hdparm thing (if exists and is needed)
313         if ! strstr "$cmdline" nohdparm; then
314                 [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
315         fi
316
317         if [ -f /fastboot ] || strstr "$cmdline" "fastboot"; then
318                 fastboot=yes
319         else
320                 fastboot=
321         fi
322
323         if [ -f /fsckoptions ]; then
324                 fsckoptions=$(cat /fsckoptions)
325         else
326                 fsckoptions=''
327         fi
328
329         if [ -f /forcefsck ]; then
330                 fsckoptions="-f $fsckoptions"
331         else
332                 # Obey the fs_passno setting for / (see fstab(5))
333                 # - find the / entry
334                 # - make sure we have at least 6 fields
335                 _ROOTFS_PASSNO=$(awk '($1 !~ /^#/ && $2 == "/" && NF >= 6) { print $6}' /etc/fstab)
336         fi
337
338         _RUN_QUOTACHECK=0
339         _ROOTFS_TYPE=$(awk '$2 == "/" && $3 != "rootfs" { print $3 }' /proc/mounts 2>/dev/null)
340
341         if [ -z "$fastboot" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" -a "$_ROOTFS_PASSNO" != 0 ]; then
342                 show "Checking root filesystem"; started
343                 initlog -c "fsck -C -T -a $fsckoptions /"
344
345                 rc=$?
346
347                 # A return of 4 or higher means there were serious problems.
348                 if [ $rc -gt 3 ]; then
349                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
350                         # don't use '\n' in nls macro !
351                         echo
352                         echo
353                         nls "*** An error occurred during the file system check."
354                         nls "*** Dropping you to a shell; the system will reboot"
355                         nls "*** when you leave the shell."
356                         echo
357
358                         PS1="`nls '(Repair filesystem)# '`"; export PS1
359                         [ "$SELINUX" = "1" ] && disable_selinux
360                         if ! is_no "$RUN_SULOGIN_ON_ERR"; then
361                                 /sbin/sulogin
362                         else
363                                 /bin/sh
364                         fi
365
366                         run_cmd "Unmounting file systems" umount -a
367                         mount -n -o remount,ro /
368                         run_cmd "Automatic reboot in progress" reboot
369                 # A return of 2 or 3 means that filesystem was repaired but we need
370                 # to reboot.
371                 elif [ "$rc" = "2" -o "$rc" = "3" ]; then
372                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
373                         echo
374                         nls "*** Filesystem was repaired but system needs to be"
375                         nls "*** rebooted before mounting it."
376                         nls "*** REBOOTING ***"
377                         echo
378
379                         run_cmd "Unmounting file systems" umount -a
380                         mount -n -o remount,ro /
381                         run_cmd "Automatic reboot in progress" reboot
382                 elif [ "$rc" = "1" ]; then
383                         _RUN_QUOTACHECK=1
384                 fi
385         fi
386
387         # Check for arguments
388         if strstr "$cmdline" nopnp; then
389                 PNP=
390         else
391                 PNP=yes
392         fi
393
394         # set up pnp and kernel pnp
395         if [ -n "$PNP" ]; then
396                 if ! is_no "$RUN_USERPNP" && [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
397                         run_cmd "Setting up ISA PNP devices (userspace pnp)" /sbin/isapnp /etc/isapnp/isapnp.conf
398                 fi
399                 if ! is_no "$RUN_KERNELPNP"; then
400                         /sbin/modprobe -k isa-pnp 2> /dev/null
401                         if [ -e /proc/isapnp -a -f /etc/isapnp/isapnp-kernel.conf ]; then
402                                 show "Setting up ISA PNP devices (kernelspace pnp)"; busy
403                                 grep -v "^#" /etc/isapnp/isapnp-kernel.conf 2>/dev/null >/proc/isapnp && (deltext; ok) || (deltext; fail)
404                         fi
405                 fi
406         fi
407
408         # Remount the root filesystem read-write
409         run_cmd "Remounting root filesystem in rw mode" mount -n -o remount,rw /
410
411         # Update quotas if fsck was run on /
412         if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
413                 run_cmd "Checking root filesystem quotas" /sbin/quotacheck -vnug /
414         fi
415
416         # Clean up SELinux labels
417         if [ -n "$SELINUX" ]; then
418                 for file in /etc/mtab /etc/cryptomtab /etc/ld.so.cache ; do
419                         [ -r $file ] && restorecon $file >/dev/null 2>&1
420                 done
421         fi
422
423 else
424         # Start logging console output since we have all /dev stuff setup
425         if [ "$RC_BOOTLOG" ]; then
426                 /sbin/blogd -q
427         fi
428 fi
429
430 # Remove stale backups
431 rm -f /etc/mtab~ /etc/mtab~~ /etc/cryptomtab~ /etc/cryptomtab~~
432
433 # Remove /etc/nologin when starting system
434 [ -f /etc/nologin.boot ] && rm -f /etc/nologin /etc/nologin.boot
435
436 if ! is_no "$DELAY_LOGIN" && [ ! -f /etc/nologin ]; then
437         show "Enabling Delay Login"; busy
438         echo > /etc/nologin
439         nls "System bootup in progress - please wait" >> /etc/nologin
440         echo >> /etc/nologin
441         chmod 644 /etc/nologin
442         cp -fp /etc/nologin /etc/nologin.boot
443         ok
444 fi
445
446 # The root filesystem is now read-write, so we can now log via
447 # syslog() directly...
448 if [ -n "$IN_INITLOG" ]; then
449         IN_INITLOG=""
450 fi
451
452 if ! is_yes "$VSERVER"; then
453         # Clear mtab
454         :>/etc/mtab
455         [ -f /etc/cryptomtab ] && :>/etc/cryptomtab
456
457         # Enter root, /proc, /sys, devfs and other into mtab.
458         mount -f /
459         mount -f /proc
460         [ -f /proc/bus/usb/devices ] && mount -f -t usbfs usbfs /proc/bus/usb
461         [ -e /dev/.devfsd ] && mount -f -t devfs devfs /dev
462
463         if grep -q sysfs /proc/mounts 2>/dev/null; then
464                 mount -f -t sysfs sysfs /sys
465                 if grep -q securityfs /proc/mounts 2>/dev/null ; then
466                                 mount -f -t securityfs securityfs /sys/kernel/security
467                 fi
468         fi
469
470         if grep -q selinuxfs /proc/mounts 2>/dev/null; then
471                 mount -f -t selinuxfs selinuxfs /selinux
472         fi
473
474         if grep -q cpuset /proc/mounts 2>/dev/null; then
475                 mount -f -t cpuset none /dev/cpuset
476         fi
477
478         if [ ! -f /proc/modules ]; then
479                 USEMODULES=
480         elif ! strstr "$cmdline" nomodules; then
481                 USEMODULES=y
482         else
483                 USEMODULES=
484         fi
485
486         # Adjust symlinks as necessary in /boot to keep system services from
487         # spewing messages about mismatched System maps and so on.
488         if ! is_no "$SET_SLINKS"; then
489                 uname_r=$(uname -r)
490                 if [ -L /boot/System.map -a -r /boot/System.map-$uname_r ] ; then
491                         ln -s -f System.map-$uname_r /boot/System.map
492                 fi
493                 if [ ! -e /boot/System.map -a -r /boot/System.map-$uname_r ] ; then
494                         ln -s -f System.map-$uname_r /boot/System.map
495                 fi
496                 unset uname_r
497         fi
498
499         # Run depmod if RUN_DEPMOD != "no" and:
500         # a) user requested or RUN_DEPMOD="";
501         # b) modules.dep is missing
502         # c) modules.dep is older than /etc/modules.conf or /lib/modules/`uname -r`
503         if ! is_no "$RUN_DEPMOD" && [ -n "$USEMODULES" ]; then
504                 if is_yes "$RUN_DEPMOD" || [ -z "$RUN_DEPMOD" ]; then
505                         run_cmd "Finding module dependencies" depmod -a
506                 elif [ "$RUN_DEPMOD" = "ifmissing" ]; then
507                         run_cmd "Finding module dependencies" depmod -A
508                 fi
509         fi
510
511         if [ -f /proc/sys/kernel/modprobe ]; then
512                 if [ -n "$USEMODULES" ]; then
513                         sysctl -w kernel.modprobe="/sbin/modprobe" >/dev/null 2>&1
514                 else
515                         # We used to set this to NULL, but that causes
516                         # 'failed to exec' messages"
517                         sysctl -w kernel.modprobe="/bin/true" >/dev/null 2>&1
518                 fi
519         fi
520
521         # Load usb storage here, to match most other things
522         if [ -n "$needusbstorage" ]; then
523                 modprobe -k usb-storage >/dev/null 2>&1
524         fi
525
526         # Load firewire devices
527         if ! strstr "$cmdline" nofirewire; then
528                 aliases=$(/sbin/modprobe -c | awk '/^alias ieee1394-controller/ { print $3 }')
529                 if [ -n "$aliases" -a "$aliases" != "off" ] ; then
530                         for alias in $aliases ; do
531                                 [ "$alias" = "off" ] && continue
532                                 run_cmd "$(nls 'Initializing firewire controller') ($alias)" /sbin/modprobe $alias
533                         done
534                         LC_ALL=C grep -E "SBP2" /proc/bus/ieee1394/devices 2>/dev/null && /sbin/modprobe -s sbp2 > /dev/null 2>&1
535                 fi
536         fi
537
538         # Load sound modules if they need persistent DMA buffers
539         if [ $(kernelverser) = "002006" ]; then
540                 MODULES_CONF=/etc/modprobe.conf
541         elif [ -r /etc/modules.conf ]; then
542                 MODULES_CONF=/etc/modules.conf
543         else
544                 MODULES_CONF=/etc/conf.modules
545         fi
546
547         if grep -q "^options sound dmabuf=1" "$MODULES_CONF" 2>/dev/null ; then
548                 RETURN=0
549                 alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
550                 if [ -n "$alias" -a "$alias" != "off" ] ; then
551                         run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
552                         RETURN=$?
553                 fi
554                 alias=$(/sbin/modprobe -c | egrep -s "^alias[[:space:]]+sound-slot-0[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
555                 if [ -n "$alias" -a "$alias" != "off" ] ; then
556                         run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
557                         RETURN=$?
558                 fi
559         fi
560
561         # Load modules
562         if [ -x /etc/rc.d/rc.modules ]; then
563                 /etc/rc.d/rc.modules
564         fi
565
566         if [ -x /sbin/multipath ]; then
567                 # first make nodes that were discarded due (possible) new /dev mount
568                 /sbin/dmsetup mknodes
569                 run_cmd "Activating dm-multipath" /sbin/multipath -v 0
570                 /sbin/dmsetup ls --target multipath --exec '/sbin/kpartx -a'
571         fi
572
573         if [ -x /sbin/dmraid ]; then
574                 run_cmd "Activating ATARAID devices" /sbin/dmraid -ay
575         fi
576
577         # Find and activate volume groups:
578         # EVMS
579         if [ -x /sbin/evms_activate ]; then
580                 if [ "$(kernelverser)" -lt "002006" ]; then
581                         # Linux 2.4 core modules
582                         modprobe -s -k evms > /dev/null 2>&1
583                         modprobe -s -k evms_passthru > /dev/null 2>&1
584                         modprobe -s -k ldev_mgr > /dev/null 2>&1
585                         modprobe -s -k dos_part > /dev/null 2>&1
586                 else
587                         # Linux 2.6 core module
588                         modprobe -s -k evmscore > /dev/null 2>&1
589                 fi
590
591                 is_yes "$EVMS_GUID_PTABLE" && modprobe -s -k gpt_part >/dev/null 2>&1
592                 is_yes "$EVMS_LVM" && modprobe -s -k lvm_vge >/dev/null 2>&1
593                 is_yes "$EVMS_AIX" && modprobe -s -k AIXlvm_vge >/dev/null 2>&1
594                 is_yes "$EVMS_OS2" && modprobe -s -k os2lvm_vge >/dev/null 2>&1
595                 run_cmd "Discovering EVMS volumes" /sbin/evms_activate
596                 if is_yes "$EVMS_LVM" && is_yes "$EVMS_LVM_COMPAT_NODES" ; then
597                         # Link nodes for compatibility with LVM
598                         if [ "$(echo /dev/evms/lvm/*)" != '/dev/evms/lvm/*' ] ; then
599                                 ln -s /dev/evms/lvm/* /dev
600                         fi
601                 fi
602         fi
603
604         # LVM (keep in sync with LVM starting after RAID run!)
605         if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
606                 lvmversion=$(/sbin/vgchange --version 2>/dev/null | awk '{gsub("vgchange: Logical Volume Manager ",""); gsub("LVM version:     ",""); gsub(/\..*/,"");print $1; exit}')
607                 if [ "$lvmversion" = "1" ] ; then
608                         modprobe -s -k lvm-mod >/dev/null 2>&1
609                         lvmignorelock=""
610                 elif [ "$lvmversion" = "2" ] ; then
611                         modprobe -s -k dm-mod >/dev/null 2>&1
612                         lvmignorelock="--ignorelockingfailure"
613                 else
614                         modprobe -s -k lvm-mod >/dev/null 2>&1
615                         # device mapper (2.5+ and patched 2.4)
616                         modprobe -s -k dm-mod >/dev/null 2>&1
617                         lvmignorelock=""
618                 fi
619
620                 run_cmd "Scanning for LVM volume groups" /sbin/vgscan $lvmignorelock
621                 run_cmd "Activating LVM volume groups" /sbin/vgchange -a y $lvmignorelock
622                 [ "$lvmversion" = "2" ] && /sbin/vgmknodes
623         fi
624
625         # Add raid devices
626         if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ] || [ -f /etc/raidtab ]; then
627                 modprobe -s md >/dev/null 2>&1
628                 if [ -f /proc/mdstat ]; then
629                         goraidtab=1
630                         golvm=0
631                         rc=0
632                         if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
633                                 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
634                                         run_cmd "Starting up RAID devices" /sbin/mdadm --assemble --scan --auto=yes
635                                         rc=$?
636                                         [ "$rc" -eq 0 ] && goraidtab=0 && golvm=1
637                                 fi
638                         fi
639
640                         if [ -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
641                                 for i in $(awk '!/^#/ && /raiddev/{print $2}' /etc/raidtab 2>/dev/null); do
642                                         golvm=1
643                                         RAIDDEV=$(basename $i)
644                                         RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat 2>/dev/null)
645                                         show "Starting up RAID device %s" $RAIDDEV
646                                         busy
647                                         if [ -z "$RAIDSTAT" ]; then
648                                                 # Try raidstart first...if that fails then
649                                                 # fall back to raid0run and if that fails too
650                                                 # fall back to raidadd, raidrun.
651                                                 RESULT=1
652                                                 if [ -x /sbin/raidstart ]; then
653                                                         /sbin/raidstart $i
654                                                         RESULT=$?
655                                                 fi
656                                                 if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
657                                                         /sbin/raid0run $i
658                                                         RESULT=$?
659                                                 fi
660                                                 if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
661                                                         /sbin/raidadd $i
662                                                         /sbin/raidrun $i
663                                                         RESULT=$?
664                                                 fi
665                                                 if [ $RESULT -gt 0 ]; then
666                                                         rc=1
667                                                         fail
668                                                 else
669                                                         ok
670                                                 fi
671                                         else
672                                                 ok
673                                         fi
674                                 done
675                         fi
676
677                         # A non-zero return means there were problems
678                         if [ $rc -gt 0 ]; then
679                                 [ -e /proc/splash ] && echo "verbose" > /proc/splash
680                                 show "Starting up RAID devices"; fail
681                                 echo
682                                 echo
683                                 nls "*** An error occurred during the RAID startup."
684                                 nls "*** Dropping you to a shell; the system will reboot"
685                                 nls "*** when you leave the shell."
686                                 echo
687
688                                 PS1="$(nls '(RAID Repair)# ')"; export PS1
689                                 [ "$SELINUX" = "1" ] && disable_selinux
690                                 if ! is_no "$RUN_SULOGIN_ON_ERR"; then
691                                         /sbin/sulogin
692                                 else
693                                         /bin/sh
694                                 fi
695
696                                 run_cmd "Unmounting file systems" umount -a
697                                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
698                                 run_cmd "Automatic reboot in progress" reboot
699                         fi
700                         # LVM on RAID (keep in sync with LVM setting few lines above)
701                         if [ "$golvm" -eq "1" ]; then
702                                 if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
703                                         run_cmd "Scanning for LVM volume groups (on RAID)" /sbin/vgscan $lvmignorelock
704                                         run_cmd "Activating LVM volume groups (on RAID)" /sbin/vgchange -a y $lvmignorelock
705                                         [ "$lvmversion" = "2" ] && /sbin/vgmknodes
706                                 fi
707                         fi
708                         show "Starting up RAID devices"; ok
709                 fi
710         fi
711
712         _RUN_QUOTACHECK=0
713         # Check filesystems
714         if [ -z "$fastboot" ] && ! strstr "$cmdline" nofsck; then
715                 rc_splash "fsck start"
716                 show "Checking filesystems"; started
717                 initlog -c "fsck -C -T -R -A -a -P $fsckoptions"
718
719                 rc=$?
720
721                 # A return of 2 or higher means there were serious problems
722                 if [ $rc -gt 1 ]; then
723                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
724                         echo
725                         echo
726                         nls "*** An error occurred during the file system check."
727                         nls "*** Dropping you to a shell; the system will reboot"
728                         nls "*** when you leave the shell."
729                         echo
730
731                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
732                         [ "$SELINUX" = "1" ] && disable_selinux
733                         if ! is_no "$RUN_SULOGIN_ON_ERR"; then
734                                 /sbin/sulogin
735                         else
736                                 /bin/sh
737                         fi
738
739                         run_cmd "Unmounting file systems" umount -a
740                         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
741                         run_cmd "Automatic reboot in progress" reboot
742                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
743                         _RUN_QUOTACHECK=1
744                 fi
745                 rc_splash "fsck stop"
746         fi
747
748         # Mount all other filesystems (except for NFS and /proc, which is already
749         # mounted). Contrary to standard usage,
750         # filesystems are NOT unmounted in single user mode.
751
752         run_cmd "Mounting local filesystems" mount -a -t nonfs,nfs4,smbfs,ncpfs,proc,cifs -O no_netdev
753
754         # now we have /usr mounted, recheck if we have gettext and tput available.
755         if is_no "$TPUT"; then
756                 GETTEXT=
757                 TPUT=
758                 rc_gettext_init
759         fi
760
761         # Now do some workaround - encrypted filesystems couldn't have been fsck-ed
762         # before mount - that's where the password is entered.
763         # mount is buggy - when remounting loopback filesystem, loop=XXX
764         # option is removed from /etc/mtab
765         if [ -z "$fastboot" ] && grep "^[^#].*encryption=" /etc/fstab 2>/dev/null | grep -v -q "noauto" 2>/dev/null; then
766                 show "Checking encrypted filesystems"; started
767                 LOOPLIST="$(LC_ALL=C awk '
768                 FILENAME=="/proc/mounts" {
769                         TAB[$2]=$1;
770                 }
771                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && /[^a-zA-Z_]ro[^a-zA-Z_]/ {
772                         if ($2 in TAB){print TAB[$2];}
773                 }
774                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
775                         if ($2 in TAB){print TAB[$2];}
776                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",ro",$4);
777                         cmd="mount " $2 " -o remount," $4;
778                         system(cmd);
779                 }
780                 ' /proc/mounts /etc/fstab)"
781                 initlog -c "fsck -T -C -a $fsckoptions $LOOPLIST"
782                 rc=$?
783
784                 # A return of 2 or higher means there were serious problems.
785                 if [ $rc -gt 1 ]; then
786                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
787                         echo
788                         echo
789                         nls "*** An error occurred during the file system check."
790                         nls "*** Dropping you to a shell; the system will reboot"
791                         nls "*** when you leave the shell."
792                         echo
793
794                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
795                         [ "$SELINUX" = "1" ] && disable_selinux
796                         if ! is_no "$RUN_SULOGIN_ON_ERR"; then
797                                 /sbin/sulogin
798                         else
799                                 /bin/sh
800                         fi
801
802                         run_cmd "Unmounting file systems" umount -a
803                         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
804                         run_cmd "Automatic reboot in progress" reboot
805                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
806                         _RUN_QUOTACHECK=1
807                 fi
808
809                 show "Remounting encrypted filesystems back in rw mode"; busy
810                 awk '
811                 FILENAME=="/proc/mounts" {
812                         TAB[$2]=$1;
813                 }
814                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
815                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",rw",$4);
816                         cmd="mount " $2 " -o remount," $4;
817                         system(cmd);
818                 }
819                 ' /proc/mounts /etc/fstab
820                 ok
821         fi
822
823         # /var/log should be writable now, so start saving the boot output
824         if [ "$RC_BOOTLOG" ]; then
825                 echo > /var/log/boot.msg
826                 killall -IO blogd
827         fi
828
829         if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
830                 run_cmd "Checking filesystem quotas" /sbin/quotacheck -vnugRa
831         fi
832
833         # Turn on quota
834         if [ -x /sbin/quotaon ]; then
835                 run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -aug
836         fi
837
838         # Turn on process accounting
839         if [ -x /etc/rc.d/rc.acct ]; then
840                 /etc/rc.d/rc.acct start
841         fi
842
843         # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
844         if is_yes "$TIME_SETUP_DELAYED" && [ -e /dev/rtc ]; then
845                 if run_cmd "$(nls 'Setting clock')$CLOCKDEF" /sbin/hwclock $CLOCKFLAGS; then
846                         show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
847                 fi
848         fi
849
850         # Initialize the serial ports
851         if [ -f /etc/rc.d/rc.serial ]; then
852                 . /etc/rc.d/rc.serial
853         fi
854
855         if [ -f /proc/sys/kernel/panic -a -n "$PANIC_REBOOT_TIME" -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
856                 show 'Setting %s seconds for kernel reboot after panic' "$PANIC_REBOOT_TIME"; busy
857                 if (sysctl -w kernel.panic=$PANIC_REBOOT_TIME >/dev/null 2>&1); then ok; else fail; fi
858         fi
859
860         # ... and here finish configuring parameters
861         /sbin/sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
862 else
863         # /var/log should be writable now, so start saving the boot output
864         if [ "$RC_BOOTLOG" ]; then
865                 echo > /var/log/boot.msg
866                 killall -IO blogd
867         fi
868
869         clean_vserver_mtab
870 fi
871
872
873 [ -n "$SELINUX" ] && [ -f /.autorelabel ] && relabel_selinux
874
875 # Clean up /.
876 rm -f /fastboot /fsckoptions /forcefsck /halt /poweroff
877
878 # Clean up /var
879 for afile in /var/lock/* /var/run/*; do
880         bafile=${afile##*/}
881         if [ -d "$afile" ]; then
882                 case $bafile in
883                 news|sudo|mon|cvs)
884                         ;;
885                 *)
886                         rm -rf $afile/*
887                         ;;
888                 esac
889         else
890                 [ "$bafile" != "hwprofile" ] && rm -f $afile 2> /dev/null
891         fi
892 done
893 # Delete stale files
894 rm -f /var/lib/rpm/__db* /var/spool/postoffice/.pid.* /tmp/.X*-lock \
895         /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.*
896 rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
897         /tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-* \
898         /tmp/scrollkeeper-* /tmp/ssh-*
899
900 {
901 # Clean up utmp/wtmp
902 if ! is_no "$NEED_XFILES"; then
903         :>/var/run/utmpx
904         touch /var/log/wtmpx
905         chown root:utmp /var/run/utmpx /var/log/wtmpx
906         chmod 0664 /var/run/utmpx /var/log/wtmpx
907 else
908         :>/var/run/utmp
909         touch /var/log/wtmp
910         chown root:utmp /var/run/utmp /var/log/wtmp
911         chmod 0664 /var/run/utmp /var/log/wtmp
912 fi
913
914 # Clean /tmp
915 if is_yes "$CLEAN_TMP"; then
916         # XXX LC_ALL needed here
917         rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
918 fi
919
920 # System protected dirs
921 mkdir -m 1777 -p /tmp/.ICE-unix > /dev/null 2>&1
922 chown root:root /tmp/.ICE-unix
923 [ -n "$SELINUX" ] && restorecon /tmp/.ICE-unix >/dev/null 2>&1
924
925 if ! is_yes "$VSERVER"; then
926         run_cmd "Enabling swap space" /bin/true
927         # Right, now turn on swap in case we swap to files
928         swapon -a >/dev/null 2>&1
929
930         # If a SCSI tape has been detected, load the st module unconditionally
931         # since many SCSI tapes don't deal well with st being loaded and unloaded
932         if [ -f /proc/scsi/scsi ] && grep -q 'Type:   Sequential-Access' /proc/scsi/scsi 2>/dev/null ; then
933                 if grep -qv ' 9 st' /proc/devices 2>/dev/null; then
934                         if [ -n "$USEMODULES" ] ; then
935                                 # Try to load the module. If it fails, ignore it...
936                                 insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
937                         fi
938                 fi
939         fi
940
941         # Now that we have all of our basic modules loaded and the kernel going,
942         # let's dump the syslog ring somewhere so we can find it later
943         dmesg -s 131072 > /var/log/dmesg
944         i=5
945         while [ $i -ge 0 ]; do
946                 if [ -f /var/log/dmesg.$i ]; then
947                         chmod 0600 /var/log/dmesg.$i
948                         mv -f /var/log/dmesg.$i /var/log/dmesg.$(($i+1))
949                 fi
950                 i=$(($i-1))
951         done
952         cp -f /var/log/dmesg /var/log/dmesg.0
953         chmod 0600 /var/log/dmesg /var/log/dmesg.0
954 fi
955
956 kill -TERM $(/sbin/pidof getkey) >/dev/null 2>&1
957 } &
958
959 # extra check if the background process we just spawned is still running,
960 # as in case of vserver bootup it finishes quite instantly.
961 if ! is_no "$RC_PROMPT" && [ -d /proc/$! ]; then
962         /sbin/getkey -c 5 i && touch /var/run/confirm
963 fi
964 wait
965 echo
966
967 # This must be last line !
968 # vi:syntax=sh
This page took 0.097351 seconds and 4 git commands to generate.