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