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