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