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