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