]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc.sysinit
- extra sysctl right after mounting /proc
[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                         [ -r $f ] || continue
578                         load_kernel_modules ${f##/etc/}
579                 done
580         fi
581
582         if [ -x /sbin/multipath ] && ! is_no "$DM_MULTIPATH"; then
583                 # first make nodes that were discarded due (possible) new /dev mount
584                 modprobe -s dm-mod
585                 /sbin/dmsetup mknodes
586                 modprobe -s dm-multipath
587                 run_cmd "Activating dm-multipath" /sbin/multipath -v 0
588                 /sbin/dmsetup ls --target multipath --exec '/sbin/kpartx -a -p p'
589         fi
590
591         if [ -x /sbin/dmraid ]; then
592                 run_cmd "Activating ATARAID devices" /sbin/dmraid -ay
593         fi
594
595         # Find and activate volume groups:
596         # EVMS
597         if [ -x /sbin/evms_activate ]; then
598                 if [ "$(kernelverser)" -lt "002006" ]; then
599                         # Linux 2.4 core modules
600                         modprobe -s evms > /dev/null 2>&1
601                         modprobe -s evms_passthru > /dev/null 2>&1
602                         modprobe -s ldev_mgr > /dev/null 2>&1
603                         modprobe -s dos_part > /dev/null 2>&1
604                 else
605                         # Linux 2.6 core module
606                         modprobe -s evmscore > /dev/null 2>&1
607                 fi
608
609                 is_yes "$EVMS_GUID_PTABLE" && modprobe -s gpt_part >/dev/null 2>&1
610                 is_yes "$EVMS_LVM" && modprobe -s lvm_vge >/dev/null 2>&1
611                 is_yes "$EVMS_AIX" && modprobe -s AIXlvm_vge >/dev/null 2>&1
612                 is_yes "$EVMS_OS2" && modprobe -s os2lvm_vge >/dev/null 2>&1
613                 run_cmd "Discovering EVMS volumes" /sbin/evms_activate
614                 if is_yes "$EVMS_LVM" && is_yes "$EVMS_LVM_COMPAT_NODES" ; then
615                         # Link nodes for compatibility with LVM
616                         if [ "$(echo /dev/evms/lvm/*)" != '/dev/evms/lvm/*' ] ; then
617                                 ln -s /dev/evms/lvm/* /dev
618                         fi
619                 fi
620         fi
621
622         # LVM (keep in sync with LVM starting after RAID run!)
623         if ! is_no "$LVM2" && [ -x /sbin/vgscan -a -x /sbin/vgchange ] || is_yes "$EVMS_LVM"; then
624                 if is_no "$LVM2"; then
625                         lvmversion=$(LC_ALL=C /sbin/vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
626                 else
627                         lvmversion=2
628                 fi
629                 if [ "$lvmversion" = "1" ] ; then
630                         modprobe -s lvm-mod >/dev/null 2>&1
631                         lvmignorelocking=""
632                         lvmsysinit=""
633                 elif [ "$lvmversion" = "2" ] ; then
634                         modprobe -s dm-mod >/dev/null 2>&1
635                         lvmignorelocking="--ignorelockingfailure"
636                         lvmsysinit="--sysinit"
637                 else
638                         modprobe -s lvm-mod >/dev/null 2>&1
639                         # device mapper (2.5+ and patched 2.4)
640                         modprobe -s dm-mod >/dev/null 2>&1
641                         lvmignorelocking=""
642                         lvmsysinit=""
643                 fi
644
645                 run_cmd "Scanning for LVM volume groups" /sbin/vgscan $lvmignorelocking
646                 run_cmd "Activating LVM volume groups" /sbin/vgchange -a y $lvmsysinit
647                 if [ "$lvmversion" = "2" ]; then
648                         /sbin/vgmknodes $lvmignorelocking
649                         # display VG statistics
650                         /sbin/vgdisplay -s $lvmignorelocking
651                 fi
652         fi
653
654         if [ "$delay_cryptsetup" != 0 ]; then
655                 show "Starting disk encryption"
656                 init_crypto 1
657                 delay_cryptsetup=$?
658                 [ $delay_cryptsetup = 0 ] && ok || fail
659         fi
660
661         # Add raid devices
662         if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ] || [ -f /etc/raidtab ]; then
663                 modprobe -s md >/dev/null 2>&1
664                 if [ -f /proc/mdstat ]; then
665                         goraidtab=1
666                         golvm=0
667                         rc=0
668                         if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
669                                 if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
670                                         show "Starting up RAID devices"; busy
671                                         /sbin/mdadm --assemble --scan --auto=yes
672                                         rc=$?
673                                         if [ "$rc" -eq 0 -o "$rc" -eq 2 ]; then
674                                                 # rc is used later, too so set sane value
675                                                 rc=0
676                                                 deltext; ok
677                                                 goraidtab=0
678                                                 golvm=1
679                                         else
680                                                 deltext; fail
681                                         fi
682
683                                 fi
684                         fi
685
686                         if [ -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
687                                 for i in $(awk '!/^#/ && /raiddev/{print $2}' /etc/raidtab 2>/dev/null); do
688                                         golvm=1
689                                         RAIDDEV=$(basename $i)
690                                         RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat 2>/dev/null)
691                                         show "Starting up RAID device %s" $RAIDDEV
692                                         busy
693                                         if [ -z "$RAIDSTAT" ]; then
694                                                 # Try raidstart first...if that fails then
695                                                 # fall back to raid0run and if that fails too
696                                                 # fall back to raidadd, raidrun.
697                                                 RESULT=1
698                                                 if [ -x /sbin/raidstart ]; then
699                                                         /sbin/raidstart $i
700                                                         RESULT=$?
701                                                 fi
702                                                 if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
703                                                         /sbin/raid0run $i
704                                                         RESULT=$?
705                                                 fi
706                                                 if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
707                                                         /sbin/raidadd $i
708                                                         /sbin/raidrun $i
709                                                         RESULT=$?
710                                                 fi
711                                                 if [ $RESULT -gt 0 ]; then
712                                                         rc=1
713                                                         fail
714                                                 else
715                                                         ok
716                                                 fi
717                                         else
718                                                 ok
719                                         fi
720                                 done
721                         fi
722
723                         # A non-zero return means there were problems
724                         if [ $rc -gt 0 ]; then
725                                 [ -e /proc/splash ] && echo "verbose" > /proc/splash
726                                 show "Starting up RAID devices"; fail
727                                 echo
728                                 echo
729                                 nls "*** An error occurred during the RAID startup."
730                                 nls "*** Dropping you to a shell; the system will reboot"
731                                 nls "*** when you leave the shell."
732                                 echo
733
734                                 PS1="$(nls '(RAID Repair)# ')"; export PS1
735                                 [ "$SELINUX" = "1" ] && disable_selinux
736                                 if ! is_no "$RUN_SULOGIN_ON_ERR"; then
737                                         /sbin/sulogin
738                                 else
739                                         /bin/sh
740                                 fi
741
742                                 run_cmd "Unmounting file systems" umount -a
743                                 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
744                                 run_cmd "Automatic reboot in progress" reboot
745                         fi
746                         # LVM on RAID (keep in sync with LVM setting few lines above)
747                         if [ "$golvm" -eq "1" ]; then
748                                 if [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
749                                         run_cmd "Scanning for LVM volume groups (on RAID)" /sbin/vgscan $lvmignorelocking
750                                         run_cmd "Activating LVM volume groups (on RAID)" /sbin/vgchange -a y $lvmsysinit
751                                         [ "$lvmversion" = "2" ] && /sbin/vgmknodes
752                                 fi
753                         fi
754                         show "Starting up RAID devices"; ok
755                 fi
756         fi
757
758         _RUN_QUOTACHECK=0
759         # Check filesystems
760         if [ -z "$fastboot" ] && ! strstr "$cmdline" nofsck; then
761                 rc_splash "fsck start"
762                 show "Checking filesystems"; started
763                 initlog -c "fsck -C -T -R -A -a -P $fsckoptions"
764
765                 rc=$?
766
767                 # A return of 2 or higher means there were serious problems
768                 if [ $rc -gt 1 ]; then
769                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
770                         echo
771                         echo
772                         nls "*** An error occurred during the file system check."
773                         nls "*** Dropping you to a shell; the system will reboot"
774                         nls "*** when you leave the shell."
775                         echo
776
777                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
778                         [ "$SELINUX" = "1" ] && disable_selinux
779                         if ! is_no "$RUN_SULOGIN_ON_ERR"; then
780                                 /sbin/sulogin
781                         else
782                                 /bin/sh
783                         fi
784
785                         run_cmd "Unmounting file systems" umount -a
786                         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
787                         run_cmd "Automatic reboot in progress" reboot
788                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
789                         _RUN_QUOTACHECK=1
790                 fi
791                 rc_splash "fsck stop"
792         fi
793
794         # Mount all other filesystems (except for NFS and /proc, which is already
795         # mounted). Contrary to standard usage,
796         # filesystems are NOT unmounted in single user mode.
797
798         run_cmd "Mounting local filesystems" mount -a -t nonfs,nfs4,smbfs,ncpfs,proc,cifs -O no_netdev
799
800         # now we have /usr mounted, recheck if we have gettext and tput available.
801         if is_no "$TPUT"; then
802                 GETTEXT=
803                 TPUT=
804                 rc_gettext_init
805         fi
806
807         # Now do some workaround - encrypted filesystems couldn't have been fsck-ed
808         # before mount - that's where the password is entered.
809         # mount is buggy - when remounting loopback filesystem, loop=XXX
810         # option is removed from /etc/mtab
811         if [ -z "$fastboot" ] && grep "^[^#].*encryption=" /etc/fstab 2>/dev/null | grep -v -q "noauto" 2>/dev/null; then
812                 show "Checking encrypted filesystems"; started
813                 LOOPLIST="$(awk '
814                 FILENAME=="/proc/mounts" {
815                         TAB[$2]=$1;
816                 }
817                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && /[^a-zA-Z_]ro[^a-zA-Z_]/ {
818                         if ($2 in TAB){print TAB[$2];}
819                 }
820                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
821                         if ($2 in TAB){print TAB[$2];}
822                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",ro",$4);
823                         cmd="mount " $2 " -o remount," $4;
824                         system(cmd);
825                 }
826                 ' /proc/mounts /etc/fstab)"
827                 initlog -c "fsck -T -C -a $fsckoptions $LOOPLIST"
828                 rc=$?
829
830                 # A return of 2 or higher means there were serious problems.
831                 if [ $rc -gt 1 ]; then
832                         [ -e /proc/splash ] && echo "verbose" > /proc/splash
833                         echo
834                         echo
835                         nls "*** An error occurred during the file system check."
836                         nls "*** Dropping you to a shell; the system will reboot"
837                         nls "*** when you leave the shell."
838                         echo
839
840                         PS1="$(nls '(Repair filesystem)# ')"; export PS1
841                         [ "$SELINUX" = "1" ] && disable_selinux
842                         if ! is_no "$RUN_SULOGIN_ON_ERR"; then
843                                 /sbin/sulogin
844                         else
845                                 /bin/sh
846                         fi
847
848                         run_cmd "Unmounting file systems" umount -a
849                         run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
850                         run_cmd "Automatic reboot in progress" reboot
851                 elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
852                         _RUN_QUOTACHECK=1
853                 fi
854
855                 show "Remounting encrypted filesystems back in rw mode"; busy
856                 awk '
857                 FILENAME=="/proc/mounts" {
858                         TAB[$2]=$1;
859                 }
860                 FILENAME=="/etc/fstab" && /encryption=/ && ! /noauto/ && ! /[^a-zA-Z_]ro[^a-zA-Z_]/ {
861                         sub("loop(=[^,]*)?","loop=" TAB[$2] ",rw",$4);
862                         cmd="mount " $2 " -o remount," $4;
863                         system(cmd);
864                 }
865                 ' /proc/mounts /etc/fstab
866                 ok
867         fi
868
869         # /var/log should be writable now, so start saving the boot output
870         if [ "$RC_BOOTLOG" ]; then
871                 echo > /var/log/boot.log
872                 killall -IO blogd
873         fi
874
875         if [ "$_RUN_QUOTACHECK" = "1" -a -x /sbin/quotacheck ]; then
876                 run_cmd "Checking filesystem quotas" /sbin/quotacheck -vnugRa
877         fi
878
879         # Turn on quota
880         if [ -x /sbin/quotaon ]; then
881                 run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -aug
882         fi
883
884         emit --no-wait local-filesystems
885
886         # FIXME: this should be delayed until remote filesystems are mounted,
887         #        especialy when /usr or other standard fs is remote
888         emit --no-wait filesystem
889
890         # Turn on process accounting
891         if [ -x /etc/rc.d/rc.acct ]; then
892                 /etc/rc.d/rc.acct start
893         fi
894
895         # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
896         if is_yes "$TIME_SETUP_DELAYED" && [ -e /dev/rtc -o -e /dev/rtc0 ]; then
897                 if run_cmd "$(nls 'Setting clock')" hwclock --hctosys; then
898                         show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
899                 fi
900         fi
901
902         # Initialize the serial ports
903         if [ -f /etc/rc.d/rc.serial ]; then
904                 . /etc/rc.d/rc.serial
905         fi
906
907         if [ -f /proc/sys/kernel/panic -a -n "$PANIC_REBOOT_TIME" -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
908                 show 'Setting %s seconds for kernel reboot after panic' "$PANIC_REBOOT_TIME"; busy
909                 # NOTE: you should use /etc/sysctl.conf instead
910                 if sysctl -w kernel.panic=$PANIC_REBOOT_TIME >/dev/null 2>&1; then ok; else fail; fi
911         fi
912
913         # ... and here finish configuring parameters
914         sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
915 else
916         emit --no-wait root-filesystem
917         emit --no-wait virtual-filesystems
918         emit --no-wait local-filesystems
919         emit --no-wait filesystem
920
921         # /var/log should be writable now, so start saving the boot output
922         if [ "$RC_BOOTLOG" ]; then
923                 echo > /var/log/boot.log
924                 killall -IO blogd
925         fi
926
927         clean_vserver_mtab
928 fi
929
930
931 [ -n "$SELINUX" ] && [ -f /.autorelabel ] && relabel_selinux
932
933 # Clean up /.
934 rm -f /fastboot /fsckoptions /forcefsck /halt /poweroff >/dev/null 2>&1
935
936 # Clean up /var
937 # /usr could be still not mounted if it is on NFS.
938 for afile in /var/lock/* /var/run/*; do
939         bafile=${afile##*/}
940         if [ -d "$afile" ]; then
941                 case $bafile in
942                 news|sudo|mon|cvs)
943                         ;;
944                 *)
945                         echo $afile/* | xargs rm -rf
946                         ;;
947                 esac
948         else
949                 [ "$bafile" != "hwprofile" -a "$bafile" != "random-seed" ] && rm -f $afile 2> /dev/null
950         fi
951 done
952
953 # Delete stale files
954 rm -f /var/lib/rpm/__db* /var/spool/postoffice/.pid.* /tmp/.X*-lock \
955         /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.*
956 rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
957         /tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-* \
958         /tmp/scrollkeeper-* /tmp/ssh-*
959
960 {
961 # Clean up utmp/wtmp
962 if ! is_no "$NEED_XFILES"; then
963         :>/var/run/utmpx
964         touch /var/log/wtmpx
965         chown root:utmp /var/run/utmpx /var/log/wtmpx
966         chmod 0664 /var/run/utmpx /var/log/wtmpx
967 else
968         :>/var/run/utmp
969         touch /var/log/wtmp
970         chown root:utmp /var/run/utmp /var/log/wtmp
971         chmod 0664 /var/run/utmp /var/log/wtmp
972 fi
973
974 # Clean /tmp
975 if is_yes "$CLEAN_TMP" && ! is_fsmounted tmpfs /tmp; then
976         LC_ALL=C rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
977 fi
978
979 # System protected dirs
980 mkdir -m 1777 -p /tmp/.ICE-unix > /dev/null 2>&1
981 chown root:root /tmp/.ICE-unix
982 [ -n "$SELINUX" ] && restorecon /tmp/.ICE-unix >/dev/null 2>&1
983
984 if ! is_yes "$VSERVER"; then
985         run_cmd "Enabling swap space" true
986         # Right, now turn on swap in case we swap to files
987         swapon -a >/dev/null 2>&1
988         emit --no-wait all-swaps
989
990         # If a SCSI tape has been detected, load the st module unconditionally
991         # since many SCSI tapes don't deal well with st being loaded and unloaded
992         if [ -f /proc/scsi/scsi ] && grep -q 'Type:   Sequential-Access' /proc/scsi/scsi 2>/dev/null ; then
993                 if grep -qv ' 9 st' /proc/devices 2>/dev/null; then
994                         if [ -n "$USEMODULES" ] ; then
995                                 # Try to load the module. If it fails, ignore it...
996                                 insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
997                         fi
998                 fi
999         fi
1000
1001         # Now that we have all of our basic modules loaded and the kernel going,
1002         # let's dump the syslog ring somewhere so we can find it later
1003         dmesg > /var/log/dmesg
1004         i=5
1005         while [ $i -ge 0 ]; do
1006                 if [ -f /var/log/dmesg.$i ]; then
1007                         chmod 0600 /var/log/dmesg.$i
1008                         mv -f /var/log/dmesg.$i /var/log/dmesg.$(($i+1))
1009                 fi
1010                 i=$(($i-1))
1011         done
1012         cp -f /var/log/dmesg /var/log/dmesg.0
1013         chmod 0600 /var/log/dmesg /var/log/dmesg.0
1014 else
1015         emit --no-wait all-swaps
1016 fi
1017
1018 if ! is_no "$RC_PROMPT"; then
1019         while :; do
1020                 pid=$(/sbin/pidof getkey)
1021                 [ -n "$pid" -o -e /var/run/getkey_done ] && break
1022                 usleep 100000
1023         done
1024         [ -n "$pid" ] && kill -TERM "$pid" >/dev/null 2>&1
1025 fi
1026 } &
1027
1028 # /proc extra check if the background process we just spawned is still running,
1029 # as in case of vserver bootup it finishes quite instantly.
1030 if ! is_no "$RC_PROMPT" && [ -d /proc/$! ]; then
1031         /sbin/getkey i && touch /var/run/confirm
1032         touch /var/run/getkey_done
1033 fi
1034 wait
1035 if ! is_no "$RC_PROMPT"; then
1036         rm -f /var/run/getkey_done
1037 fi
1038 echo
1039
1040 emit --no-wait pld.sysinit-done
1041
This page took 0.110386 seconds and 4 git commands to generate.