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