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