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