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