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