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