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