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