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