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