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